From 764f576d641fbc1f0608148d995a63847adb010e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 18 Sep 2016 23:43:32 +0200 Subject: [PATCH 1/3] test/helpers.rmdir(): Retry once after a delay. Attempt to avoid "Permission denied" on Windows potentially caused by open filepath handle in sibling process. --- test/functional/helpers.lua | 18 ++++++++++++++---- test/functional/legacy/012_directory_spec.lua | 6 +++--- .../legacy/031_close_commands_spec.lua | 19 ++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index f6d09e6139..0fb168b736 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -376,8 +376,8 @@ local function wait() end -- sleeps the test runner (_not_ the nvim instance) -local function sleep(timeout) - run(nil, nil, nil, timeout) +local function sleep(ms) + run(nil, nil, nil, ms) end local function curbuf_contents() @@ -403,7 +403,7 @@ local function expect(contents) return eq(dedent(contents), curbuf_contents()) end -local function rmdir(path) +local function do_rmdir(path) if lfs.attributes(path, 'mode') ~= 'directory' then return nil end @@ -411,7 +411,7 @@ local function rmdir(path) if file ~= '.' and file ~= '..' then local abspath = path..'/'..file if lfs.attributes(abspath, 'mode') == 'directory' then - local ret = rmdir(abspath) -- recurse + local ret = do_rmdir(abspath) -- recurse if not ret then return nil end @@ -431,6 +431,16 @@ local function rmdir(path) return ret end +local function rmdir(path) + local ret, err = pcall(do_rmdir, path) + -- During teardown, the nvim process may not exit quickly enough, then rmdir() + -- will fail (on Windows). + if not ret then -- Try again. + sleep(1000) + do_rmdir(path) + end +end + local exc_exec = function(cmd) nvim_command(([[ try diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua index 44e1c14d78..686b6177d8 100644 --- a/test/functional/legacy/012_directory_spec.lua +++ b/test/functional/legacy/012_directory_spec.lua @@ -36,6 +36,7 @@ describe("'directory' option", function() clear() end) teardown(function() + execute('qall!') helpers.rmdir('Xtest.je') helpers.rmdir('Xtest2') os.remove('Xtest1') @@ -71,15 +72,14 @@ describe("'directory' option", function() wait() -- swapfile should no longer exist in CWD. - eq(nil, lfs.attributes('.Xtest1.swp')) -- for unix - eq(nil, lfs.attributes('Xtest1.swp')) -- for other systems + eq(nil, lfs.attributes('.Xtest1.swp')) -- unix + eq(nil, lfs.attributes('Xtest1.swp')) -- non-unix eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2")) execute('set dir=Xtest.je,~') execute('e Xtest2/Xtest3') eq(1, eval('&swapfile')) - execute('swap') wait() eq({ "Xtest3" }, ls_dir_sorted("Xtest2")) diff --git a/test/functional/legacy/031_close_commands_spec.lua b/test/functional/legacy/031_close_commands_spec.lua index eaf4e2982f..d41eadaa00 100644 --- a/test/functional/legacy/031_close_commands_spec.lua +++ b/test/functional/legacy/031_close_commands_spec.lua @@ -19,7 +19,18 @@ local expect = helpers.expect local execute = helpers.execute describe('Commands that close windows and/or buffers', function() - setup(clear) + local function cleanup() + os.remove('Xtest1') + os.remove('Xtest2') + os.remove('Xtest3') + end + setup(function() + cleanup() + clear() + end) + teardown(function() + cleanup() + end) it('is working', function() insert('testtext') @@ -112,10 +123,4 @@ describe('Commands that close windows and/or buffers', function() " Now nvim should have exited throw "Oh, Not finished yet."]]) end) - - teardown(function() - os.remove('Xtest1') - os.remove('Xtest2') - os.remove('Xtest3') - end) end) From 13e57246216c946594862938a392e4b8fab4e8b4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 20 Sep 2016 03:02:48 +0200 Subject: [PATCH 2/3] test/helpers.rmdir(): lfs.rmdir() instead of os.remove() os.remove() fails on empty directories in non-POSIX systems. https://github.com/keplerproject/luafilesystem/issues/4 lfs.rmdir() "usually" works, so use it instead. Closes #5236 --- test/functional/helpers.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 0fb168b736..d5b7442b57 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -424,15 +424,15 @@ local function do_rmdir(path) end end end - local ret, err = os.remove(path) + local ret, err = lfs.rmdir(path) if not ret then - error('os.remove: '..err) + error('lfs.rmdir('..path..'): '..err) end return ret end local function rmdir(path) - local ret, err = pcall(do_rmdir, path) + local ret, _ = pcall(do_rmdir, path) -- During teardown, the nvim process may not exit quickly enough, then rmdir() -- will fail (on Windows). if not ret then -- Try again. From 911421d328a91a56389248fe27bee6c95784d95f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 20 Sep 2016 09:46:16 +0200 Subject: [PATCH 3/3] test: legacy/012_directory_spec: Also use dot-prefix on Windows. win32 handles dot-prefixed files just fine; Nvim-on-Windows does not perpetuate the Vim-on-Windows behavior of avoiding dot-prefixed files. --- test/functional/legacy/012_directory_spec.lua | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua index 686b6177d8..cef31ae405 100644 --- a/test/functional/legacy/012_directory_spec.lua +++ b/test/functional/legacy/012_directory_spec.lua @@ -53,27 +53,21 @@ describe("'directory' option", function() execute('set dir=.,~') -- sanity check: files should not exist yet. - eq(nil, lfs.attributes('.Xtest1.swp')) -- unix - eq(nil, lfs.attributes('Xtest1.swp')) -- non-unix + eq(nil, lfs.attributes('.Xtest1.swp')) execute('e! Xtest1') wait() eq('Xtest1', eval('buffer_name("%")')) -- Verify that the swapfile exists. In the legacy test this was done by -- reading the output from :!ls. - if eval('has("unix")') == 1 then - neq(nil, lfs.attributes('.Xtest1.swp')) - else - neq(nil, lfs.attributes('Xtest1.swp')) - end + neq(nil, lfs.attributes('.Xtest1.swp')) execute('set dir=./Xtest2,.,~') execute('e Xtest1') wait() -- swapfile should no longer exist in CWD. - eq(nil, lfs.attributes('.Xtest1.swp')) -- unix - eq(nil, lfs.attributes('Xtest1.swp')) -- non-unix + eq(nil, lfs.attributes('.Xtest1.swp')) eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2"))