From 7d58de11f49c574a8a305e28e96b9ff810493012 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Feb 2023 18:25:01 +0800 Subject: fix(rpc)!: preseve files when stdio channel is closed (#22137) BREAKING CHANGE: Unsaved changes are now preserved rather than discarded when stdio channel is closed. --- test/functional/ex_cmds/oldfiles_spec.lua | 5 ++ test/functional/ex_cmds/profile_spec.lua | 1 + .../ex_cmds/swapfile_preserve_recover_spec.lua | 63 ++++++++++++++++------ 3 files changed, 53 insertions(+), 16 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 5f87c3cdd9..19611429e0 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -2,6 +2,8 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear +local command = helpers.command +local expect_exit = helpers.expect_exit local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local ok = helpers.ok @@ -19,6 +21,7 @@ describe(':oldfiles', function() before_each(_clear) after_each(function() + expect_exit(command, 'qall!') os.remove(shada_file) end) @@ -42,6 +45,7 @@ describe(':oldfiles', function() | Press ENTER or type command to continue^ | ]]) + feed('') end) it('can be filtered with :filter', function() @@ -107,6 +111,7 @@ describe(':browse oldfiles', function() end) after_each(function() + expect_exit(command, 'qall!') os.remove(shada_file) end) diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua index 2b92f8d0de..bf045a4d1d 100644 --- a/test/functional/ex_cmds/profile_spec.lua +++ b/test/functional/ex_cmds/profile_spec.lua @@ -30,6 +30,7 @@ describe(':profile', function() before_each(helpers.clear) after_each(function() + helpers.expect_exit(command, 'qall!') if lfs.attributes(tempfile, 'uid') ~= nil then os.remove(tempfile) end diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index 8eed00c973..ad59025d47 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -13,6 +13,7 @@ local nvim_prog = helpers.nvim_prog local ok = helpers.ok local rmdir = helpers.rmdir local new_argv = helpers.new_argv +local new_pipename = helpers.new_pipename local pesc = helpers.pesc local os_kill = helpers.os_kill local set_session = helpers.set_session @@ -37,10 +38,21 @@ describe(':recover', function() end) -describe(':preserve', function() +describe("preserve and (R)ecover with custom 'directory'", function() local swapdir = lfs.currentdir()..'/Xtest_recover_dir' + local testfile = 'Xtest_recover_file1' + -- Put swapdir at the start of the 'directory' list. #1836 + -- Note: `set swapfile` *must* go after `set directory`: otherwise it may + -- attempt to create a swapfile in different directory. + local init = [[ + set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// + set swapfile fileformat=unix undolevels=-1 + ]] + + local nvim1 before_each(function() - clear() + nvim1 = spawn(new_argv()) + set_session(nvim1) rmdir(swapdir) lfs.mkdir(swapdir) end) @@ -49,25 +61,15 @@ describe(':preserve', function() rmdir(swapdir) end) - it("saves to custom 'directory' and (R)ecovers #1836", function() - local testfile = 'Xtest_recover_file1' - -- Put swapdir at the start of the 'directory' list. #1836 - -- Note: `set swapfile` *must* go after `set directory`: otherwise it may - -- attempt to create a swapfile in different directory. - local init = [[ - set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// - set swapfile fileformat=unix undolevels=-1 - ]] - + local function setup_swapname() exec(init) command('edit! '..testfile) feed('isometext') - command('preserve') exec('redir => g:swapname | silent swapname | redir END') + return eval('g:swapname') + end - local swappath1 = eval('g:swapname') - - os_kill(eval('getpid()')) + local function test_recover(swappath1) -- Start another Nvim instance. local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true) @@ -90,6 +92,35 @@ describe(':preserve', function() -- Verify that :swapname was not truncated (:help 'shortmess'). ok(nil == string.find(swappath1, '%.%.%.')) ok(nil == string.find(swappath2, '%.%.%.')) + end + + it('with :preserve and SIGKILL', function() + local swappath1 = setup_swapname() + command('preserve') + os_kill(eval('getpid()')) + test_recover(swappath1) + end) + + it('closing stdio channel without :preserve #22096', function() + local swappath1 = setup_swapname() + nvim1:close() + test_recover(swappath1) + end) + + it('killing TUI process without :preserve #22096', function() + helpers.skip(helpers.is_os('win')) + local screen = Screen.new() + screen:attach() + local child_server = new_pipename() + funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server}) + screen:expect({any = pesc('[No Name]')}) -- Wait for the child process to start. + local child_session = helpers.connect(child_server) + set_session(child_session) + local swappath1 = setup_swapname() + set_session(nvim1) + command('call chanclose(&channel)') -- Kill the child process. + screen:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop. + test_recover(swappath1) end) end) -- cgit From 9b9f8dfcc41ceb80d3970eb58af8ee350b57dc7f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 18 Feb 2023 09:27:10 +0800 Subject: test: make {MATCH:} behave less unexpectedly in screen:expect() Include the rest of the line and allow multiple {MATCH:} patterns. --- test/functional/ex_cmds/trust_spec.lua | 117 +++------------------------------ 1 file changed, 10 insertions(+), 107 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua index 10ee02a790..fe13bd7cd2 100644 --- a/test/functional/ex_cmds/trust_spec.lua +++ b/test/functional/ex_cmds/trust_spec.lua @@ -1,9 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) -local Screen = require('test.functional.ui.screen') local eq = helpers.eq local clear = helpers.clear local command = helpers.command +local exec_capture = helpers.exec_capture +local matches = helpers.matches local pathsep = helpers.get_pathsep() local is_os = helpers.is_os local funcs = helpers.funcs @@ -29,147 +30,49 @@ describe(':trust', function() end) it('trust then deny then remove a file using current buffer', function() - local screen = Screen.new(80, 8) - screen:attach() - screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - }) - local cwd = funcs.getcwd() local hash = funcs.sha256(helpers.read_file('test_file')) command('edit test_file') - command('trust') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}| - ]]) + matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++deny') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| - ]]) + matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++remove') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| - ]]) + matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then trust then remove a file using current buffer', function() - local screen = Screen.new(80, 8) - screen:attach() - screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - }) - local cwd = funcs.getcwd() local hash = funcs.sha256(helpers.read_file('test_file')) command('edit test_file') - command('trust ++deny') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| - ]]) + matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}| - ]]) + matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++remove') - screen:expect([[ - ^test | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| - ]]) + matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then remove a file using file path', function() - local screen = Screen.new(80, 8) - screen:attach() - screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - }) - local cwd = funcs.getcwd() - command('trust ++deny test_file') - screen:expect([[ - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| - ]]) + matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file')) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - command('trust ++remove test_file') - screen:expect([[ - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| - ]]) + matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove test_file')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) -- cgit From 524e1a06432ed7a88c1e183d81812dd48dc18cfb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Feb 2023 16:15:04 +0800 Subject: fix(highlight): avoid ORing underline flags (#22372) When combining attributes use the one that takes priority. For :highlight command use the last one specified. For API use a hard-coded order same as the order in docs. --- test/functional/ex_cmds/highlight_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 1cd6759a53..18f215cf75 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -36,4 +36,13 @@ describe(':highlight', function() command('highlight normal ctermbg=red') eq('9', eval('synIDattr(hlID("Normal"), "bg", "cterm")')) end) + + it('only the last underline style takes effect #22371', function() + command('highlight NonText gui=underline,undercurl') + eq('', eval('synIDattr(hlID("NonText"), "underline", "gui")')) + eq('1', eval('synIDattr(hlID("NonText"), "undercurl", "gui")')) + command('highlight NonText gui=undercurl,underline') + eq('', eval('synIDattr(hlID("NonText"), "undercurl", "gui")')) + eq('1', eval('synIDattr(hlID("NonText"), "underline", "gui")')) + end) end) -- cgit From 6d0c61d90d316473eee0729363e20bf06825b09b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Mar 2023 21:09:11 +0800 Subject: fix(api): set script context when setting usercmd or option (#22624) --- test/functional/ex_cmds/verbose_spec.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index 000e746f1c..e55372e993 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture local write_file = helpers.write_file local call_viml_function = helpers.meths.call_function -describe('lua :verbose', function() +local function last_set_tests(cmd) local script_location, script_file -- All test cases below use the same nvim instance. setup(function() @@ -46,7 +46,7 @@ endfunction\ let &tw = s:return80()\ ", true) ]]) - exec(':source '..script_file) + exec(cmd .. ' ' .. script_file) end) teardown(function() @@ -106,6 +106,9 @@ test_group FileType end) it('"Last set" for command defined by nvim_command', function() + if cmd == 'luafile' then + pending('nvim_command does not set the script context') + end local result = exec_capture(':verbose command Bdelete') eq(string.format([[ Name Args Address Complete Definition @@ -123,7 +126,7 @@ test_group FileType script_location), result) end) - it('"Last set for function', function() + it('"Last set" for function', function() local result = exec_capture(':verbose function Close_Window') eq(string.format([[ function Close_Window() abort @@ -140,6 +143,14 @@ test_group FileType Last set from %s line 22]], script_location), result) end) +end + +describe('lua :verbose when using :source', function() + last_set_tests('source') +end) + +describe('lua :verbose when using :luafile', function() + last_set_tests('luafile') end) describe('lua verbose:', function() -- cgit From 9d574f8dd7248a4cf8dcbe615f3058d34efb7ac3 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Mar 2023 22:56:16 +0100 Subject: ci: bump to windows 2022 Skip failing funcitonaltests. Use jobstart() instead termopen() for oldtests to prevent CI freezing. --- test/functional/ex_cmds/mksession_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 0a0c7ca410..0a1cdd93aa 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -18,6 +18,8 @@ local is_os = helpers.is_os local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' +if helpers.skip(helpers.is_os('win')) then return end + describe(':mksession', function() local session_file = file_prefix .. '.vim' local tab_dir = file_prefix .. '.d' -- cgit From 846a056744bf458d4376cd7638c94f7c82862046 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 9 Mar 2023 11:45:20 +0100 Subject: refactor(redraw): make cursor position redraw use the "redraw later" pattern --- test/functional/ex_cmds/map_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index ec912053b2..a197b81cc5 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -152,7 +152,7 @@ describe('Screen', function() ~ | ~ | ~ | - > | + -- INSERT -- | ]]) end) -- cgit From ecc4d0e435d618828b938d78fbded7fbe1314760 Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Mon, 20 Mar 2023 03:25:12 +0600 Subject: fix(shell): on Windows :make does not echo #22728 Problem: On Windows, :make does not display the output of the program it runs. The cause is the default 'shellpipe'. On Linux, nvim uses `tee` to redirect the output to both stdout and the error file. In Windows, for both cmd.exe and powershell, the output is only redirected to the error file. Solution: - On Windows, change the 'shellpipe' default to "2>&1| tee". - Nvim includes `tee` in its Windows package. - Document recommended defaults for powershell. Fixes #12910 --- test/functional/ex_cmds/make_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index bf585ee44c..f42e21e4cb 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -34,8 +34,8 @@ describe(':make', function() nvim('set_option', 'makeprg', testprg('shell-test')) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between - -- command and last line (indicating zero exit) - matches('LastExitCode%s+[(]', out) + -- command and last line (indicating zero exit) + matches('LastExitCode%s+ready [$]%s+[(]', out) matches('\n.*%: ready [$]', out) end) -- cgit From fe9cbcb3a5c82932ecfb8f49d07e98a1fc2b31e5 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sat, 25 Mar 2023 18:58:48 +0200 Subject: feat(api): nvim_exec2(), deprecate nvim_exec() #19032 Problem: The signature of nvim_exec() is not extensible per ":help api-contract". Solution: Introduce nvim_exec2() and deprecate nvim_exec(). --- test/functional/ex_cmds/script_spec.lua | 4 ++-- test/functional/ex_cmds/source_spec.lua | 20 ++++++++++---------- test/functional/ex_cmds/verbose_spec.lua | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index bf69ada820..d13268c97c 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -34,7 +34,7 @@ describe('script_get-based command', function() %s %s endif ]])):format(cmd, garbage))) - eq('', meths.exec('messages', true)) + eq('', meths.exec2('messages', { output = true }).output) if check_neq then neq(0, exc_exec(dedent([[ %s %s @@ -49,7 +49,7 @@ describe('script_get-based command', function() EOF endif ]])):format(cmd, garbage))) - eq('', meths.exec('messages', true)) + eq('', meths.exec2('messages', { output = true }).output) if check_neq then eq(true, pcall(source, (dedent([[ let g:exc = 0 diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 64c3464be7..e12ead240d 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -96,12 +96,12 @@ describe(':source', function() let d = s:s]]) command('source') - eq('2', meths.exec('echo a', true)) - eq("{'k': 'v'}", meths.exec('echo b', true)) + eq('2', meths.exec2('echo a', { output = true }).output) + eq("{'k': 'v'}", meths.exec2('echo b', { output = true }).output) -- Script items are created only on script var access - eq("1", meths.exec('echo c', true)) - eq("0zBEEFCAFE", meths.exec('echo d', true)) + eq("1", meths.exec2('echo c', { output = true }).output) + eq("0zBEEFCAFE", meths.exec2('echo d', { output = true }).output) exec('set cpoptions+=C') eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) @@ -124,14 +124,14 @@ describe(':source', function() -- Source the 2nd line only feed('ggjV') feed_command(':source') - eq('3', meths.exec('echo a', true)) + eq('3', meths.exec2('echo a', { output = true }).output) -- Source from 2nd line to end of file feed('ggjVG') feed_command(':source') - eq('4', meths.exec('echo a', true)) - eq("{'K': 'V'}", meths.exec('echo b', true)) - eq("1_C()", meths.exec('echo D()', true)) + eq('4', meths.exec2('echo a', { output = true }).output) + eq("{'K': 'V'}", meths.exec2('echo b', { output = true }).output) + eq("1_C()", meths.exec2('echo D()', { output = true }).output) -- Source last line only feed_command(':$source') @@ -147,7 +147,7 @@ describe(':source', function() let a = 123 ]] command('source') - eq('123', meths.exec('echo a', true)) + eq('123', meths.exec2('echo a', { output = true }).output) end) it('multiline heredoc command', function() @@ -157,7 +157,7 @@ describe(':source', function() EOF]]) command('source') - eq('4', meths.exec('echo luaeval("y")', true)) + eq('4', meths.exec2('echo luaeval("y")', { output = true }).output) end) it('can source lua files', function() diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index e55372e993..2482fd912f 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -24,11 +24,11 @@ vim.opt.number = true vim.api.nvim_set_keymap('n', 'key1', ':echo "test"', {noremap = true}) vim.keymap.set('n', 'key2', ':echo "test"') -vim.api.nvim_exec("augroup test_group\ +vim.api.nvim_exec2("augroup test_group\ autocmd!\ autocmd FileType c setl cindent\ augroup END\ - ", false) + ", { output = false }) vim.api.nvim_command("command Bdelete :bd") vim.api.nvim_create_user_command("TestCommand", ":echo 'Hello'", {}) -- cgit From 4863ca6b8902c5b0aab95f2af640118cd417d379 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Mar 2023 10:49:32 +0800 Subject: test: use exec_capture() in more places (#22787) Problem: Using `meths.exec2("code", { output = true })` is too verbose. Solution: Use exec_capture() in more places. --- test/functional/ex_cmds/script_spec.lua | 5 +++-- test/functional/ex_cmds/source_spec.lua | 20 ++++++++++---------- test/functional/ex_cmds/verbose_spec.lua | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index d13268c97c..62249caa5e 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local neq = helpers.neq local command = helpers.command +local exec_capture = helpers.exec_capture local write_file = helpers.write_file local meths = helpers.meths local clear = helpers.clear @@ -34,7 +35,7 @@ describe('script_get-based command', function() %s %s endif ]])):format(cmd, garbage))) - eq('', meths.exec2('messages', { output = true }).output) + eq('', exec_capture('messages')) if check_neq then neq(0, exc_exec(dedent([[ %s %s @@ -49,7 +50,7 @@ describe('script_get-based command', function() EOF endif ]])):format(cmd, garbage))) - eq('', meths.exec2('messages', { output = true }).output) + eq('', exec_capture('messages')) if check_neq then eq(true, pcall(source, (dedent([[ let g:exc = 0 diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index e12ead240d..41045f5cb4 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -96,12 +96,12 @@ describe(':source', function() let d = s:s]]) command('source') - eq('2', meths.exec2('echo a', { output = true }).output) - eq("{'k': 'v'}", meths.exec2('echo b', { output = true }).output) + eq('2', exec_capture('echo a')) + eq("{'k': 'v'}", exec_capture('echo b')) -- Script items are created only on script var access - eq("1", meths.exec2('echo c', { output = true }).output) - eq("0zBEEFCAFE", meths.exec2('echo d', { output = true }).output) + eq("1", exec_capture('echo c')) + eq("0zBEEFCAFE", exec_capture('echo d')) exec('set cpoptions+=C') eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) @@ -124,14 +124,14 @@ describe(':source', function() -- Source the 2nd line only feed('ggjV') feed_command(':source') - eq('3', meths.exec2('echo a', { output = true }).output) + eq('3', exec_capture('echo a')) -- Source from 2nd line to end of file feed('ggjVG') feed_command(':source') - eq('4', meths.exec2('echo a', { output = true }).output) - eq("{'K': 'V'}", meths.exec2('echo b', { output = true }).output) - eq("1_C()", meths.exec2('echo D()', { output = true }).output) + eq('4', exec_capture('echo a')) + eq("{'K': 'V'}", exec_capture('echo b')) + eq("1_C()", exec_capture('echo D()')) -- Source last line only feed_command(':$source') @@ -147,7 +147,7 @@ describe(':source', function() let a = 123 ]] command('source') - eq('123', meths.exec2('echo a', { output = true }).output) + eq('123', exec_capture('echo a')) end) it('multiline heredoc command', function() @@ -157,7 +157,7 @@ describe(':source', function() EOF]]) command('source') - eq('4', meths.exec2('echo luaeval("y")', { output = true }).output) + eq('4', exec_capture('echo luaeval("y")')) end) it('can source lua files', function() diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index 2482fd912f..def09e2f9e 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -28,7 +28,7 @@ vim.api.nvim_exec2("augroup test_group\ autocmd!\ autocmd FileType c setl cindent\ augroup END\ - ", { output = false }) + ", {}) vim.api.nvim_command("command Bdelete :bd") vim.api.nvim_create_user_command("TestCommand", ":echo 'Hello'", {}) -- cgit From 743860de40502227b3f0ed64317eb937d24d4a36 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 21:59:06 +0200 Subject: test: replace lfs with luv and vim.fs test: replace lfs with luv luv already pretty much does everything lfs does, so this duplication of dependencies isn't needed. --- test/functional/ex_cmds/cd_spec.lua | 9 +++++---- test/functional/ex_cmds/file_spec.lua | 7 ++++--- test/functional/ex_cmds/mksession_spec.lua | 4 ++-- test/functional/ex_cmds/mkview_spec.lua | 6 +++--- test/functional/ex_cmds/profile_spec.lua | 12 +++++------- test/functional/ex_cmds/swapfile_preserve_recover_spec.lua | 13 +++++++------ test/functional/ex_cmds/write_spec.lua | 4 ++-- test/functional/ex_cmds/wviminfo_spec.lua | 8 ++++---- 8 files changed, 32 insertions(+), 31 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index 5ed71651c7..b6a3713158 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -1,6 +1,6 @@ -- Specs for :cd, :tcd, :lcd and getcwd() -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq @@ -11,6 +11,7 @@ local exc_exec = helpers.exc_exec local pathsep = helpers.get_pathsep() local skip = helpers.skip local is_os = helpers.is_os +local mkdir = helpers.mkdir -- These directories will be created for testing local directories = { @@ -36,14 +37,14 @@ for _, cmd in ipairs {'cd', 'chdir'} do before_each(function() clear() for _, d in pairs(directories) do - lfs.mkdir(d) + mkdir(d) end directories.start = cwd() end) after_each(function() for _, d in pairs(directories) do - lfs.rmdir(d) + luv.fs_rmdir(d) end end) @@ -273,7 +274,7 @@ end describe("getcwd()", function () before_each(function() clear() - lfs.mkdir(directories.global) + mkdir(directories.global) end) after_each(function() diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua index 771c283134..131661828e 100644 --- a/test/functional/ex_cmds/file_spec.lua +++ b/test/functional/ex_cmds/file_spec.lua @@ -1,17 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local clear = helpers.clear local command = helpers.command local eq = helpers.eq local funcs = helpers.funcs local rmdir = helpers.rmdir +local mkdir = helpers.mkdir describe(':file', function() - local swapdir = lfs.currentdir()..'/Xtest-file_spec' + local swapdir = luv.cwd()..'/Xtest-file_spec' before_each(function() clear() rmdir(swapdir) - lfs.mkdir(swapdir) + mkdir(swapdir) end) after_each(function() command('%bwipeout!') diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 0a1cdd93aa..d70ccb5b39 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -1,4 +1,3 @@ -local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') @@ -15,6 +14,7 @@ local sleep = helpers.sleep local meths = helpers.meths local skip = helpers.skip local is_os = helpers.is_os +local mkdir = helpers.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' @@ -26,7 +26,7 @@ describe(':mksession', function() before_each(function() clear() - lfs.mkdir(tab_dir) + mkdir(tab_dir) end) after_each(function() diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua index fef8065b2e..f71b826210 100644 --- a/test/functional/ex_cmds/mkview_spec.lua +++ b/test/functional/ex_cmds/mkview_spec.lua @@ -1,4 +1,3 @@ -local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear @@ -7,6 +6,7 @@ local get_pathsep = helpers.get_pathsep local eq = helpers.eq local funcs = helpers.funcs local rmdir = helpers.rmdir +local mkdir = helpers.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec' @@ -17,8 +17,8 @@ describe(':mkview', function() before_each(function() clear() - lfs.mkdir(view_dir) - lfs.mkdir(local_dir) + mkdir(view_dir) + mkdir(local_dir) end) after_each(function() diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua index bf045a4d1d..249373a9c4 100644 --- a/test/functional/ex_cmds/profile_spec.lua +++ b/test/functional/ex_cmds/profile_spec.lua @@ -1,5 +1,5 @@ require('os') -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eval = helpers.eval @@ -12,18 +12,16 @@ local read_file = helpers.read_file -- tmpname() also creates the file on POSIX systems. Remove it again. -- We just need the name, ignoring any race conditions. -if lfs.attributes(tempfile, 'uid') then +if luv.fs_stat(tempfile).uid then os.remove(tempfile) end local function assert_file_exists(filepath) - -- Use 2-argument lfs.attributes() so no extra table gets created. - -- We don't really care for the uid. - neq(nil, lfs.attributes(filepath, 'uid')) + neq(nil, luv.fs_stat(filepath).uid) end local function assert_file_exists_not(filepath) - eq(nil, lfs.attributes(filepath, 'uid')) + eq(nil, luv.fs_stat(filepath)) end describe(':profile', function() @@ -31,7 +29,7 @@ describe(':profile', function() after_each(function() helpers.expect_exit(command, 'qall!') - if lfs.attributes(tempfile, 'uid') ~= nil then + if luv.fs_stat(tempfile).uid ~= nil then os.remove(tempfile) end end) diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index ad59025d47..639bc6c94e 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -1,6 +1,5 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') local luv = require('luv') local eq, eval, expect, exec = helpers.eq, helpers.eval, helpers.expect, helpers.exec @@ -21,6 +20,7 @@ local spawn = helpers.spawn local nvim_async = helpers.nvim_async local expect_msg_seq = helpers.expect_msg_seq local pcall_err = helpers.pcall_err +local mkdir = helpers.mkdir describe(':recover', function() before_each(clear) @@ -39,7 +39,7 @@ describe(':recover', function() end) describe("preserve and (R)ecover with custom 'directory'", function() - local swapdir = lfs.currentdir()..'/Xtest_recover_dir' + local swapdir = luv.cwd()..'/Xtest_recover_dir' local testfile = 'Xtest_recover_file1' -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may @@ -54,7 +54,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() nvim1 = spawn(new_argv()) set_session(nvim1) rmdir(swapdir) - lfs.mkdir(swapdir) + mkdir(swapdir) end) after_each(function() command('%bwipeout!') @@ -126,7 +126,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() end) describe('swapfile detection', function() - local swapdir = lfs.currentdir()..'/Xtest_swapdialog_dir' + local swapdir = luv.cwd()..'/Xtest_swapdialog_dir' local nvim0 -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may @@ -139,7 +139,7 @@ describe('swapfile detection', function() nvim0 = spawn(new_argv()) set_session(nvim0) rmdir(swapdir) - lfs.mkdir(swapdir) + mkdir(swapdir) end) after_each(function() set_session(nvim0) @@ -361,7 +361,8 @@ describe('swapfile detection', function() ]]) -- pretend that the swapfile was created before boot - lfs.touch(swname, os.time() - luv.uptime() - 10) + local atime = os.time() - luv.uptime() - 10 + luv.fs_utime(swname, atime, atime) feed(':edit Xswaptest') screen:expect({any = table.concat({ diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 1ccd27875e..126646f21a 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local eq, eval, clear, write_file, source, insert = helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.source, helpers.insert @@ -153,7 +153,7 @@ describe(':write', function() end write_file(fname_bak, 'TTYX') skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) - lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true) + luv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname) eq('Vim(write):E166: Can\'t open linked file for writing', pcall_err(command, 'write!')) end) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 861a977ea6..7525343891 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local clear = helpers.clear local command, eq, neq, write_file = helpers.command, helpers.eq, helpers.neq, helpers.write_file @@ -21,10 +21,10 @@ describe(':wshada', function() it('creates a shada file', function() -- file should _not_ exist - eq(nil, lfs.attributes(shada_file)) + eq(nil, luv.fs_stat(shada_file)) command('wsh! '..shada_file) -- file _should_ exist - neq(nil, lfs.attributes(shada_file)) + neq(nil, luv.fs_stat(shada_file)) end) it('overwrites existing files', function() @@ -35,7 +35,7 @@ describe(':wshada', function() -- sanity check eq(text, read_file(shada_file)) - neq(nil, lfs.attributes(shada_file)) + neq(nil, luv.fs_stat(shada_file)) command('wsh! '..shada_file) -- cgit From 4ce0ada0d4c8c57a181ab08717a3d052d46ae158 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Apr 2023 16:57:47 +0800 Subject: fix(highlight): add missing g: prefix for colors_name (#22952) Fix #22951. This was fixed in Vim in patch 8.2.0613. --- test/functional/ex_cmds/highlight_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 18f215cf75..45764e6719 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -3,6 +3,9 @@ local helpers = require("test.functional.helpers")(after_each) local eq, command = helpers.eq, helpers.command local clear = helpers.clear local eval, exc_exec = helpers.eval, helpers.exc_exec +local exec = helpers.exec +local funcs = helpers.funcs +local meths = helpers.meths describe(':highlight', function() local screen @@ -45,4 +48,20 @@ describe(':highlight', function() eq('', eval('synIDattr(hlID("NonText"), "undercurl", "gui")')) eq('1', eval('synIDattr(hlID("NonText"), "underline", "gui")')) end) + + it('clear', function() + meths.set_var('colors_name', 'foo') + eq(1, funcs.exists('g:colors_name')) + command('hi clear') + eq(0, funcs.exists('g:colors_name')) + meths.set_var('colors_name', 'foo') + eq(1, funcs.exists('g:colors_name')) + exec([[ + func HiClear() + hi clear + endfunc + ]]) + funcs.HiClear() + eq(0, funcs.exists('g:colors_name')) + end) end) -- cgit From 75d9c413d49261b8f9a96f45edda0af9f0e8d947 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Apr 2023 17:44:08 +0800 Subject: fix(excmd): make :def unknown rather than unimplemented (#23150) --- test/functional/ex_cmds/excmd_spec.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index e243f3c524..b313d6428c 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -2,6 +2,7 @@ local helpers = require("test.functional.helpers")(after_each) local command = helpers.command local eq = helpers.eq local clear = helpers.clear +local funcs = helpers.funcs local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -26,5 +27,18 @@ describe('Ex cmds', function() pcall_err(command, ':bdelete 9999999999999999999999999999999999999999')) assert_alive() end) -end) + it(':def is an unknown command #23149', function() + eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) + eq(1, funcs.exists(':d')) + eq('delete', funcs.fullcommand('d')) + eq(1, funcs.exists(':de')) + eq('delete', funcs.fullcommand('de')) + eq(0, funcs.exists(':def')) + eq('', funcs.fullcommand('def')) + eq(1, funcs.exists(':defe')) + eq('defer', funcs.fullcommand('defe')) + eq(2, funcs.exists(':defer')) + eq('defer', funcs.fullcommand('defer')) + end) +end) -- cgit From 9e79f7433eb0e8c5ab9b7c84ac7670aac2f56671 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 21 Apr 2023 13:16:32 +0200 Subject: fix(usercmd): Fix buffer overflow in uc_list() (#23225) fix(usercmd): fix buffer overflow in uc_list() Build with: -Wp,-D_FORTIFY_SOURCE=3 -O1 and gcc 13. *** buffer overflow detected ***: terminated (gdb) bt #0 __pthread_kill_implementation (threadid=, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 #1 0x00007f3eb8b93c03 in __pthread_kill_internal (signo=6, threadid=) at pthread_kill.c:78 #2 0x00007f3eb8b42aee in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 #3 0x00007f3eb8b2b87f in __GI_abort () at abort.c:79 #4 0x00007f3eb8b2c60f in __libc_message (fmt=fmt@entry=0x7f3eb8ca72e6 "*** %s ***: terminated\n") at ../sysdeps/posix/libc_fatal.c:150 #5 0x00007f3eb8c27b29 in __GI___fortify_fail (msg=msg@entry=0x7f3eb8ca728c "buffer overflow detected") at fortify_fail.c:24 #6 0x00007f3eb8c26364 in __GI___chk_fail () at chk_fail.c:28 #7 0x00007f3eb8c25f45 in ___snprintf_chk (s=s@entry=0x55b8c7c096a5 "t' item", maxlen=maxlen@entry=1025, flag=flag@entry=2, slen=slen@entry=1020, format=format@entry=0x55b8c7b872a6 "%ldc") at snprintf_chk.c:29 #8 0x000055b8c7aea59f in snprintf (__fmt=0x55b8c7b872a6 "%ldc", __n=1025, __s=0x55b8c7c096a5 "t' item") at /usr/include/bits/stdio2.h:54 #9 uc_list (name=name@entry=0x55b8c8351788 "Explore", name_len=name_len@entry=7) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/usercmd.c:534 #10 0x000055b8c7aeb8a0 in ex_command (eap=0x7fffdc350e60) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/usercmd.c:1009 #11 0x000055b8c7972537 in execute_cmd0 (retv=retv@entry=0x7fffdc350e54, eap=eap@entry=0x7fffdc350e60, errormsg=errormsg@entry=0x7fffdc350e58, preview=preview@entry=false) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/ex_docmd.c:1620 #12 0x000055b8c7975c55 in do_one_cmd (cmdlinep=cmdlinep@entry=0x7fffdc3510b8, flags=flags@entry=0, cstack=cstack@entry=0x7fffdc351140, fgetline=fgetline@entry=0x55b8c79882b8 , cookie=cookie@entry=0x0) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/ex_docmd.c:2279 #13 0x000055b8c79767fe in do_cmdline (cmdline=, fgetline=0x55b8c79882b8 , cookie=0x0, flags=0) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/ex_docmd.c:578 #14 0x000055b8c7a17463 in nv_colon (cap=0x7fffdc351780) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/normal.c:3228 #15 0x000055b8c7a11b35 in normal_execute (state=0x7fffdc351700, key=) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/normal.c:1196 #16 0x000055b8c7ab0994 in state_enter (s=0x7fffdc351700) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/state.c:99 #17 0x000055b8c7a0ef68 in normal_enter (cmdwin=false, noexmode=false) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/normal.c:497 #18 0x000055b8c78a0640 in main (argc=, argv=) at /usr/src/debug/neovim-0.9.0-1.fc38.x86_64/src/nvim/main.c:641 --- test/functional/ex_cmds/excmd_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index b313d6428c..14cc2b8387 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -28,6 +28,11 @@ describe('Ex cmds', function() assert_alive() end) + it('listing long user command does not crash', function() + command('execute "command" repeat("T", 255) ":"') + command('command') + end) + it(':def is an unknown command #23149', function() eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) eq(1, funcs.exists(':d')) -- cgit From d9f78b63361e00a7f623ebb5b869606ac653b180 Mon Sep 17 00:00:00 2001 From: T727 <74924917+T-727@users.noreply.github.com> Date: Sat, 22 Apr 2023 13:04:05 +0300 Subject: docs(powershell): use tee.exe instead of Tee-Object Problem: Tee-Object does not create a file if it does not receive input for example when :grep does not find matches. and so nvim tries to open a nonexistent errorfile causing an error. Solution: use tee.exe instead of Tee-Object --- test/functional/ex_cmds/make_spec.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index f42e21e4cb..8d903330b1 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -24,10 +24,8 @@ describe(':make', function() it('captures stderr & non zero exit code #14349', function () nvim('set_option', 'makeprg', testprg('shell-test')..' foo') local out = eval('execute("make")') - -- Make program exit code correctly captured - matches('\nshell returned 3', out) -- Error message is captured in the file and printed in the footer - matches('\n.*%: Unknown first argument%: foo', out) + matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out) end) it('captures stderr & zero exit code #14349', function () -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- test/functional/ex_cmds/highlight_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 45764e6719..958dd99226 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -24,7 +24,7 @@ describe(':highlight', function() end) it('invalid group name', function() - eq('Vim(highlight):E411: highlight group not found: foo', + eq('Vim(highlight):E411: Highlight group not found: foo', exc_exec("highlight foo")) end) -- cgit From 4a098b97e53551a3383e669f4730be542c61e012 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 06:32:17 +0800 Subject: fix(excmd): append original command to error message Revert the change to do_cmdline_cmd() from #5226. This function is used in many places, so making it different from Vim leads to small differences from Vim in the behavior of some functions like execute() and assert_fails(). If DOCMD_VERBOSE really needs to be removed somewhere, a do_cmdline() call without DOCMD_VERBOSE is also shorter than a do_cmdline() call with DOCMD_VERBOSE. --- test/functional/ex_cmds/excmd_spec.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index 14cc2b8387..a92329ede5 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -11,20 +11,24 @@ describe('Ex cmds', function() clear() end) + local function check_excmd_err(cmd, err) + eq(err .. ': ' .. cmd, pcall_err(command, cmd)) + end + it('handle integer overflow from user-input #5555', function() command(':9999999999999999999999999999999999999999') command(':later 9999999999999999999999999999999999999999') command(':echo expand("#<9999999999999999999999999999999999999999")') command(':lockvar 9999999999999999999999999999999999999999') command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999') - eq('Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999', - pcall_err(command, ':tabnext 9999999999999999999999999999999999999999')) - eq('Vim(Next):E939: Positive count required', - pcall_err(command, ':N 9999999999999999999999999999999999999999')) + check_excmd_err(':tabnext 9999999999999999999999999999999999999999', + 'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999') + check_excmd_err(':N 9999999999999999999999999999999999999999', + 'Vim(Next):E939: Positive count required') + check_excmd_err(':bdelete 9999999999999999999999999999999999999999', + 'Vim(bdelete):E939: Positive count required') eq('Vim(menu):E329: No menu "9999999999999999999999999999999999999999"', pcall_err(command, ':menu 9999999999999999999999999999999999999999')) - eq('Vim(bdelete):E939: Positive count required', - pcall_err(command, ':bdelete 9999999999999999999999999999999999999999')) assert_alive() end) -- cgit From a2b9117ca8f8abe8d4c9e2d1bacb73b1902a4e1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:12:42 +0800 Subject: vim-patch:8.2.1978: making a mapping work in all modes is complicated Problem: Making a mapping work in all modes is complicated. Solution: Add the special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) https://github.com/vim/vim/commit/957cf67d50516ba98716f59c9e1cb6412ec1535d Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar --- test/functional/ex_cmds/cmd_map_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index 919d167712..a0aec7fdd0 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -90,7 +90,7 @@ describe('mappings with ', function() {1:~ }| {1:~ }| {1:~ }| - {2:E5521: mapping must end with before second } | + {2:E1136: mapping must end with before second } | ]]) command('noremap let x = 3') @@ -103,7 +103,7 @@ describe('mappings with ', function() {1:~ }| {1:~ }| {1:~ }| - {2:E5520: mapping must end with } | + {2:E1135: mapping must end with } | ]]) eq(0, eval('x')) end) -- cgit From 29c228dc1087676af5b72f4145ab146cff75156e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:33:06 +0800 Subject: vim-patch:8.2.3887: E1135 is used for two different errors Problem: E1135 is used for two different errors. Solution: Renumber one error. https://github.com/vim/vim/commit/806da5176e9e9ab011d927c4ca33a8dde1769539 Co-authored-by: Bram Moolenaar --- test/functional/ex_cmds/cmd_map_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index a0aec7fdd0..12867179bd 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -103,7 +103,7 @@ describe('mappings with ', function() {1:~ }| {1:~ }| {1:~ }| - {2:E1135: mapping must end with } | + {2:E1255: mapping must end with } | ]]) eq(0, eval('x')) end) -- cgit From 1fe1bb084d0099fc4f9bfdc11189485d0f74b75a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 19 Dec 2022 16:37:45 +0000 Subject: refactor(options): deprecate nvim[_buf|_win]_[gs]et_option Co-authored-by: zeertzjq Co-authored-by: famiu --- test/functional/ex_cmds/append_spec.lua | 3 ++- test/functional/ex_cmds/ls_spec.lua | 2 +- test/functional/ex_cmds/make_spec.lua | 4 ++-- test/functional/ex_cmds/map_spec.lua | 2 +- test/functional/ex_cmds/mksession_spec.lua | 14 +++++++------- test/functional/ex_cmds/source_spec.lua | 2 +- test/functional/ex_cmds/verbose_spec.lua | 4 ++-- test/functional/ex_cmds/write_spec.lua | 8 ++++---- 8 files changed, 20 insertions(+), 19 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index fadb5c9b42..e3a39384a6 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -8,6 +8,7 @@ local clear = helpers.clear local funcs = helpers.funcs local command = helpers.command local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local Screen = require('test.functional.ui.screen') local cmdtest = function(cmd, prep, ret1) @@ -42,7 +43,7 @@ local cmdtest = function(cmd, prep, ret1) eq(hisline, funcs.histget(':', -2)) eq(cmd, funcs.histget(':')) -- Test that command-line window was launched - eq('nofile', curbufmeths.get_option('buftype')) + eq('nofile', meths.get_option_value('buftype', {buf=0})) eq('n', funcs.mode(1)) feed('') eq('c', funcs.mode(1)) diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua index 2583d80269..d02af21731 100644 --- a/test/functional/ex_cmds/ls_spec.lua +++ b/test/functional/ex_cmds/ls_spec.lua @@ -14,7 +14,7 @@ describe(':ls', function() end) it('R, F for :terminal buffers', function() - nvim('set_option', 'shell', string.format('"%s" INTERACT', testprg('shell-test'))) + nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('edit foo') command('set hidden') diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index 8d903330b1..d82f59ddf9 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -22,14 +22,14 @@ describe(':make', function() end) it('captures stderr & non zero exit code #14349', function () - nvim('set_option', 'makeprg', testprg('shell-test')..' foo') + nvim('set_option_value', 'makeprg', testprg('shell-test')..' foo', {}) local out = eval('execute("make")') -- Error message is captured in the file and printed in the footer matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out) end) it('captures stderr & zero exit code #14349', function () - nvim('set_option', 'makeprg', testprg('shell-test')) + nvim('set_option_value', 'makeprg', testprg('shell-test'), {}) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between -- command and last line (indicating zero exit) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index a197b81cc5..a580e88b93 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -18,7 +18,7 @@ describe(':*map', function() it('are not affected by &isident', function() meths.set_var('counter', 0) command('nnoremap :let counter+=1') - meths.set_option('isident', ('%u'):format(('>'):byte())) + meths.set_option_value('isident', ('%u'):format(('>'):byte()), {}) command('nnoremap :let counter+=1') -- &isident used to disable keycode parsing here as well feed('\24\25') diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index d70ccb5b39..f51e7c62cb 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -81,13 +81,13 @@ describe(':mksession', function() local buf_count = #meths.list_bufs() eq(2, buf_count) - eq('terminal', meths.buf_get_option(0, 'buftype')) + eq('terminal', meths.get_option_value('buftype', { buf = 0 })) test_terminal_session_disabled(2) -- no terminal should be set. As a side effect we end up with a blank buffer - eq('', meths.buf_get_option(meths.list_bufs()[1], 'buftype')) - eq('', meths.buf_get_option(meths.list_bufs()[2], 'buftype')) + eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[1] })) + eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[2] })) end ) @@ -112,7 +112,7 @@ describe(':mksession', function() it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() command('terminal') - eq('terminal', meths.buf_get_option(0, 'buftype')) + eq('terminal', meths.get_option_value('buftype', { buf = 0 })) local buf_count = #meths.list_bufs() eq(1, buf_count) @@ -120,7 +120,7 @@ describe(':mksession', function() test_terminal_session_disabled(1) -- no terminal should be set - eq('', meths.buf_get_option(0, 'buftype')) + eq('', meths.get_option_value('buftype', { buf = 0 })) end) it('restores tab-local working directories', function() @@ -249,7 +249,7 @@ describe(':mksession', function() style = 'minimal', } meths.open_win(buf, false, config) - local cmdheight = meths.get_option('cmdheight') + local cmdheight = meths.get_option_value('cmdheight', {}) command('mksession ' .. session_file) -- Create a new test instance of Nvim. @@ -262,7 +262,7 @@ describe(':mksession', function() -- window was not restored. eq(1, funcs.winnr('$')) -- The command-line height should remain the same as it was. - eq(cmdheight, meths.get_option('cmdheight')) + eq(cmdheight, meths.get_option_value('cmdheight', {})) os.remove(tmpfile) end) diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 41045f5cb4..02f5bff021 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -48,7 +48,7 @@ describe(':source', function() pending("'shellslash' only works on Windows") return end - meths.set_option('shellslash', false) + meths.set_option_value('shellslash', false, {}) mkdir('Xshellslash') write_file([[Xshellslash/Xstack.vim]], [[ diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index def09e2f9e..50077e9e0c 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -18,7 +18,7 @@ local function last_set_tests(cmd) script_location = table.concat{current_dir, helpers.get_pathsep(), script_file} write_file(script_file, [[ -vim.api.nvim_set_option('hlsearch', false) +vim.api.nvim_set_option_value('hlsearch', false, {}) vim.bo.expandtab = true vim.opt.number = true vim.api.nvim_set_keymap('n', 'key1', ':echo "test"', {noremap = true}) @@ -160,7 +160,7 @@ describe('lua verbose:', function() clear() script_file = 'test_luafile.lua' write_file(script_file, [[ - vim.api.nvim_set_option('hlsearch', false) + vim.api.nvim_set_option_value('hlsearch', false, {}) ]]) exec(':source '..script_file) end) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 126646f21a..0b8ce93b09 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -129,18 +129,18 @@ describe(':write', function() eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), pcall_err(command, 'write .')) end - meths.set_option('writeany', true) + meths.set_option_value('writeany', true, {}) -- Message from buf_write eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .')) funcs.mkdir(fname_bak) - meths.set_option('backupdir', '.') - meths.set_option('backup', true) + meths.set_option_value('backupdir', '.', {}) + meths.set_option_value('backup', true, {}) write_file(fname, 'content0') command('edit ' .. fname) funcs.setline(1, 'TTY') eq('Vim(write):E510: Can\'t make backup file (add ! to override)', pcall_err(command, 'write')) - meths.set_option('backup', false) + meths.set_option_value('backup', false, {}) funcs.setfperm(fname, 'r--------') eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', pcall_err(command, 'write')) -- cgit From 576dddb46168e81aa0f78c28816082c662dedea1 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 22 May 2023 12:47:10 +0600 Subject: test: don't unnecessarily specify win/buf for `nvim_(get|set)_option_value` `nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter. --- test/functional/ex_cmds/append_spec.lua | 2 +- test/functional/ex_cmds/mksession_spec.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index e3a39384a6..4134eed87e 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -43,7 +43,7 @@ local cmdtest = function(cmd, prep, ret1) eq(hisline, funcs.histget(':', -2)) eq(cmd, funcs.histget(':')) -- Test that command-line window was launched - eq('nofile', meths.get_option_value('buftype', {buf=0})) + eq('nofile', meths.get_option_value('buftype', {})) eq('n', funcs.mode(1)) feed('') eq('c', funcs.mode(1)) diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index f51e7c62cb..7522d4a99c 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -81,7 +81,7 @@ describe(':mksession', function() local buf_count = #meths.list_bufs() eq(2, buf_count) - eq('terminal', meths.get_option_value('buftype', { buf = 0 })) + eq('terminal', meths.get_option_value('buftype', {})) test_terminal_session_disabled(2) @@ -112,7 +112,7 @@ describe(':mksession', function() it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() command('terminal') - eq('terminal', meths.get_option_value('buftype', { buf = 0 })) + eq('terminal', meths.get_option_value('buftype', {})) local buf_count = #meths.list_bufs() eq(1, buf_count) @@ -120,7 +120,7 @@ describe(':mksession', function() test_terminal_session_disabled(1) -- no terminal should be set - eq('', meths.get_option_value('buftype', { buf = 0 })) + eq('', meths.get_option_value('buftype', {})) end) it('restores tab-local working directories', function() -- cgit From 4b60267f82ef1947f8a583c02eaf502cf1db69ca Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Jun 2023 21:00:55 +0800 Subject: feat(:source): source current ft=lua buffer as Lua code (#23802) --- test/functional/ex_cmds/source_spec.lua | 108 +++++++++++++++++--------------- 1 file changed, 59 insertions(+), 49 deletions(-) (limited to 'test/functional/ex_cmds') diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 02f5bff021..24987354a4 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -7,6 +7,7 @@ local meths = helpers.meths local feed = helpers.feed local feed_command = helpers.feed_command local write_file = helpers.write_file +local tmpname = helpers.tmpname local exec = helpers.exec local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua @@ -179,56 +180,65 @@ describe(':source', function() os.remove(test_file) end) - it('can source selected region in lua file', function() - local test_file = 'test.lua' - - write_file (test_file, [[ - vim.g.b = 5 - vim.g.b = 6 - vim.g.b = 7 - a = [=[ - "\ a - \ b]=] - ]]) - - command('edit '..test_file) - - feed('ggjV') - feed_command(':source') - eq(6, eval('g:b')) - - feed('GVkk') - feed_command(':source') - eq(' "\\ a\n \\ b', exec_lua('return _G.a')) - - os.remove(test_file) - end) - - it('can source current lua buffer without argument', function() - local test_file = 'test.lua' - - write_file(test_file, [[ - vim.g.c = 10 - vim.g.c = 11 - vim.g.c = 12 - a = [=[ - \ 1 - "\ 2]=] - vim.g.sfile_value = vim.fn.expand('') - vim.g.stack_value = vim.fn.expand('') - vim.g.script_value = vim.fn.expand('