diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 92c83b5f49..4dde733e1e 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -419,6 +419,14 @@ end -- clear('-e') -- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}} function module.clear(...) + local argv, env = module.new_argv(...) + module.set_session(module.spawn(argv, nil, env)) +end + +-- Builds an argument list for use in clear(). +-- +--@see clear() for parameters. +function module.new_argv(...) local args = {unpack(module.nvim_argv)} table.insert(args, '--headless') local new_args @@ -458,7 +466,7 @@ function module.clear(...) for _, arg in ipairs(new_args) do table.insert(args, arg) end - module.set_session(module.spawn(args, nil, env)) + return args, env end function module.insert(...) diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index a4746c2205..04c9c01d7c 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -1,26 +1,22 @@ --- ShaDa buffer list saving/reading support +-- shada buffer list saving/reading support local helpers = require('test.functional.helpers')(after_each) local nvim_command, funcs, eq, curbufmeths = helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear = - shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear +local reset, clear = shada_helpers.reset, shada_helpers.clear -describe('ShaDa support code', function() +describe('shada support code', function() local testfilename = 'Xtestfile-functional-shada-buffers' local testfilename_2 = 'Xtestfile-functional-shada-buffers-2' - before_each(reset) after_each(clear) it('is able to dump and restore buffer list', function() - set_additional_cmd('set shada+=%') - reset() + reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) nvim_command('qall') - reset() + reset('set shada+=%') eq(3, funcs.bufnr('$')) eq('', funcs.bufname(1)) eq(testfilename, funcs.bufname(2)) @@ -28,11 +24,9 @@ describe('ShaDa support code', function() end) it('does not restore buffer list without % in &shada', function() - set_additional_cmd('set shada+=%') - reset() + reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - set_additional_cmd('') nvim_command('qall') reset() eq(1, funcs.bufnr('$')) @@ -40,61 +34,57 @@ describe('ShaDa support code', function() end) it('does not dump buffer list without % in &shada', function() + reset() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - set_additional_cmd('set shada+=%') nvim_command('qall') - reset() + reset('set shada+=%') eq(1, funcs.bufnr('$')) eq('', funcs.bufname(1)) end) it('does not dump unlisted buffer', function() - set_additional_cmd('set shada+=%') - reset() + reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) curbufmeths.set_option('buflisted', false) nvim_command('qall') - reset() + reset('set shada+=%') eq(2, funcs.bufnr('$')) eq('', funcs.bufname(1)) eq(testfilename, funcs.bufname(2)) end) it('does not dump quickfix buffer', function() - set_additional_cmd('set shada+=%') - reset() + reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) curbufmeths.set_option('buftype', 'quickfix') nvim_command('qall') - reset() + reset('set shada+=%') eq(2, funcs.bufnr('$')) eq('', funcs.bufname(1)) eq(testfilename, funcs.bufname(2)) end) it('does not dump unnamed buffers', function() - set_additional_cmd('set shada+=% hidden') - reset() + reset('set shada+=% hidden') curbufmeths.set_lines(0, 1, true, {'foo'}) nvim_command('enew') curbufmeths.set_lines(0, 1, true, {'bar'}) eq(2, funcs.bufnr('$')) nvim_command('qall!') - reset() + reset('set shada+=% hidden') eq(1, funcs.bufnr('$')) eq('', funcs.bufname(1)) end) it('restores 1 buffer with %1 in &shada, #5759', function() - set_additional_cmd('set shada+=%1') - reset() + reset('set shada+=%1') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) nvim_command('qall') - reset() + reset('set shada+=%1') eq(2, funcs.bufnr('$')) eq('', funcs.bufname(1)) eq(testfilename, funcs.bufname(2)) diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index d5e061bb50..fb3ec4a87c 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -1,47 +1,39 @@ local helpers = require('test.functional.helpers')(nil) -local spawn, set_session, meths, nvim_prog = - helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog -local write_file, merge_args = helpers.write_file, helpers.merge_args +local meths = helpers.meths +local write_file = helpers.write_file +local concat_tables = helpers.concat_tables local mpack = require('mpack') local tmpname = helpers.tmpname() -local append_argv = nil -local function nvim_argv(shada_file, embed) - if embed == nil then - embed = true +-- o={ +-- args=…, +-- args_rm=…, +-- shadafile=…, +-- } +local function reset(o) + assert(o == nil or type(o) == 'table' or type(o) == 'string') + o = o and o or {} + local args_rm = o.args_rm or {} + table.insert(args_rm, '-i') + local args={ + '-i', o.shadafile or tmpname, + } + if type(o) == 'string' then + args = concat_tables(args, {'--cmd', o}) + elseif o.args then + args = concat_tables(args, o.args) end - local argv = {nvim_prog, '-u', 'NONE', '-i', shada_file or tmpname, '-N', - '--cmd', 'set shortmess+=I background=light noswapfile', - '--headless', embed and '--embed' or nil} - if helpers.prepend_argv or append_argv then - return merge_args(helpers.prepend_argv, argv, append_argv) - else - return argv - end -end - -local reset = function(shada_file) - set_session(spawn(nvim_argv(shada_file))) + helpers.clear{ + args_rm=args_rm, + args=args, + } meths.set_var('tmpname', tmpname) end -local set_additional_cmd = function(s) - append_argv = {'--cmd', s} -end - -local function add_argv(...) - if select('#', ...) == 0 then - append_argv = nil - else - append_argv = {...} - end -end - local clear = function() os.remove(tmpname) - append_argv = nil end local get_shada_rw = function(fname) @@ -89,10 +81,7 @@ end return { reset=reset, - set_additional_cmd=set_additional_cmd, - add_argv=add_argv, clear=clear, get_shada_rw=get_shada_rw, read_shada_file=read_shada_file, - nvim_argv=nvim_argv, } diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index e6450e68b3..e319fd9e6b 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -6,11 +6,7 @@ local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq = local exc_exec, redir_exec = helpers.exc_exec, helpers.redir_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear = - shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear -local add_argv = shada_helpers.add_argv -local nvim_argv = shada_helpers.nvim_argv +local reset, clear = shada_helpers.reset, shada_helpers.clear local nvim_current_line = function() return curwinmeths.get_cursor()[1] @@ -71,8 +67,7 @@ describe('ShaDa support code', function() nvim_command('2') nvim_command('kB') nvim_command('wshada') - set_additional_cmd('set shada=\'0,f0') - reset() + reset('set shada=\'0,f0') nvim_command('language C') nvim_command('normal! `A') eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) @@ -223,17 +218,32 @@ describe('ShaDa support code', function() -- during -c used to add item with zero lnum to jump list. it('does not create incorrect file for non-existent buffers when writing from -c', function() - add_argv('--cmd', 'silent edit ' .. non_existent_testfilename, '-c', 'qall') - local argv = nvim_argv(nil, false) -- no --embed + local argv = helpers.new_argv{ + args_rm={ + '-i', + '--embed', -- no --embed + }, + args={ + '-i', meths.get_var('tmpname'), -- Use same shada file as parent. + '--cmd', 'silent edit '..non_existent_testfilename, + '-c', 'qall'}, + } eq('', funcs.system(argv)) eq(0, exc_exec('rshada')) end) it('does not create incorrect file for non-existent buffers opened from -c', function() - add_argv('-c', 'silent edit ' .. non_existent_testfilename, - '-c', 'autocmd VimEnter * qall') - local argv = nvim_argv(nil, false) -- no --embed + local argv = helpers.new_argv{ + args_rm={ + '-i', + '--embed', -- no --embed + }, + args={ + '-i', meths.get_var('tmpname'), -- Use same shada file as parent. + '-c', 'silent edit '..non_existent_testfilename, + '-c', 'autocmd VimEnter * qall'}, + } eq('', funcs.system(argv)) eq(0, exc_exec('rshada')) end) diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index 71af14aba8..1f06cbe350 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -3,9 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear = - shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear +local reset, clear = shada_helpers.reset, shada_helpers.clear local setreg = function(name, contents, typ) if type(contents) == 'string' then @@ -52,9 +50,8 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - set_additional_cmd('set shada=\'0,<0') nvim_command('qall') - reset() + reset('set shada=\'0,<0') eq({{'d', 'e', ''}, 'v'}, getreg('c')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b')) @@ -76,9 +73,8 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - set_additional_cmd('set shada=\'0,\\"0') nvim_command('qall') - reset() + reset('set shada=\'0,\\"0') eq({{'d', 'e', ''}, 'v'}, getreg('c')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b')) @@ -142,7 +138,6 @@ describe('ShaDa support code', function() reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 setreg('e', {'\171«'}, 'c') - set_additional_cmd('') nvim_command('qall') reset() eq({{'\171«'}, 'v'}, getreg('e')) diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 5f7daf73e5..ff63aed235 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -15,7 +15,6 @@ local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw local read_shada_file = shada_helpers.read_shada_file -local set_additional_cmd = shada_helpers.set_additional_cmd local wshada, _, shada_fname, clean = get_shada_rw('Xtest-functional-shada-shada.shada') @@ -244,8 +243,7 @@ describe('ShaDa support code', function() funcs.mkdir(dirname, '', 0) eq(0, funcs.filewritable(dirname)) - set_additional_cmd('set shada=') - reset(dirshada) + reset{shadafile=dirshada, args={'--cmd', 'set shada='}} meths.set_option('shada', '\'10') eq('Vim(wshada):E886: System error while opening ShaDa file ' .. 'Xtest-functional-shada-shada.d/main.shada for reading to merge ' diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index f817bcef74..74bbceddcc 100644 --- a/test/functional/shada/variables_spec.lua +++ b/test/functional/shada/variables_spec.lua @@ -4,9 +4,7 @@ local meths, funcs, nvim_command, eq, exc_exec = helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear = - shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear +local reset, clear = shada_helpers.reset, shada_helpers.clear describe('ShaDa support code', function() before_each(reset) @@ -25,8 +23,7 @@ describe('ShaDa support code', function() local autotest = function(tname, varname, varval, val_is_expr) it('is able to dump and read back ' .. tname .. ' variable automatically', function() - set_additional_cmd('set shada+=!') - reset() + reset('set shada+=!') if val_is_expr then nvim_command('let g:' .. varname .. ' = ' .. varval) varval = meths.get_var(varname) @@ -36,7 +33,7 @@ describe('ShaDa support code', function() -- Exit during `reset` is not a regular exit: it does not write shada -- automatically nvim_command('qall') - reset() + reset('set shada+=!') eq(varval, meths.get_var(varname)) end) end @@ -55,8 +52,7 @@ describe('ShaDa support code', function() meths.set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') - set_additional_cmd('set shada-=!') - reset() + reset('set shada-=!') nvim_command('rshada') eq(0, funcs.exists('g:STRVAR')) end) @@ -98,7 +94,6 @@ describe('ShaDa support code', function() meths.set_var('LSTVAR', {'«'}) meths.set_var('DCTVAR', {['«']='«'}) meths.set_var('NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}}) - set_additional_cmd('') nvim_command('qall') reset() eq('«', meths.get_var('STRVAR')) @@ -131,11 +126,10 @@ describe('ShaDa support code', function() nvim_command('let F = function("tr")') meths.set_var('U', '10') nvim_command('set shada+=!') - set_additional_cmd('set shada+=!') eq('Vim(wshada):E5004: Error while dumping variable g:F, itself: attempt to dump function reference', exc_exec('wshada')) meths.set_option('shada', '') - reset() + reset('set shada+=!') eq('10', meths.get_var('U')) end) @@ -148,8 +142,7 @@ describe('ShaDa support code', function() eq('Vim(wshada):E5005: Unable to dump variable g:L: container references itself in index 0', exc_exec('wshada')) meths.set_option('shada', '') - set_additional_cmd('set shada+=!') - reset() + reset('set shada+=!') eq('10', meths.get_var('U')) end) end)