From 0f34b256aa4c87ed7211275614618e741912a6ec Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 20 Jul 2015 16:51:53 +0200 Subject: [PATCH 1/2] Test: add new helper function: rmdir() - lfs.rmdir() only removes empty directories - os.remove() supercedes lfs.rmdir(); removes files and empty directories - helpers.rmdir() first removes all files within a directory, then the directory itself --- test/functional/helpers.lua | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 33d04616a0..d5c22c6f1c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -290,6 +290,28 @@ local function expect(contents) return eq(dedent(contents), curbuf_contents()) end +local function rmdir(path) + if lfs.attributes(path, 'mode') ~= 'directory' then + return nil + end + for file in lfs.dir(path) do + if file == '.' or file == '..' then + goto continue + end + ret, err = os.remove(path..'/'..file) + if not ret then + error('os.remove: '..err) + return nil + end + ::continue:: + end + ret, err = os.remove(path) + if not ret then + error('os.remove: '..err) + end + return ret +end + return { clear = clear, spawn = spawn, @@ -321,5 +343,6 @@ return { curbuf_contents = curbuf_contents, wait = wait, set_session = set_session, - write_file = write_file + write_file = write_file, + rmdir = rmdir } From 2b2cea38a9822c7f8ac88f33099252bd0378b9ba Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 20 Jul 2015 22:17:22 +0200 Subject: [PATCH 2/2] Test: fix functional/ex_cmds/recover_spec.lua os.remove() wasn't removing the temporary swap directory which leads to problems when the test is run a second time. That's also the reason why the CI never caught this. os.remove() got replaced by helpers.rmdir(). --- test/functional/ex_cmds/recover_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua index d4c9477133..b92739e40e 100644 --- a/test/functional/ex_cmds/recover_spec.lua +++ b/test/functional/ex_cmds/recover_spec.lua @@ -20,11 +20,11 @@ describe(':preserve', function() local swapdir = lfs.currentdir()..'/testdir_recover_spec' before_each(function() clear() - os.remove(swapdir) + helpers.rmdir(swapdir) lfs.mkdir(swapdir) end) after_each(function() - os.remove(swapdir) + helpers.rmdir(swapdir) end) it("saves to custom 'directory' and (R)ecovers (issue #1836)", function()