fix(tests): check for EOF on exit of nvim properly

This commit is contained in:
bfredl 2022-06-08 23:22:50 +02:00
parent dd8b6094c0
commit e3281d992e
16 changed files with 74 additions and 56 deletions

View File

@ -27,6 +27,7 @@ local write_file = helpers.write_file
local exec_lua = helpers.exec_lua
local exc_exec = helpers.exc_exec
local insert = helpers.insert
local expect_exit = helpers.expect_exit
local pcall_err = helpers.pcall_err
local format_string = helpers.format_string
@ -2617,7 +2618,7 @@ describe('API', function()
it('does not cause heap-use-after-free on exit while setting options', function()
command('au OptionSet * q')
command('silent! call nvim_create_buf(0, 1)')
expect_exit(command, 'silent! call nvim_create_buf(0, 1)')
end)
end)

View File

@ -16,12 +16,13 @@ local trim = helpers.trim
local currentdir = helpers.funcs.getcwd
local iswin = helpers.iswin
local assert_alive = helpers.assert_alive
local expect_exit = helpers.expect_exit
describe('fileio', function()
before_each(function()
end)
after_each(function()
command(':qall!')
expect_exit(command, ':qall!')
os.remove('Xtest_startup_shada')
os.remove('Xtest_startup_file1')
os.remove('Xtest_startup_file1~')

View File

@ -14,6 +14,7 @@ local pesc = helpers.pesc
local rmdir = helpers.rmdir
local sleep = helpers.sleep
local meths = helpers.meths
local expect_exit = helpers.expect_exit
local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec'
@ -44,7 +45,7 @@ describe(':mksession', function()
command('mksession '..session_file)
-- Create a new test instance of Nvim.
command('qall!')
expect_exit(command, 'qall!')
clear()
-- Restore session.
command('source '..session_file)
@ -113,7 +114,7 @@ describe(':mksession', function()
if iswin() then
sleep(100) -- Make sure all child processes have exited.
end
command('qall!')
expect_exit(command, 'qall!')
-- Create a new test instance of Nvim.
clear()
@ -156,7 +157,7 @@ describe(':mksession', function()
command('cd '..cwd_dir)
command('mksession '..session_path)
command('qall!')
expect_exit(command, 'qall!')
-- Create a new test instance of Nvim.
clear()

View File

@ -270,6 +270,13 @@ function module.command(cmd)
module.request('nvim_command', cmd)
end
-- use for commands which expect nvim to quit
function module.expect_exit(...)
eq("EOF was received from Nvim. Likely the Nvim process crashed.",
module.pcall_err(...))
end
-- Evaluates a VimL expression.
-- Fails on VimL error, but does not update v:errmsg.
function module.eval(expr)

View File

@ -6,6 +6,7 @@ local source = helpers.source
local clear, command, expect, eq, eval = helpers.clear, helpers.command, helpers.expect, helpers.eq, helpers.eval
local write_file, dedent = helpers.write_file, helpers.dedent
local read_file = helpers.read_file
local expect_exit = helpers.expect_exit
describe('autocommands that delete and unload buffers:', function()
local test_file = 'Xtest-008_autocommands.out'
@ -78,7 +79,7 @@ describe('autocommands that delete and unload buffers:', function()
command('silent! edit Xxx1')
command('silent! edit Makefile') -- an existing file
command('silent! split new2')
command('silent! quit')
expect_exit(command, 'silent! quit')
eq('VimLeave done',
string.match(read_file(test_file), "^%s*(.-)%s*$"))
end)

View File

@ -16,6 +16,7 @@ local insert = helpers.insert
local command = helpers.command
local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths
local expect_exit = helpers.expect_exit
local function ls_dir_sorted(dirname)
local files = {}
@ -43,7 +44,7 @@ describe("'directory' option", function()
clear()
end)
teardown(function()
command('qall!')
expect_exit(command, 'qall!')
helpers.rmdir('Xtest.je')
helpers.rmdir('Xtest2')
os.remove('Xtest1')

View File

@ -17,6 +17,7 @@ local source = helpers.source
local insert = helpers.insert
local expect = helpers.expect
local feed_command = helpers.feed_command
local expect_exit = helpers.expect_exit
describe('Commands that close windows and/or buffers', function()
local function cleanup()
@ -118,7 +119,7 @@ describe('Commands that close windows and/or buffers', function()
feed_command('q!')
feed('<CR>')
expect('testtext 1')
source([[
expect_exit(source, [[
q!
" Now nvim should have exited
throw "Oh, Not finished yet."]])

View File

@ -22,7 +22,7 @@ local remove_trace = helpers.remove_trace
local mkdir_p = helpers.mkdir_p
local rmdir = helpers.rmdir
local write_file = helpers.write_file
local expect_exit = helpers.expect_exit
describe('lua stdlib', function()
before_each(clear)
@ -2677,9 +2677,7 @@ describe('lua: builtin modules', function()
it('does not work when disabled without runtime', function()
clear{args={'--luamod-dev'}, env={VIMRUNTIME='fixtures/a'}}
-- error checking could be better here. just check that --luamod-dev
-- does anything at all by breaking with missing runtime..
eq(nil, exec_lua[[return vim.tbl_count {x=1,y=2}]])
expect_exit(exec_lua, [[return vim.tbl_count {x=1,y=2}]])
end)
end)

View File

@ -17,6 +17,7 @@ local mkdir = helpers.mkdir
local rmdir = helpers.rmdir
local alter_slashes = helpers.alter_slashes
local tbl_contains = helpers.tbl_contains
local expect_exit = helpers.expect_exit
describe('startup defaults', function()
describe(':filetype', function()
@ -174,7 +175,7 @@ describe('startup defaults', function()
command('write')
local f = eval('fnamemodify(@%,":p")')
assert(string.len(f) > 3)
command('qall')
expect_exit(command, 'qall')
clear{args={}, args_rm={'-i'}, env=env}
eq({ f }, eval('v:oldfiles'))
os.remove('Xtest-foo')

View File

@ -2,6 +2,7 @@
local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, eq, curbufmeths =
helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths
local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear
@ -15,7 +16,7 @@ describe('shada support code', function()
reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada+=%')
eq(3, funcs.bufnr('$'))
eq('', funcs.bufname(1))
@ -27,7 +28,7 @@ describe('shada support code', function()
reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
@ -37,7 +38,7 @@ describe('shada support code', function()
reset()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada+=%')
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
@ -48,7 +49,7 @@ describe('shada support code', function()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buflisted', false)
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada+=%')
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
@ -60,7 +61,7 @@ describe('shada support code', function()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buftype', 'quickfix')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada+=%')
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
@ -73,7 +74,7 @@ describe('shada support code', function()
nvim_command('enew')
curbufmeths.set_lines(0, 1, true, {'bar'})
eq(2, funcs.bufnr('$'))
nvim_command('qall!')
expect_exit(nvim_command, 'qall!')
reset('set shada+=% hidden')
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
@ -83,7 +84,7 @@ describe('shada support code', function()
reset('set shada+=%1')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada+=%1')
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))

View File

@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, meths, nvim_feed, eq =
helpers.command, helpers.funcs, helpers.meths, helpers.feed, helpers.eq
local assert_alive = helpers.assert_alive
local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear
@ -25,13 +26,13 @@ describe('ShaDa support code', function()
nvim_command('set shada=\'0 history=2')
nvim_feed(':" Test\n')
nvim_feed(':" Test 2\n')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('set shada=\'0 history=2')
nvim_command('rshada')
eq('" Test 2', funcs.histget(':', -1))
eq('" Test', funcs.histget(':', -2))
nvim_command('qall')
expect_exit(nvim_command, 'qall')
end)
it('respects &history when dumping',
@ -138,7 +139,7 @@ describe('ShaDa support code', function()
nvim_command('set hlsearch shada-=h')
nvim_feed('/test\n')
eq(1, meths.get_vvar('hlsearch'))
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq(1, meths.get_vvar('hlsearch'))
end)
@ -147,7 +148,7 @@ describe('ShaDa support code', function()
nvim_command('set hlsearch shada-=h')
nvim_feed('/test\n')
nvim_command('nohlsearch')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq(0, meths.get_vvar('hlsearch'))
end)
@ -156,7 +157,7 @@ describe('ShaDa support code', function()
nvim_command('set hlsearch')
nvim_feed('/test\n')
eq(1, meths.get_vvar('hlsearch'))
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq(0, meths.get_vvar('hlsearch'))
end)
@ -175,7 +176,7 @@ describe('ShaDa support code', function()
it('dumps and loads history with UTF-8 characters', function()
reset()
nvim_feed(':echo "«"\n')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq('echo "«"', funcs.histget(':', -1))
end)
@ -183,7 +184,7 @@ describe('ShaDa support code', function()
it('dumps and loads replacement with UTF-8 characters',
function()
nvim_command('substitute/./«/ge')
nvim_command('qall!')
expect_exit(nvim_command, 'qall!')
reset()
funcs.setline('.', {'.'})
nvim_command('&')
@ -193,7 +194,7 @@ describe('ShaDa support code', function()
it('dumps and loads substitute pattern with UTF-8 characters',
function()
nvim_command('substitute/«/./ge')
nvim_command('qall!')
expect_exit(nvim_command, 'qall!')
reset()
funcs.setline('.', {'«\171'})
nvim_command('&')
@ -204,7 +205,7 @@ describe('ShaDa support code', function()
function()
nvim_command('silent! /«/')
nvim_command('set shada+=/0')
nvim_command('qall!')
expect_exit(nvim_command, 'qall!')
reset()
funcs.setline('.', {'\171«'})
nvim_command('~&')
@ -217,7 +218,7 @@ describe('ShaDa support code', function()
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
nvim_command('silent! /\171/')
nvim_command('set shada+=/0')
nvim_command('qall!')
expect_exit(nvim_command, 'qall!')
reset()
funcs.setline('.', {'\171«'})
nvim_command('~&')

View File

@ -4,6 +4,7 @@ local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq =
helpers.meths, helpers.curwinmeths, helpers.curbufmeths, helpers.command,
helpers.funcs, helpers.eq
local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture
local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear
@ -79,7 +80,7 @@ describe('ShaDa support code', function()
nvim_command('mark a')
nvim_command('2')
nvim_command('kb')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! `a')
@ -92,7 +93,7 @@ describe('ShaDa support code', function()
it('is able to dump and read back mark "', function()
nvim_command('edit ' .. testfilename)
nvim_command('2')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! `"')
@ -104,7 +105,7 @@ describe('ShaDa support code', function()
nvim_command('tabedit ' .. testfilename_2)
nvim_command('2')
nvim_command('q!')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('edit ' .. testfilename_2)
nvim_command('normal! `"')
@ -116,7 +117,7 @@ describe('ShaDa support code', function()
local tf_full = curbufmeths.get_name()
nvim_command('edit ' .. testfilename_2)
local tf_full_2 = curbufmeths.get_name()
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
local oldfiles = meths.get_vvar('oldfiles')
table.sort(oldfiles)
@ -145,7 +146,7 @@ describe('ShaDa support code', function()
nvim_command('enew')
nvim_command('normal! gg')
local saved = exec_capture('jumps')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq(saved, exec_capture('jumps'))
end)
@ -176,7 +177,7 @@ describe('ShaDa support code', function()
nvim_command('normal! G')
nvim_command('sleep 2')
nvim_command('normal! gg')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('redraw')
nvim_command('edit ' .. testfilename)
@ -200,7 +201,7 @@ describe('ShaDa support code', function()
nvim_command('edit ' .. testfilename)
nvim_command('normal! Gra')
nvim_command('normal! ggrb')
nvim_command('qall!')
expect_exit(nvim_command, 'qall!')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! Gg;')

View File

@ -4,6 +4,7 @@ local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear
local expect_exit = helpers.expect_exit
local setreg = function(name, contents, typ)
if type(contents) == 'string' then
@ -27,7 +28,7 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'d', 'e', ''}, 'v'}, getreg('c'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('l'))
@ -39,7 +40,7 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{}, ''}, getreg('c'))
eq({{}, ''}, getreg('l'))
@ -50,7 +51,7 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada=\'0,<0')
eq({{'d', 'e', ''}, 'v'}, getreg('c'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('l'))
@ -62,7 +63,7 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{}, ''}, getreg('c'))
eq({{}, ''}, getreg('l'))
@ -73,7 +74,7 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada=\'0,\\"0')
eq({{'d', 'e', ''}, 'v'}, getreg('c'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('l'))
@ -85,7 +86,7 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'d', 'e', ''}, 'v'}, getreg('c'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('l'))
@ -96,7 +97,7 @@ describe('ShaDa support code', function()
nvim_command('set shada=\'0,<2')
setreg('o', {'d'}, 'c')
setreg('t', {'a', 'b', 'cde'}, 'l')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({{}, ''}, getreg('t'))
@ -106,7 +107,7 @@ describe('ShaDa support code', function()
nvim_command('set shada=\'0,\\"2')
setreg('o', {'d'}, 'c')
setreg('t', {'a', 'b', 'cde'}, 'l')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({{}, ''}, getreg('t'))
@ -117,7 +118,7 @@ describe('ShaDa support code', function()
setreg('o', {'d'}, 'c')
setreg('t', {'a', 'b', 'cde'}, 'l')
setreg('h', {'abc', 'acb', 'bac', 'bca', 'cab', 'cba'}, 'b3')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'d'}, 'v'}, getreg('o'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('t'))
@ -128,7 +129,7 @@ describe('ShaDa support code', function()
function()
reset()
setreg('e', {'«'}, 'c')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'«'}, 'v'}, getreg('e'))
end)
@ -138,7 +139,7 @@ describe('ShaDa support code', function()
reset()
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
setreg('e', {'\171«'}, 'c')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'\171«'}, 'v'}, getreg('e'))
end)
@ -148,7 +149,7 @@ describe('ShaDa support code', function()
setreg('1', {'one'}, 'c')
setreg('2', {'two'}, 'c')
setreg('a', {'a'}, 'c')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{}, ''}, getreg('0'))
eq({{'one'}, 'v'}, getreg('1'))
@ -161,7 +162,7 @@ describe('ShaDa support code', function()
setreg('0', {'zero'}, 'c')
setreg('1', {'one'}, 'c')
setreg('2', {'two'}, 'c')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'zero'}, 'v'}, getreg('0'))
eq({{'one'}, 'v'}, getreg('1'))
@ -173,7 +174,7 @@ describe('ShaDa support code', function()
setreg('0', {'zero'}, 'c')
setreg('1', {'one'}, 'cu')
setreg('2', {'two'}, 'c')
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq({{'zero'}, 'v'}, getreg('0'))
eq({{'one'}, 'v'}, getreg('1'))

View File

@ -2,6 +2,7 @@
local helpers = require('test.functional.helpers')(after_each)
local meths, funcs, nvim_command, eq, eval =
helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.eval
local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear
@ -33,7 +34,7 @@ describe('ShaDa support code', function()
local vartype = eval('type(g:' .. varname .. ')')
-- Exit during `reset` is not a regular exit: it does not write shada
-- automatically
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset('set shada+=!')
eq(vartype, eval('type(g:' .. varname .. ')'))
eq(varval, meths.get_var(varname))
@ -98,7 +99,7 @@ describe('ShaDa support code', function()
meths.set_var('LSTVAR', {'«'})
meths.set_var('DCTVAR', {['«']='«'})
meths.set_var('NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}})
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq('«', meths.get_var('STRVAR'))
eq({'«'}, meths.get_var('LSTVAR'))
@ -116,7 +117,7 @@ describe('ShaDa support code', function()
meths.set_var('DCTVAR', {['«\171']='«\171'})
meths.set_var('NESTEDVAR', {['\171']={{'\171«'}, {['\171']='\171'},
{a='Test'}}})
nvim_command('qall')
expect_exit(nvim_command, 'qall')
reset()
eq('\171', meths.get_var('STRVAR'))
eq({'\171'}, meths.get_var('LSTVAR'))

View File

@ -4,6 +4,7 @@ local clear, feed, command = helpers.clear, helpers.feed, helpers.command
local eq = helpers.eq
local insert = helpers.insert
local poke_eventloop = helpers.poke_eventloop
local expect_exit = helpers.expect_exit
describe('Screen', function()
local screen
@ -1003,7 +1004,7 @@ describe('Screen', function()
-- test/functional/ui/syntax_conceal_spec.lua.
describe('concealed line after window scroll', function()
after_each(function()
command(':qall!')
expect_exit(command, ':qall!')
os.remove('Xcolesearch')
end)

View File

@ -219,7 +219,7 @@ if(USE_BUNDLED_BUSTED)
# nvim-client: https://github.com/neovim/lua-client
add_custom_command(OUTPUT ${ROCKS_DIR}/nvim-client
COMMAND ${LUAROCKS_BINARY}
ARGS build nvim-client 0.2.3-1 ${LUAROCKS_BUILDARGS}
ARGS build nvim-client 0.2.4-1 ${LUAROCKS_BUILDARGS}
DEPENDS luv)
add_custom_target(nvim-client DEPENDS ${ROCKS_DIR}/nvim-client)