Create and destroy temp PATH in tests

Since busted seems to spawn isolated child processes for every test
suite, the temporary PATH directories have to be created at the
beginning and destroyed at the end of a test suite.
This commit is contained in:
Florian Gamböck 2017-08-01 20:23:53 +02:00
parent a716009caa
commit 829e887806
1 changed files with 8 additions and 0 deletions

View File

@ -46,6 +46,7 @@ local function remove_test_path_dir(test_path)
end end
local test_dir local test_dir
local test_path
--- Get and create a temporary test dir based on `pat`, where %d gets replaced by --- Get and create a temporary test dir based on `pat`, where %d gets replaced by
-- the current PID. -- the current PID.
@ -65,11 +66,13 @@ describe("awful.completion.shell in empty directory", function()
io.popen = function(...) --luacheck: ignore io.popen = function(...) --luacheck: ignore
return orig_popen(string.format('cd %s && ', test_dir) .. ...) return orig_popen(string.format('cd %s && ', test_dir) .. ...)
end end
test_path = get_test_path_dir()
end) end)
teardown(function() teardown(function()
assert.True(os.remove(test_dir)) assert.True(os.remove(test_dir))
io.popen = orig_popen --luacheck: ignore io.popen = orig_popen --luacheck: ignore
remove_test_path_dir(test_path)
end) end)
if has_bash then if has_bash then
@ -97,12 +100,14 @@ describe("awful.completion.shell", function()
io.popen = function(...) --luacheck: ignore io.popen = function(...) --luacheck: ignore
return orig_popen(string.format('cd %s && ', test_dir) .. ...) return orig_popen(string.format('cd %s && ', test_dir) .. ...)
end end
test_path = get_test_path_dir()
end) end)
teardown(function() teardown(function()
assert.True(os.remove(test_dir .. '/localcommand')) assert.True(os.remove(test_dir .. '/localcommand'))
assert.True(os.remove(test_dir)) assert.True(os.remove(test_dir))
io.popen = orig_popen --luacheck: ignore io.popen = orig_popen --luacheck: ignore
remove_test_path_dir(test_path)
end) end)
if has_bash then if has_bash then
@ -159,11 +164,14 @@ describe("awful.completion.shell handles $SHELL", function()
gdebug.print_warning = function(message) gdebug.print_warning = function(message)
print_warning_message = message print_warning_message = message
end end
test_path = get_test_path_dir()
end) end)
teardown(function() teardown(function()
os.getenv = orig_getenv --luacheck: ignore os.getenv = orig_getenv --luacheck: ignore
gdebug.print_warning = orig_print_warning gdebug.print_warning = orig_print_warning
remove_test_path_dir(test_path)
end) end)
before_each(function() before_each(function()