aboutsummaryrefslogtreecommitdiff
path: root/spec/util
diff options
context:
space:
mode:
authorGeorge Roman <george.roman.99@gmail.com>2018-07-24 11:09:42 +0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-24 15:41:22 -0300
commit8e6a83911027de167d689d060ce581f653d73213 (patch)
tree622218f964f10a27b7922bcfcd3bf14fd6c1735b /spec/util
parent961670659be3e986bc74b9b8c2a296f4640302e5 (diff)
downloadluarocks-8e6a83911027de167d689d060ce581f653d73213.tar.gz
luarocks-8e6a83911027de167d689d060ce581f653d73213.tar.bz2
luarocks-8e6a83911027de167d689d060ce581f653d73213.zip
Tests: add test_env.run_in_tmp utility function
Diffstat (limited to 'spec/util')
-rw-r--r--spec/util/test_env.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index 0218aa53..181f4693 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -101,6 +101,25 @@ function test_env.get_tmp_path()
101 return path 101 return path
102end 102end
103 103
104--- Helper function that runs the given function inside
105-- a temporary directory, isolating it
106-- @param f function: the function to be run
107function test_env.run_in_tmp(f, finally)
108 local olddir = lfs.currentdir()
109 local tmpdir = test_env.get_tmp_path()
110 lfs.mkdir(tmpdir)
111 lfs.chdir(tmpdir)
112
113 if finally then
114 finally(function()
115 lfs.chdir(olddir)
116 lfs.rmdir(tmpdir)
117 end)
118 end
119
120 f(tmpdir)
121end
122
104--- Helper function for execute_bool and execute_output 123--- Helper function for execute_bool and execute_output
105-- @param command string: command to execute 124-- @param command string: command to execute
106-- @param print_command boolean: print command if 'true' 125-- @param print_command boolean: print command if 'true'