test/helpers.rmdir(): Retry once after a delay.

Attempt to avoid "Permission denied" on Windows potentially caused by open
filepath handle in sibling process.
This commit is contained in:
Justin M. Keyes 2016-09-18 23:43:32 +02:00
parent efe8311371
commit 764f576d64
3 changed files with 29 additions and 14 deletions

View File

@ -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

View File

@ -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"))

View File

@ -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)