From 16336c486ecb5a60e85a870904316308c7d7fc3f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 25 Sep 2022 02:20:47 +0200 Subject: feat(gen_help_html.lua): adapt to new parser - adapt to parser changes from https://github.com/vigoux/tree-sitter-vimdoc/pull/16 - numerous other generator improvements --- test/functional/core/startup_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 4f9df4010e..a32c801c97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -354,7 +354,9 @@ describe('startup', function() local function pack_clear(cmd) -- add packages after config dir in rtp but before config/after - clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} + clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}, + args_rm={'runtimepath'}, + } end -- cgit From 4716a578ae0c3516d685495bb55e40c939a4ac87 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 23 Oct 2022 10:17:45 +0200 Subject: docs: fix typos --- test/functional/core/startup_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index a32c801c97..2084d365a5 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -637,7 +637,7 @@ describe('runtime:', function() end) it('loads plugin/*.lua from start packages', function() - local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory', + local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category', 'start', 'test_plugin'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, -- cgit From 5eb5f4948826e9d47685ea9e257409cc3e693614 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 22 Nov 2022 01:13:30 +0100 Subject: test: simplify platform detection (#21020) Extend the capabilities of is_os to detect more platforms such as freebsd and openbsd. Also remove `iswin()` helper function as it can be replaced by `is_os("win")`. --- test/functional/core/startup_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 2084d365a5..bab339e253 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -20,11 +20,11 @@ local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir local sleep = helpers.sleep -local iswin = helpers.iswin local startswith = helpers.startswith local write_file = helpers.write_file local meths = helpers.meths local alter_slashes = helpers.alter_slashes +local is_os = helpers.is_os local testfile = 'Xtest_startuptime' after_each(function() @@ -79,7 +79,7 @@ describe('startup', function() it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 4) screen:attach() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -95,7 +95,7 @@ describe('startup', function() ]]) end) it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -111,7 +111,7 @@ describe('startup', function() end) end) it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -130,7 +130,7 @@ describe('startup', function() it('input from pipe (implicit) #7679', function() local screen = Screen.new(25, 4) screen:attach() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -665,7 +665,7 @@ describe('runtime:', function() end) it('loads plugin/*.lua from site packages', function() - local nvimdata = iswin() and "nvim-data" or "nvim" + local nvimdata = is_os('win') and "nvim-data" or "nvim" local plugin_path = table.concat({xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) local plugin_after_path = table.concat({plugin_path, 'after', 'plugin'}, pathsep) -- cgit From 3f478547cfec72b9d3eb53efde2df45d85c44c18 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Sat, 26 Nov 2022 01:50:52 +0100 Subject: fix(startup): support .exrc or .nvimrc with init.lua (#21181) --- test/functional/core/startup_spec.lua | 64 +++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index bab339e253..41596f5416 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -12,6 +12,7 @@ local eval = helpers.eval local exec_lua = helpers.exec_lua local feed = helpers.feed local funcs = helpers.funcs +local pesc = helpers.pesc local mkdir = helpers.mkdir local mkdir_p = helpers.mkdir_p local nvim_prog = helpers.nvim_prog @@ -576,7 +577,66 @@ describe('user config init', function() eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) end) - describe 'with explicitly provided config'(function() + describe('with existing .exrc in cwd', function() + local exrc_path = '.exrc' + local xstate = 'Xstate' + + before_each(function() + write_file(init_lua_path, [[ + vim.o.exrc = true + vim.g.from_exrc = 0 + ]]) + mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + write_file(exrc_path, [[ + let g:from_exrc = 1 + ]]) + end) + + after_each(function() + os.remove(exrc_path) + rmdir(xstate) + end) + + it('loads .exrc #13501', function() + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The .exrc file is not trusted, and the prompt is skipped because there is no UI. + eq(0, eval('g:from_exrc')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) + -- `i` to enter Terminal mode, `a` to allow + feed('ia') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + | + -- TERMINAL -- | + ]]) + feed(':echo g:from_exrc') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + 1 | + -- TERMINAL -- | + ]]) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The .exrc file is now trusted. + eq(1, eval('g:from_exrc')) + end) + end) + + describe('with explicitly provided config', function() local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep) before_each(function() write_file(custom_lua_path, [[ @@ -591,7 +651,7 @@ describe('user config init', function() end) end) - describe 'VIMRC also exists'(function() + describe('VIMRC also exists', function() before_each(function() write_file(table.concat({xconfig, 'nvim', 'init.vim'}, pathsep), [[ let g:vim_rc = 1 -- cgit From 03166838abf23e3c2de55333fb2b9b0af34a2c56 Mon Sep 17 00:00:00 2001 From: Munif Tanjim Date: Tue, 20 Dec 2022 06:38:24 +0600 Subject: test(exrc): add tests for .nvimrc and .nvim.lua (#21478) --- test/functional/core/startup_spec.lua | 97 ++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 41596f5416..7664401824 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -581,15 +581,26 @@ describe('user config init', function() local exrc_path = '.exrc' local xstate = 'Xstate' + local function setup_exrc_file(filename) + exrc_path = filename + + if string.find(exrc_path, "%.lua$") then + write_file(exrc_path, string.format([[ + vim.g.exrc_file = "%s" + ]], exrc_path)) + else + write_file(exrc_path, string.format([[ + let g:exrc_file = "%s" + ]], exrc_path)) + end + end + before_each(function() write_file(init_lua_path, [[ vim.o.exrc = true - vim.g.from_exrc = 0 + vim.g.exrc_file = '---' ]]) mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - write_file(exrc_path, [[ - let g:from_exrc = 1 - ]]) end) after_each(function() @@ -597,43 +608,47 @@ describe('user config init', function() rmdir(xstate) end) - it('loads .exrc #13501', function() - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } - -- The .exrc file is not trusted, and the prompt is skipped because there is no UI. - eq(0, eval('g:from_exrc')) - - local screen = Screen.new(50, 8) - screen:attach() - funcs.termopen({nvim_prog}) - screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) - -- `i` to enter Terminal mode, `a` to allow - feed('ia') - screen:expect([[ - | - ~ | - ~ | - ~ | - ~ | - [No Name] 0,0-1 All| - | - -- TERMINAL -- | - ]]) - feed(':echo g:from_exrc') - screen:expect([[ - | - ~ | - ~ | - ~ | - ~ | - [No Name] 0,0-1 All| - 1 | - -- TERMINAL -- | - ]]) - - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } - -- The .exrc file is now trusted. - eq(1, eval('g:from_exrc')) - end) + for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do + it('loads ' .. filename, function () + setup_exrc_file(filename) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI. + eq('---', eval('g:exrc_file')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) + -- `i` to enter Terminal mode, `a` to allow + feed('ia') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + | + -- TERMINAL -- | + ]]) + feed(':echo g:exrc_file') + screen:expect(string.format([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + %s%s| + -- TERMINAL -- | + ]], filename, string.rep(' ', 50 - #filename))) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The 'exrc' file is now trusted. + eq(filename, eval('g:exrc_file')) + end) + end end) describe('with explicitly provided config', function() -- cgit From d7855caa183f9eacc7cfd3f2ab7f071063ff84af Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 30 Dec 2022 15:06:47 +0800 Subject: test: add test for setting &columns from modeline with tabpages --- test/functional/core/startup_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 7664401824..9e22efa545 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -465,6 +465,19 @@ describe('startup', function() clear{args={'--cmd', 'set packpath^=test/functional/fixtures', '--cmd', [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]]}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} eq({'ordinary', 'FANCY', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) end) + + it('window widths are correct when modelines set &columns with tabpages', function() + write_file('tab1.noft', 'vim: columns=81') + write_file('tab2.noft', 'vim: columns=81') + finally(function() + os.remove('tab1.noft') + os.remove('tab2.noft') + end) + clear({args = {'-p', 'tab1.noft', 'tab2.noft'}}) + eq(81, meths.win_get_width(0)) + command('tabnext') + eq(81, meths.win_get_width(0)) + end) end) describe('sysinit', function() -- cgit From 43e8ec92de9e0850e7d202cb7ff9051bc408447e Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 2 May 2022 21:10:01 +0200 Subject: fix(tui): more work in the TUI --- test/functional/core/startup_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 9e22efa545..72d8f3a103 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -544,7 +544,7 @@ describe('sysinit', function() nvim_exec() | cmd: aunmenu * | > | - <" -u NONE -i NONE --cmd "set noruler" -D 1,1 All| + <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| | ]]) command([[call chansend(g:id, "cont\n")]]) -- cgit From 7c94bcd2d77e2e54b8836ab8325460a367b79eae Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 20 Sep 2021 19:00:50 -0700 Subject: feat(lua)!: execute Lua with "nvim -l" Problem: Nvim has Lua but the "nvim" CLI can't easily be used to execute Lua scripts, especially scripts that take arguments or produce output. Solution: - support "nvim -l [args...]" for running scripts. closes #15749 - exit without +q - remove lua2dox_filter - remove Doxyfile. This wasn't used anyway, because the doxygen config is inlined in gen_vimdoc.py (`Doxyfile` variable). - use "nvim -l" in docs-gen CI job Examples: $ nvim -l scripts/lua2dox.lua --help Lua2DoX (0.2 20130128) ... $ echo "print(vim.inspect(_G.arg))" | nvim -l - --arg1 --arg2 $ echo 'print(vim.inspect(vim.api.nvim_buf_get_text(1,0,0,-1,-1,{})))' | nvim +"put ='text'" -l - TODO? -e executes Lua code -l loads a module -i enters REPL _after running the other arguments_. --- test/functional/core/startup_spec.lua | 149 ++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 26 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 72d8f3a103..1df8d76c97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -26,6 +26,7 @@ local write_file = helpers.write_file local meths = helpers.meths local alter_slashes = helpers.alter_slashes local is_os = helpers.is_os +local dedent = helpers.dedent local testfile = 'Xtest_startuptime' after_each(function() @@ -47,6 +48,34 @@ describe('startup', function() assert_log("require%('vim%._editor'%)", testfile, 100) end) end) + + it('-D does not hang #12647', function() + clear() + local screen + screen = Screen.new(60, 7) + screen:attach() + command([[let g:id = termopen('"]]..nvim_prog.. + [[" -u NONE -i NONE --cmd "set noruler" -D')]]) + screen:expect([[ + ^ | + | + Entering Debug mode. Type "cont" to continue. | + nvim_exec() | + cmd: aunmenu * | + > | + | + ]]) + command([[call chansend(g:id, "cont\n")]]) + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + [No Name] | + | + | + ]]) + end) end) describe('startup', function() @@ -58,6 +87,94 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) + describe('-l Lua', function() + local function assert_l_out(expected, args_before, args_after) + local args = { nvim_prog, '--clean' } + vim.list_extend(args, args_before or {}) + vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) + vim.list_extend(args, args_after or {}) + local out = funcs.system(args):gsub('\r\n', '\n') + return eq(dedent(expected), out) + end + + it('failure modes', function() + -- nvim -l + matches('nvim: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + eq(1, eval('v:shell_error')) + end) + + it('os.exit() sets Nvim exitcode', function() + -- nvim -l foo.lua -arg1 -- a b c + assert_l_out([[ + bufs: + args: { "-arg1", "--exitcode", "73", "--arg2" }]], + {}, + { '-arg1', "--exitcode", "73", '--arg2' } + ) + eq(73, eval('v:shell_error')) + end) + + it('sets _G.arg', function() + -- nvim -l foo.lua -arg1 -- a b c + assert_l_out([[ + bufs: + args: { "-arg1", "--arg2", "arg3" }]], + {}, + { '-arg1', '--arg2', 'arg3' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua -- + assert_l_out([[ + bufs: + args: {}]], + {}, + { '--' } + ) + eq(0, eval('v:shell_error')) + + -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 + assert_l_out([[ + bufs: file1 file2 file3 file4 + args: { "-arg1", "arg 2" }]], + { 'file1', 'file2', }, + { '-arg1', 'arg 2', '--', 'file3', 'file4' } + ) + eq(0, eval('v:shell_error')) + + -- nvim file1 file2 -l foo.lua -arg1 -- + assert_l_out([[ + bufs: file1 file2 + args: { "-arg1" }]], + { 'file1', 'file2', }, + { '-arg1', '--' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua + assert_l_out([[ + bufs: + args: { "-c", "set wrap?" }]], + {}, + { '-c', 'set wrap?' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua + assert_l_out( + -- luacheck: ignore 611 (Line contains only whitespaces) + [[ + wrap + + bufs: + args: { "-c", "set wrap?" }]], + { '-c', 'set wrap?' }, + { '-c', 'set wrap?' } + ) + eq(0, eval('v:shell_error')) + end) + end) + it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() -- system() puts a pipe at both ends. local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', @@ -66,6 +183,7 @@ describe('startup', function() '+q' }) eq('0 0', out) end) + it('with --embed: has("ttyin")==0 has("ttyout")==0', function() local screen = Screen.new(25, 3) -- Remote UI connected by --embed. @@ -77,6 +195,7 @@ describe('startup', function() 0 0 | ]]) end) + it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 4) screen:attach() @@ -95,6 +214,7 @@ describe('startup', function() | ]]) end) + it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) @@ -111,6 +231,7 @@ describe('startup', function() read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) @@ -128,6 +249,7 @@ describe('startup', function() read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe (implicit) #7679', function() local screen = Screen.new(25, 4) screen:attach() @@ -147,6 +269,7 @@ describe('startup', function() | ]]) end) + it('input from pipe + file args #7679', function() eq('ohyeah\r\n0 0 bufs=3', funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', @@ -532,32 +655,6 @@ describe('sysinit', function() eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')) end) - it('fixed hang issue with -D (#12647)', function() - local screen - screen = Screen.new(60, 7) - screen:attach() - command([[let g:id = termopen('"]]..nvim_prog.. - [[" -u NONE -i NONE --cmd "set noruler" -D')]]) - screen:expect([[ - ^ | - Entering Debug mode. Type "cont" to continue. | - nvim_exec() | - cmd: aunmenu * | - > | - <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| - | - ]]) - command([[call chansend(g:id, "cont\n")]]) - screen:expect([[ - ^ | - ~ | - ~ | - [No Name] | - | - <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| - | - ]]) - end) end) describe('user config init', function() -- cgit From 45549f031ee52a01601c33acc411f3111cfc4e95 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 1 Jan 2023 03:14:13 +0100 Subject: feat(lua): send "--" literally to Lua "-l" script Problem: When "-l" is followed by "--", we stop sending args to the Lua script and treat "--" in the usual way. This was for flexibility but didn't have a strong use-case, and has these problems: - prevents Lua "-l" scripts from handling "--" in their own way. - complicates the startup logic (must call nlua_init before command_line_scan) Solution: Don't treat "--" specially if it follows "-l". --- test/functional/core/startup_spec.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 1df8d76c97..dbd517995c 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -107,7 +107,8 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - args: { "-arg1", "--exitcode", "73", "--arg2" }]], + nvim args: 8 + lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } ) @@ -118,7 +119,8 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - args: { "-arg1", "--arg2", "arg3" }]], + nvim args: 7 + lua args: { "-arg1", "--arg2", "arg3" }]], {}, { '-arg1', '--arg2', 'arg3' } ) @@ -127,7 +129,8 @@ describe('startup', function() -- nvim -l foo.lua -- assert_l_out([[ bufs: - args: {}]], + nvim args: 5 + lua args: { "--" }]], {}, { '--' } ) @@ -135,8 +138,9 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 assert_l_out([[ - bufs: file1 file2 file3 file4 - args: { "-arg1", "arg 2" }]], + bufs: file1 file2 + nvim args: 11 + lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) @@ -145,7 +149,8 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- assert_l_out([[ bufs: file1 file2 - args: { "-arg1" }]], + nvim args: 8 + lua args: { "-arg1", "--" }]], { 'file1', 'file2', }, { '-arg1', '--' } ) @@ -154,7 +159,8 @@ describe('startup', function() -- nvim -l foo.lua assert_l_out([[ bufs: - args: { "-c", "set wrap?" }]], + nvim args: 6 + lua args: { "-c", "set wrap?" }]], {}, { '-c', 'set wrap?' } ) @@ -167,7 +173,8 @@ describe('startup', function() wrap bufs: - args: { "-c", "set wrap?" }]], + nvim args: 8 + lua args: { "-c", "set wrap?" }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) -- cgit From adef308a5925a3b967af3bd7c598074e5b6cae18 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 2 Jan 2023 15:34:14 +0100 Subject: feat(lua): exit 1 on Lua "-l" script error --- test/functional/core/startup_spec.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index dbd517995c..455de08548 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -88,11 +88,11 @@ describe('startup', function() end) describe('-l Lua', function() - local function assert_l_out(expected, args_before, args_after) + local function assert_l_out(expected, nvim_args, lua_args) local args = { nvim_prog, '--clean' } - vim.list_extend(args, args_before or {}) + vim.list_extend(args, nvim_args or {}) vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) - vim.list_extend(args, args_after or {}) + vim.list_extend(args, lua_args or {}) local out = funcs.system(args):gsub('\r\n', '\n') return eq(dedent(expected), out) end @@ -115,6 +115,13 @@ describe('startup', function() eq(73, eval('v:shell_error')) end) + it('Lua error sets Nvim exitcode', function() + eq(0, eval('v:shell_error')) + matches('E5113: .* my pearls!!', + funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) + eq(1, eval('v:shell_error')) + end) + it('sets _G.arg', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ @@ -396,11 +403,13 @@ describe('startup', function() { 'put =mode(1)', 'print', '' })) end) - it('fails on --embed with -es/-Es', function() - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es', + it('fails on --embed with -es/-Es/-l', function() + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-es' })) - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es', + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-Es' })) + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', + funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' })) end) it('does not crash if --embed is given twice', function() -- cgit From f43de742e881e54a3602e00c8c247cecca65a266 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Jan 2023 02:54:53 +0100 Subject: feat(lua): execute stdin ("-") as Lua --- test/functional/core/startup_spec.lua | 58 +++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 455de08548..d7e64c6b54 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -88,18 +88,18 @@ describe('startup', function() end) describe('-l Lua', function() - local function assert_l_out(expected, nvim_args, lua_args) - local args = { nvim_prog, '--clean' } + local function assert_l_out(expected, nvim_args, lua_args, script, input) + local args = { nvim_prog } vim.list_extend(args, nvim_args or {}) - vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) + vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, lua_args or {}) - local out = funcs.system(args):gsub('\r\n', '\n') + local out = funcs.system(args, input):gsub('\r\n', '\n') return eq(dedent(expected), out) end it('failure modes', function() - -- nvim -l - matches('nvim: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + -- nvim -l + matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) eq(1, eval('v:shell_error')) end) @@ -107,7 +107,7 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - nvim args: 8 + nvim args: 7 lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } @@ -115,18 +115,35 @@ describe('startup', function() eq(73, eval('v:shell_error')) end) - it('Lua error sets Nvim exitcode', function() + it('Lua-error sets Nvim exitcode', function() eq(0, eval('v:shell_error')) matches('E5113: .* my pearls!!', funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) eq(1, eval('v:shell_error')) + matches('E5113: .* %[string "error%("whoa"%)"%]:1: whoa', + funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")')) + eq(1, eval('v:shell_error')) + end) + + it('executes stdin "-"', function() + assert_l_out('args=2 whoa', + nil, + { 'arg1', 'arg 2' }, + '-', + "print(('args=%d %s'):format(#_G.arg, 'whoa'))") + assert_l_out('biiig input: 1000042', + nil, + nil, + '-', + ('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42))) + eq(0, eval('v:shell_error')) end) it('sets _G.arg', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - nvim args: 7 + nvim args: 6 lua args: { "-arg1", "--arg2", "arg3" }]], {}, { '-arg1', '--arg2', 'arg3' } @@ -136,7 +153,7 @@ describe('startup', function() -- nvim -l foo.lua -- assert_l_out([[ bufs: - nvim args: 5 + nvim args: 4 lua args: { "--" }]], {}, { '--' } @@ -146,7 +163,7 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 assert_l_out([[ bufs: file1 file2 - nvim args: 11 + nvim args: 10 lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } @@ -156,7 +173,7 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- assert_l_out([[ bufs: file1 file2 - nvim args: 8 + nvim args: 7 lua args: { "-arg1", "--" }]], { 'file1', 'file2', }, { '-arg1', '--' } @@ -166,7 +183,7 @@ describe('startup', function() -- nvim -l foo.lua assert_l_out([[ bufs: - nvim args: 6 + nvim args: 5 lua args: { "-c", "set wrap?" }]], {}, { '-c', 'set wrap?' } @@ -180,13 +197,22 @@ describe('startup', function() wrap bufs: - nvim args: 8 + nvim args: 7 lua args: { "-c", "set wrap?" }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) eq(0, eval('v:shell_error')) end) + + it('disables swapfile/shada/config/plugins', function() + assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scriptnames=1', + nil, + nil, + '-', + [[print(('updatecount=%d shadafile=%s loadplugins=%s scriptnames=%d'):format( + vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.split(vim.fn.execute('scriptnames'),'\n'))))]]) + end) end) it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() @@ -375,11 +401,11 @@ describe('startup', function() it('-es/-Es disables swapfile, user config #8540', function() for _,arg in ipairs({'-es', '-Es'}) do local out = funcs.system({nvim_prog, arg, - '+set swapfile? updatecount? shada?', + '+set swapfile? updatecount? shadafile?', "+put =execute('scriptnames')", '+%print'}) local line1 = string.match(out, '^.-\n') -- updatecount=0 means swapfile was disabled. - eq(" swapfile updatecount=0 shada=!,'100,<50,s10,h\n", line1) + eq(" swapfile updatecount=0 shadafile=\n", line1) -- Standard plugins were loaded, but not user config. eq('health.vim', string.match(out, 'health.vim')) eq(nil, string.match(out, 'init.vim')) -- cgit From e17430c1cd97db5624e27515a4f5da17f9d926d6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 7 Jan 2023 02:12:54 +0100 Subject: feat(lua): store "nvim -l" scriptname in _G.arg[0] --- test/functional/core/startup_spec.lua | 50 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index d7e64c6b54..9dabcd28b3 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -108,7 +108,9 @@ describe('startup', function() assert_l_out([[ bufs: nvim args: 7 - lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], + lua args: { "-arg1", "--exitcode", "73", "--arg2", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } ) @@ -126,11 +128,11 @@ describe('startup', function() end) it('executes stdin "-"', function() - assert_l_out('args=2 whoa', + assert_l_out('arg0=- args=2 whoa', nil, { 'arg1', 'arg 2' }, '-', - "print(('args=%d %s'):format(#_G.arg, 'whoa'))") + "print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))") assert_l_out('biiig input: 1000042', nil, nil, @@ -140,23 +142,15 @@ describe('startup', function() end) it('sets _G.arg', function() - -- nvim -l foo.lua -arg1 -- a b c - assert_l_out([[ - bufs: - nvim args: 6 - lua args: { "-arg1", "--arg2", "arg3" }]], - {}, - { '-arg1', '--arg2', 'arg3' } - ) - eq(0, eval('v:shell_error')) - - -- nvim -l foo.lua -- + -- nvim -l foo.lua [args] assert_l_out([[ bufs: - nvim args: 4 - lua args: { "--" }]], + nvim args: 7 + lua args: { "-arg1", "--arg2", "--", "arg3", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, - { '--' } + { '-arg1', '--arg2', '--', 'arg3' } ) eq(0, eval('v:shell_error')) @@ -164,27 +158,21 @@ describe('startup', function() assert_l_out([[ bufs: file1 file2 nvim args: 10 - lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], + lua args: { "-arg1", "arg 2", "--", "file3", "file4", + [0] = "test/functional/fixtures/startup.lua" + }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) eq(0, eval('v:shell_error')) - -- nvim file1 file2 -l foo.lua -arg1 -- - assert_l_out([[ - bufs: file1 file2 - nvim args: 7 - lua args: { "-arg1", "--" }]], - { 'file1', 'file2', }, - { '-arg1', '--' } - ) - eq(0, eval('v:shell_error')) - -- nvim -l foo.lua assert_l_out([[ bufs: nvim args: 5 - lua args: { "-c", "set wrap?" }]], + lua args: { "-c", "set wrap?", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, { '-c', 'set wrap?' } ) @@ -198,7 +186,9 @@ describe('startup', function() bufs: nvim args: 7 - lua args: { "-c", "set wrap?" }]], + lua args: { "-c", "set wrap?", + [0] = "test/functional/fixtures/startup.lua" + }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) -- cgit