mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #5362 from justinmk/testcleanup
test: helpers.rmdir(): retry+sleep on failure
This commit is contained in:
commit
bba6315580
@ -376,8 +376,8 @@ local function wait()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- sleeps the test runner (_not_ the nvim instance)
|
-- sleeps the test runner (_not_ the nvim instance)
|
||||||
local function sleep(timeout)
|
local function sleep(ms)
|
||||||
run(nil, nil, nil, timeout)
|
run(nil, nil, nil, ms)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function curbuf_contents()
|
local function curbuf_contents()
|
||||||
@ -403,7 +403,7 @@ local function expect(contents)
|
|||||||
return eq(dedent(contents), curbuf_contents())
|
return eq(dedent(contents), curbuf_contents())
|
||||||
end
|
end
|
||||||
|
|
||||||
local function rmdir(path)
|
local function do_rmdir(path)
|
||||||
if lfs.attributes(path, 'mode') ~= 'directory' then
|
if lfs.attributes(path, 'mode') ~= 'directory' then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -411,7 +411,7 @@ local function rmdir(path)
|
|||||||
if file ~= '.' and file ~= '..' then
|
if file ~= '.' and file ~= '..' then
|
||||||
local abspath = path..'/'..file
|
local abspath = path..'/'..file
|
||||||
if lfs.attributes(abspath, 'mode') == 'directory' then
|
if lfs.attributes(abspath, 'mode') == 'directory' then
|
||||||
local ret = rmdir(abspath) -- recurse
|
local ret = do_rmdir(abspath) -- recurse
|
||||||
if not ret then
|
if not ret then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -424,13 +424,23 @@ local function rmdir(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local ret, err = os.remove(path)
|
local ret, err = lfs.rmdir(path)
|
||||||
if not ret then
|
if not ret then
|
||||||
error('os.remove: '..err)
|
error('lfs.rmdir('..path..'): '..err)
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function 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.
|
||||||
|
sleep(1000)
|
||||||
|
do_rmdir(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local exc_exec = function(cmd)
|
local exc_exec = function(cmd)
|
||||||
nvim_command(([[
|
nvim_command(([[
|
||||||
try
|
try
|
||||||
|
@ -36,6 +36,7 @@ describe("'directory' option", function()
|
|||||||
clear()
|
clear()
|
||||||
end)
|
end)
|
||||||
teardown(function()
|
teardown(function()
|
||||||
|
execute('qall!')
|
||||||
helpers.rmdir('Xtest.je')
|
helpers.rmdir('Xtest.je')
|
||||||
helpers.rmdir('Xtest2')
|
helpers.rmdir('Xtest2')
|
||||||
os.remove('Xtest1')
|
os.remove('Xtest1')
|
||||||
@ -52,34 +53,27 @@ describe("'directory' option", function()
|
|||||||
execute('set dir=.,~')
|
execute('set dir=.,~')
|
||||||
|
|
||||||
-- sanity check: files should not exist yet.
|
-- sanity check: files should not exist yet.
|
||||||
eq(nil, lfs.attributes('.Xtest1.swp')) -- unix
|
eq(nil, lfs.attributes('.Xtest1.swp'))
|
||||||
eq(nil, lfs.attributes('Xtest1.swp')) -- non-unix
|
|
||||||
|
|
||||||
execute('e! Xtest1')
|
execute('e! Xtest1')
|
||||||
wait()
|
wait()
|
||||||
eq('Xtest1', eval('buffer_name("%")'))
|
eq('Xtest1', eval('buffer_name("%")'))
|
||||||
-- Verify that the swapfile exists. In the legacy test this was done by
|
-- Verify that the swapfile exists. In the legacy test this was done by
|
||||||
-- reading the output from :!ls.
|
-- reading the output from :!ls.
|
||||||
if eval('has("unix")') == 1 then
|
neq(nil, lfs.attributes('.Xtest1.swp'))
|
||||||
neq(nil, lfs.attributes('.Xtest1.swp'))
|
|
||||||
else
|
|
||||||
neq(nil, lfs.attributes('Xtest1.swp'))
|
|
||||||
end
|
|
||||||
|
|
||||||
execute('set dir=./Xtest2,.,~')
|
execute('set dir=./Xtest2,.,~')
|
||||||
execute('e Xtest1')
|
execute('e Xtest1')
|
||||||
wait()
|
wait()
|
||||||
|
|
||||||
-- swapfile should no longer exist in CWD.
|
-- swapfile should no longer exist in CWD.
|
||||||
eq(nil, lfs.attributes('.Xtest1.swp')) -- for unix
|
eq(nil, lfs.attributes('.Xtest1.swp'))
|
||||||
eq(nil, lfs.attributes('Xtest1.swp')) -- for other systems
|
|
||||||
|
|
||||||
eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2"))
|
eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2"))
|
||||||
|
|
||||||
execute('set dir=Xtest.je,~')
|
execute('set dir=Xtest.je,~')
|
||||||
execute('e Xtest2/Xtest3')
|
execute('e Xtest2/Xtest3')
|
||||||
eq(1, eval('&swapfile'))
|
eq(1, eval('&swapfile'))
|
||||||
execute('swap')
|
|
||||||
wait()
|
wait()
|
||||||
|
|
||||||
eq({ "Xtest3" }, ls_dir_sorted("Xtest2"))
|
eq({ "Xtest3" }, ls_dir_sorted("Xtest2"))
|
||||||
|
@ -19,7 +19,18 @@ local expect = helpers.expect
|
|||||||
local execute = helpers.execute
|
local execute = helpers.execute
|
||||||
|
|
||||||
describe('Commands that close windows and/or buffers', function()
|
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()
|
it('is working', function()
|
||||||
insert('testtext')
|
insert('testtext')
|
||||||
@ -112,10 +123,4 @@ describe('Commands that close windows and/or buffers', function()
|
|||||||
" Now nvim should have exited
|
" Now nvim should have exited
|
||||||
throw "Oh, Not finished yet."]])
|
throw "Oh, Not finished yet."]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
teardown(function()
|
|
||||||
os.remove('Xtest1')
|
|
||||||
os.remove('Xtest2')
|
|
||||||
os.remove('Xtest3')
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user