Use luafilesystem to change directory

In some circumstances, if not every syscall was somehow redefined, the
directory was not changed correctly. With luafilesystem.chdir it is
assured that we are in the wanted directory afterwards.
This commit is contained in:
Florian Gamböck 2017-07-02 16:02:36 +02:00
parent c279dd32ce
commit 8e2d844f60
1 changed files with 7 additions and 0 deletions

View File

@ -6,6 +6,7 @@ end
local gfs = require("gears.filesystem") local gfs = require("gears.filesystem")
local Gio = require("lgi").Gio local Gio = require("lgi").Gio
local GLib = require("lgi").GLib local GLib = require("lgi").GLib
local lfs = require("lfs")
local has_bash = GLib.find_program_in_path("bash") local has_bash = GLib.find_program_in_path("bash")
local has_zsh = GLib.find_program_in_path("zsh") local has_zsh = GLib.find_program_in_path("zsh")
@ -60,12 +61,14 @@ end
describe("awful.completion.shell in empty directory", function() describe("awful.completion.shell in empty directory", function()
local orig_popen = io.popen local orig_popen = io.popen
local orig_dir = lfs.currentdir()
setup(function() setup(function()
test_dir = get_test_dir() test_dir = get_test_dir()
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
lfs.chdir(test_dir)
test_path = get_test_path_dir() test_path = get_test_path_dir()
end) end)
@ -73,6 +76,7 @@ describe("awful.completion.shell in empty directory", 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) remove_test_path_dir(test_path)
lfs.chdir(orig_dir)
end) end)
if has_bash then if has_bash then
@ -92,6 +96,7 @@ end)
describe("awful.completion.shell", function() describe("awful.completion.shell", function()
local orig_popen = io.popen local orig_popen = io.popen
local orig_dir = lfs.currentdir()
setup(function() setup(function()
test_dir = get_test_dir() test_dir = get_test_dir()
@ -102,6 +107,7 @@ 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
lfs.chdir(test_dir)
test_path = get_test_path_dir() test_path = get_test_path_dir()
end) end)
@ -112,6 +118,7 @@ describe("awful.completion.shell", 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) remove_test_path_dir(test_path)
lfs.chdir(orig_dir)
end) end)
if has_bash then if has_bash then