From 2fd25fb909fd4472c46c8c3c652b21d70bac9e77 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 Aug 2022 07:20:23 +0800 Subject: vim-patch:8.1.0832: confirm() is not tested (#19896) Problem: confirm() is not tested. Solution: Add a test. (Dominique Pelle, closes vim/vim#3868) https://github.com/vim/vim/commit/2e0500921891e4fec57e97d3c0021aa2d2b4d7ae --- test/functional/vimscript/input_spec.lua | 77 +++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 554d15e550..d6ab71b7d5 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -8,7 +8,8 @@ local clear = helpers.clear local source = helpers.source local command = helpers.command local exc_exec = helpers.exc_exec -local nvim_async = helpers.nvim_async +local pcall_err = helpers.pcall_err +local async_meths = helpers.async_meths local NIL = helpers.NIL local screen @@ -449,6 +450,78 @@ describe('inputdialog()', function() end) describe('confirm()', function() + -- oldtest: Test_confirm() + it('works', function() + meths.set_option('more', false) -- Avoid hit-enter prompt + meths.set_option('laststatus', 2) + -- screen:expect() calls are needed to avoid feeding input too early + screen:expect({any = 'No Name'}) + + async_meths.command([[let a = confirm('Press O to proceed')]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('o') + screen:expect({any = 'No Name'}) + eq(1, meths.get_var('a')) + + async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('y') + screen:expect({any = 'No Name'}) + eq(1, meths.get_var('a')) + + async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('n') + screen:expect({any = 'No Name'}) + eq(2, meths.get_var('a')) + + -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. + + -- confirm() should return 0 when pressing ESC. + async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('') + screen:expect({any = 'No Name'}) + eq(0, meths.get_var('a')) + + -- Default choice is returned when pressing . + async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('') + screen:expect({any = 'No Name'}) + eq(1, meths.get_var('a')) + + async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('') + screen:expect({any = 'No Name'}) + eq(2, meths.get_var('a')) + + async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('') + screen:expect({any = 'No Name'}) + eq(0, meths.get_var('a')) + + -- Test with the {type} 4th argument + for _, type in ipairs({'Error', 'Question', 'Info', 'Warning', 'Generic'}) do + async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type)) + screen:expect({any = '{CONFIRM:.+: }'}) + feed('y') + screen:expect({any = 'No Name'}) + eq(1, meths.get_var('a')) + end + + eq('Vim(call):E730: using List as a String', + pcall_err(command, 'call confirm([])')) + eq('Vim(call):E730: using List as a String', + pcall_err(command, 'call confirm("Are you sure?", [])')) + eq('Vim(call):E745: Using a List as a Number', + pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", [])')) + eq('Vim(call):E730: using List as a String', + pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", 0, [])')) + end) + it("shows dialog even if :silent #8788", function() command("autocmd BufNewFile * call confirm('test')") @@ -483,7 +556,7 @@ describe('confirm()', function() feed(':call nvim_command("edit x")') check_and_clear(':call nvim_command("edit |\n') - nvim_async('command', 'edit x') + async_meths.command('edit x') check_and_clear(' |\n') end) end) -- cgit From d5328ea408d93d53b46417a65ca3b2fc99ab64b6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 Aug 2022 10:38:53 +0800 Subject: vim-patch:8.2.0522: several errors are not tested for (#19901) Problem: Several errors are not tested for. Solution: Add tests. (Yegappan Lakshmanan, closes vim/vim#5892) https://github.com/vim/vim/commit/ee4e0c1e9a81cb5d96e0060203a9033c2f28588e Omit Test_range() change: reverted in patch 8.2.0615. Cherry-pick Test_z_no_space_before_xxx() from patch 8.2.0195. Cherry-pick Test_reverse_sort_uniq() change from patch 8.2.0183. Make uniq() error behavior consistent with sort(). Cherry-pick Test_set_ttytype() change from patch 8.1.1826. Cherry-pick quickfix checks from patch 8.1.2373 to test_preview.vim. Test_viminfo_error() is applicable. Cherry-pick E1058 from patch 8.2.0149 and port Test_deep_nest() to Lua. --- test/functional/vimscript/eval_spec.lua | 75 ++++++++++++++++++++++++++++++++ test/functional/vimscript/input_spec.lua | 20 ++++----- 2 files changed, 85 insertions(+), 10 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 0c2ca8de78..65ac5b8c80 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -10,11 +10,13 @@ -- test/functional/vimscript/functions_spec.lua local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local lfs = require('lfs') local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec +local exec = helpers.exec local eval = helpers.eval local command = helpers.command local write_file = helpers.write_file @@ -144,3 +146,76 @@ describe('List support code', function() end end) end) + +-- oldtest: Test_deep_nest() +it('Error when if/for/while/try/function is nested too deep',function() + clear() + local screen = Screen.new(80, 24) + screen:attach() + meths.set_option('laststatus', 2) + exec([[ + " Deep nesting of if ... endif + func Test1() + let @a = join(repeat(['if v:true'], 51), "\n") + let @a ..= "\n" + let @a ..= join(repeat(['endif'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of for ... endfor + func Test2() + let @a = join(repeat(['for i in [1]'], 51), "\n") + let @a ..= "\n" + let @a ..= join(repeat(['endfor'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of while ... endwhile + func Test3() + let @a = join(repeat(['while v:true'], 51), "\n") + let @a ..= "\n" + let @a ..= join(repeat(['endwhile'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of try ... endtry + func Test4() + let @a = join(repeat(['try'], 51), "\n") + let @a ..= "\necho v:true\n" + let @a ..= join(repeat(['endtry'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of function ... endfunction + func Test5() + let @a = join(repeat(['function X()'], 51), "\n") + let @a ..= "\necho v:true\n" + let @a ..= join(repeat(['endfunction'], 51), "\n") + @a + let @a = '' + endfunc + ]]) + screen:expect({any = '%[No Name%]'}) + feed(':call Test1()') + screen:expect({any = 'E579: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test2()') + screen:expect({any = 'E585: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test3()') + screen:expect({any = 'E585: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test4()') + screen:expect({any = 'E601: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test5()') + screen:expect({any = 'E1058: '}) +end) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index d6ab71b7d5..f50b39c2c5 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -455,24 +455,24 @@ describe('confirm()', function() meths.set_option('more', false) -- Avoid hit-enter prompt meths.set_option('laststatus', 2) -- screen:expect() calls are needed to avoid feeding input too early - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) async_meths.command([[let a = confirm('Press O to proceed')]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('o') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(1, meths.get_var('a')) - async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('y') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(1, meths.get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('n') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(2, meths.get_var('a')) -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. @@ -481,26 +481,26 @@ describe('confirm()', function() async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(0, meths.get_var('a')) -- Default choice is returned when pressing . async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(1, meths.get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(2, meths.get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) screen:expect({any = '{CONFIRM:.+: }'}) feed('') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(0, meths.get_var('a')) -- Test with the {type} 4th argument @@ -508,7 +508,7 @@ describe('confirm()', function() async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type)) screen:expect({any = '{CONFIRM:.+: }'}) feed('y') - screen:expect({any = 'No Name'}) + screen:expect({any = '%[No Name%]'}) eq(1, meths.get_var('a')) end -- cgit From 813476bf7291dfaf9fc0ef77c9f53a07258a3801 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 30 Aug 2022 23:13:52 +0100 Subject: fix(exceptions): restore `did_throw` (#20000) `!did_throw` doesn't exactly imply `!current_exception`, as `did_throw = false` is sometimes used to defer exception handling for later (without forgetting the exception). E.g: uncaught exception handling in `do_cmdline()` may be deferred to a different call (e.g: when `try_level > 0`). In #7881, `current_exception = NULL` in `do_cmdline()` is used as an analogue of `did_throw = false`, but also causes the pending exception to be lost, which also leaks as `discard_exception()` wasn't used. It may be possible to fix this by saving/restoring `current_exception`, but handling all of `did_throw`'s edge cases seems messier. Maybe not worth diverging over. This fix also uncovers a `man_spec.lua` bug on Windows: exceptions are thrown due to Windows missing `man`, but they're lost; skip these tests if `man` isn't executable. --- test/functional/vimscript/eval_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 65ac5b8c80..d4fa7afe89 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -219,3 +219,31 @@ it('Error when if/for/while/try/function is nested too deep',function() feed(':call Test5()') screen:expect({any = 'E1058: '}) end) + +describe("uncaught exception", function() + before_each(clear) + after_each(function() + os.remove('throw1.vim') + os.remove('throw2.vim') + os.remove('throw3.vim') + end) + + it('is not forgotten #13490', function() + command('autocmd BufWinEnter * throw "i am error"') + eq('i am error', exc_exec('try | new | endtry')) + + -- Like Vim, throwing here aborts the processing of the script, but does not stop :runtime! + -- from processing the others. + -- Only the first thrown exception should be rethrown from the :try below, though. + for i = 1, 3 do + write_file('throw' .. i .. '.vim', ([[ + let result ..= '%d' + throw 'throw%d' + let result ..= 'X' + ]]):format(i, i)) + end + command('set runtimepath+=. | let result = ""') + eq('throw1', exc_exec('try | runtime! throw*.vim | endtry')) + eq('123', eval('result')) + end) +end) -- cgit From 0c6b39894f4cac99c3d81857986e4eae533fb59a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 06:19:49 +0800 Subject: feat(mapset): support restoring Lua callback (#20024) vim-patch:9.0.0341: mapset() does not restore mapping properly Problem: mapset() does not restore mapping properly. Solution: Use an empty string for . (closes vim/vim#11022) https://github.com/vim/vim/commit/92a3d20682d46359bb50a452b4f831659e799155 --- test/functional/vimscript/map_functions_spec.lua | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index aa64006de0..96b86d053e 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -3,6 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval +local exec = helpers.exec +local exec_lua = helpers.exec_lua local expect = helpers.expect local feed = helpers.feed local funcs = helpers.funcs @@ -10,6 +12,7 @@ local meths = helpers.meths local nvim = helpers.nvim local source = helpers.source local command = helpers.command +local pcall_err = helpers.pcall_err describe('maparg()', function() before_each(clear) @@ -194,4 +197,43 @@ describe('mapset()', function() feed('foo') expect('<<') end) + + it('can restore Lua callback from the dict returned by maparg()', function() + eq(0, exec_lua([[ + GlobalCount = 0 + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + return GlobalCount + ]])) + feed('asdf') + eq(1, exec_lua([[return GlobalCount]])) + + exec_lua([[ + _G.saved_asdf_map = vim.fn.maparg('asdf', 'n', false, true) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 10 end }) + ]]) + feed('asdf') + eq(11, exec_lua([[return GlobalCount]])) + + exec_lua([[vim.fn.mapset('n', false, _G.saved_asdf_map)]]) + feed('asdf') + eq(12, exec_lua([[return GlobalCount]])) + + exec([[ + let g:saved_asdf_map = maparg('asdf', 'n', v:false, v:true) + lua vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 10 end }) + ]]) + feed('asdf') + eq(22, exec_lua([[return GlobalCount]])) + + command([[call mapset('n', v:false, g:saved_asdf_map)]]) + feed('asdf') + eq(23, exec_lua([[return GlobalCount]])) + end) + + it('does not leak memory if lhs is missing', function() + eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]])) + eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]])) + end) end) -- cgit From 38059b4f31d8c9374002e209bc9ee2df28ac17fa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 14:03:32 +0800 Subject: vim-patch:8.2.2646: Vim9: error for not using string doesn't mention argument Problem: Vim9: error for not using string doesn't mention argument. Solution: Add argument number. https://github.com/vim/vim/commit/f28f2ac425600b88da0bdcc12a82cd620f575681 --- test/functional/vimscript/executable_spec.lua | 6 ++++-- test/functional/vimscript/exepath_spec.lua | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index b4162b2336..b49eb09512 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -34,11 +34,13 @@ describe('executable()', function() it('fails for invalid values', function() for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do - eq('Vim(call):E928: String required', exc_exec('call executable('..input..')')) + eq('Vim(call):E1174: String required for argument 1', + exc_exec('call executable('..input..')')) end command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do - eq('Vim(call):E928: String required', exc_exec('call executable('..input..')')) + eq('Vim(call):E1174: String required for argument 1', + exc_exec('call executable('..input..')')) end end) diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua index bbca954511..439dd96fcd 100644 --- a/test/functional/vimscript/exepath_spec.lua +++ b/test/functional/vimscript/exepath_spec.lua @@ -21,12 +21,12 @@ describe('exepath()', function() it('fails for invalid values', function() for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do - eq('Vim(call):E928: String required', exc_exec('call exepath('..input..')')) + eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) end - eq('Vim(call):E1142: Non-empty string required', exc_exec('call exepath("")')) + eq('Vim(call):E1142: Non-empty string required for argument 1', exc_exec('call exepath("")')) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do - eq('Vim(call):E928: String required', exc_exec('call exepath('..input..')')) + eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) end end) -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- test/functional/vimscript/timer_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 5463cfb234..1818a71ea2 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -131,34 +131,34 @@ describe('timers', function() nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})") screen:expect([[ - ITEM 1 | + ^ITEM 1 | ITEM 2 | {1:~ }| {1:~ }| {1:~ }| - ^ | + | ]]) nvim_async("command", "let g:cont = 1") screen:expect([[ - ITEM 1 | + ^ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }| {1:~ }| - ^ | + | ]]) feed("3") eq(51, eval("g:c2")) - screen:expect([[ + screen:expect{grid=[[ ^ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }| {1:~ }| | - ]]) + ]], unchanged=true} end) it('can be stopped', function() -- cgit From 291a6496327e90056ea68085ad52ab74ca1df752 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 21:07:18 +0800 Subject: fix(mapset): remove existing abbreviation of same lhs (#20320) --- test/functional/vimscript/map_functions_spec.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index 96b86d053e..ed1863754a 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -12,6 +12,7 @@ local meths = helpers.meths local nvim = helpers.nvim local source = helpers.source local command = helpers.command +local exec_capture = helpers.exec_capture local pcall_err = helpers.pcall_err describe('maparg()', function() @@ -178,8 +179,9 @@ describe('mapset()', function() eq('\nn lhs rhs\n map description', helpers.exec_capture("nmap lhs")) local mapargs = funcs.maparg('lhs', 'n', false, true) - meths.del_keymap('n', 'lhs') - eq('\nNo mapping found', helpers.exec_capture("nmap lhs")) + meths.set_keymap('n', 'lhs', 'rhs', {desc = 'MAP DESCRIPTION'}) + eq('\nn lhs rhs\n MAP DESCRIPTION', + helpers.exec_capture("nmap lhs")) funcs.mapset('n', false, mapargs) eq('\nn lhs rhs\n map description', helpers.exec_capture("nmap lhs")) @@ -198,6 +200,22 @@ describe('mapset()', function() expect('<<') end) + it('replaces an abbreviation of the same lhs #20320', function() + command('inoreabbr foo bar') + eq('\ni foo * bar', exec_capture('iabbr foo')) + feed('ifoo ') + expect('bar ') + local mapargs = funcs.maparg('foo', 'i', true, true) + command('inoreabbr foo BAR') + eq('\ni foo * BAR', exec_capture('iabbr foo')) + feed('foo ') + expect('bar BAR ') + funcs.mapset('i', true, mapargs) + eq('\ni foo * bar', exec_capture('iabbr foo')) + feed('foo') + expect('bar BAR bar') + end) + it('can restore Lua callback from the dict returned by maparg()', function() eq(0, exec_lua([[ GlobalCount = 0 -- cgit From c815aadfccd6bada47ecfb09fe188ee7f7c5caf3 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:43:23 +0200 Subject: docs: fix typos (#20150) Co-authored-by: Miguel Carneiro Co-authored-by: Gregory Anders Co-authored-by: Raphael Co-authored-by: C.D. MacEachern Co-authored-by: zeertzjq --- test/functional/vimscript/map_functions_spec.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index ed1863754a..8645b1e506 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -176,15 +176,12 @@ describe('mapset()', function() it('can restore mapping description from the dict returned by maparg()', function() meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'}) - eq('\nn lhs rhs\n map description', - helpers.exec_capture("nmap lhs")) + eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) local mapargs = funcs.maparg('lhs', 'n', false, true) meths.set_keymap('n', 'lhs', 'rhs', {desc = 'MAP DESCRIPTION'}) - eq('\nn lhs rhs\n MAP DESCRIPTION', - helpers.exec_capture("nmap lhs")) + eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture("nmap lhs")) funcs.mapset('n', false, mapargs) - eq('\nn lhs rhs\n map description', - helpers.exec_capture("nmap lhs")) + eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) end) it('can restore "replace_keycodes" from the dict returned by maparg()', function() -- cgit From df646572c53f55268a5dbb61628d7c3b302d5663 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:53:52 +0200 Subject: docs: fix typos (#20394) Co-authored-by: Raphael Co-authored-by: smjonas Co-authored-by: zeertzjq --- test/functional/vimscript/container_functions_spec.lua | 2 +- test/functional/vimscript/json_functions_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/container_functions_spec.lua b/test/functional/vimscript/container_functions_spec.lua index 04a3248c49..5bef3fce05 100644 --- a/test/functional/vimscript/container_functions_spec.lua +++ b/test/functional/vimscript/container_functions_spec.lua @@ -8,7 +8,7 @@ local clear = helpers.clear before_each(clear) describe('extend()', function() - it('suceeds to extend list with itself', function() + it('succeeds to extend list with itself', function() meths.set_var('l', {1, {}}) eq({1, {}, 1, {}}, eval('extend(l, l)')) eq({1, {}, 1, {}}, meths.get_var('l')) diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua index 5d1597f53d..70d0934756 100644 --- a/test/functional/vimscript/json_functions_spec.lua +++ b/test/functional/vimscript/json_functions_spec.lua @@ -343,7 +343,7 @@ describe('json_decode() function', function() exc_exec('call json_decode("\\t\\"abc\\\\u0000")')) end) - it('fails to parse unknown escape sequnces', function() + it('fails to parse unknown escape sequences', function() eq('Vim(call):E474: Unknown escape sequence: \\a"', exc_exec('call json_decode("\\t\\"\\\\a\\"")')) end) -- cgit From b4d42bb9058308c38e3fe9d59458ce65b3f65eb0 Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Wed, 20 Jul 2022 01:43:26 +0600 Subject: fix: make_filter_cmd for :! powershell Problem: `Start-Process` requires the command to be split into the shell command and its arguments. Previously it was done by parsing, which didn't handle cases such as - commands with escaped space in their filepath - quoted commands with space in their filepath Solution: Use - `pwsh -Command` instead of `Start-Process` - `Get-Content` instead of `-RedirectStandardInput` - `Out-File` instead of `-RedirectStandardOutput` --- test/functional/vimscript/system_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index a778e2f435..d0061d051e 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -642,12 +642,12 @@ describe('shell :!', function() if iswin() then feed(':4verbose %!sort /R') screen:expect{ - any=[[Executing command: .?Start%-Process sort %-ArgumentList "/R" %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]] + any=[[Executing command: .?Get%-Content .* | & sort /R 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] } else feed(':4verbose %!sort -r') screen:expect{ - any=[[Executing command: .?Start%-Process sort %-ArgumentList "%-r" %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]] + any=[[Executing command: .?Get%-Content .* | & sort %-r 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] } end feed('') -- cgit From f2482b3b533c8ed131a33aaead332c226a9e6aca Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Wed, 20 Jul 2022 20:55:28 +0600 Subject: fix: :! pwsh redirection for `command not found` Problem: If the shell command passed to the filtered bang command isn't found, the error isn't redirected to the temp.out file when shell is set to powershell. Solution: Use anonymous function with Invoke-Command operator (&). --- test/functional/vimscript/system_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index d0061d051e..ed822add72 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -642,12 +642,12 @@ describe('shell :!', function() if iswin() then feed(':4verbose %!sort /R') screen:expect{ - any=[[Executing command: .?Get%-Content .* | & sort /R 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] + any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]] } else feed(':4verbose %!sort -r') screen:expect{ - any=[[Executing command: .?Get%-Content .* | & sort %-r 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] + any=[[Executing command: .?& { Get%-Content .* | & sort %-r } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]] } end feed('') -- cgit From 71497c164db3180bbec539765f987b483662f73f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Oct 2022 07:31:06 +0800 Subject: test: add test for :function followed by --- test/functional/vimscript/eval_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index d4fa7afe89..1fbdedb815 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -17,6 +17,7 @@ local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec local exec = helpers.exec +local exec_capture = helpers.exec_capture local eval = helpers.eval local command = helpers.command local write_file = helpers.write_file @@ -247,3 +248,16 @@ describe("uncaught exception", function() eq('123', eval('result')) end) end) + +describe('lambda function', function() + before_each(clear) + + it('can be shown using :function followed by #20466', function() + command('let A = {-> 1}') + local num = exec_capture('echo A'):match("function%('(%d+)'%)") + eq(([[ + function %s(...) +1 return 1 + endfunction]]):format(num), exec_capture(('function %s'):format(num))) + end) +end) -- cgit From 0ed1429fcb826c0022744fa17edfbe36a750d5f6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 24 Oct 2022 15:49:16 +0800 Subject: test: add a test for a crash fixed by patch 8.2.0908 --- test/functional/vimscript/eval_spec.lua | 37 +++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 1fbdedb815..64a3cf5471 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -17,12 +17,16 @@ local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec local exec = helpers.exec +local exec_lua = helpers.exec_lua local exec_capture = helpers.exec_capture local eval = helpers.eval local command = helpers.command local write_file = helpers.write_file local meths = helpers.meths local sleep = helpers.sleep +local matches = helpers.matches +local pcall_err = helpers.pcall_err +local assert_alive = helpers.assert_alive local poke_eventloop = helpers.poke_eventloop local feed = helpers.feed @@ -249,10 +253,10 @@ describe("uncaught exception", function() end) end) -describe('lambda function', function() +describe('listing functions using :function', function() before_each(clear) - it('can be shown using :function followed by #20466', function() + it('works for lambda functions with #20466', function() command('let A = {-> 1}') local num = exec_capture('echo A'):match("function%('(%d+)'%)") eq(([[ @@ -260,4 +264,33 @@ describe('lambda function', function() 1 return 1 endfunction]]):format(num), exec_capture(('function %s'):format(num))) end) + + -- FIXME: If the same function is deleted, the crash still happens. #20790 + it('does not crash if another function is deleted while listing', function() + local screen = Screen.new(80, 24) + screen:attach() + matches('.*: Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[ + vim.cmd([[ + func Func1() + endfunc + func Func2() + endfunc + func Func3() + endfunc + ]]) + + local ns = vim.api.nvim_create_namespace('test') + + vim.ui_attach(ns, { ext_messages = true }, function(event, _, content) + if event == 'msg_show' and content[1][2] == 'function Func1()' then + vim.cmd('delfunc Func3') + end + end) + + vim.cmd('function') + + vim.ui_detach(ns) + ]=])) + assert_alive() + end) end) -- cgit From 25cf4f2fc712530a65dc3b533508c36d0439b728 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 13:04:08 +0800 Subject: vim-patch:8.2.2653: build failure Problem: Build failure. Solution: Add missing changes. https://github.com/vim/vim/commit/3a0f092ac0dbdd4ce71f9c4abe020e89f13df36c Omit E1176: only applicable to Vim9 script. Co-authored-by: Bram Moolenaar --- test/functional/vimscript/exepath_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua index 439dd96fcd..db96b79743 100644 --- a/test/functional/vimscript/exepath_spec.lua +++ b/test/functional/vimscript/exepath_spec.lua @@ -23,7 +23,7 @@ describe('exepath()', function() for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) end - eq('Vim(call):E1142: Non-empty string required for argument 1', exc_exec('call exepath("")')) + eq('Vim(call):E1175: Non-empty string required for argument 1', exc_exec('call exepath("")')) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) -- cgit From a86295cd5c2bf15a11eb05e226fd8e226154f6a6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:26:17 +0800 Subject: vim-patch:8.2.0615: regexp benchmark stest is old style (#20940) Problem: Regexp benchmark stest is old style. Solution: Make it a new style test. Fix using a NULL list. Add more tests. (Yegappan Lakshmanan, closes vim/vim#5963) https://github.com/vim/vim/commit/ad48e6c1590842ab6d48e6caba3e9250734dae27 N/A patches: vim-patch:9.0.0829: wrong counts in macro comment --- test/functional/vimscript/null_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index 2451da983e..1153baac46 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -69,7 +69,7 @@ describe('NULL', function() null_expr_test('can be splice-indexed', 'L[:]', 0, {}) null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) - null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() + null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function() -- cgit From 01ccfb40e3ac678829f301aec1d10f5fc06548c6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 20:16:29 +0800 Subject: vim-patch:8.2.1106: crash when trying to use s: variable in typed command Problem: Crash when trying to use s: variable in typed command. Solution: Don't use the script index when not set. (Ken Takata, closes vim/vim#6366) https://github.com/vim/vim/commit/8e6cbb72324b6fb25d1a9abd6cc4d102d0e5f14e --- test/functional/vimscript/eval_spec.lua | 74 --------------------------------- 1 file changed, 74 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 64a3cf5471..9b0ace0882 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -16,7 +16,6 @@ local lfs = require('lfs') local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec -local exec = helpers.exec local exec_lua = helpers.exec_lua local exec_capture = helpers.exec_capture local eval = helpers.eval @@ -152,79 +151,6 @@ describe('List support code', function() end) end) --- oldtest: Test_deep_nest() -it('Error when if/for/while/try/function is nested too deep',function() - clear() - local screen = Screen.new(80, 24) - screen:attach() - meths.set_option('laststatus', 2) - exec([[ - " Deep nesting of if ... endif - func Test1() - let @a = join(repeat(['if v:true'], 51), "\n") - let @a ..= "\n" - let @a ..= join(repeat(['endif'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of for ... endfor - func Test2() - let @a = join(repeat(['for i in [1]'], 51), "\n") - let @a ..= "\n" - let @a ..= join(repeat(['endfor'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of while ... endwhile - func Test3() - let @a = join(repeat(['while v:true'], 51), "\n") - let @a ..= "\n" - let @a ..= join(repeat(['endwhile'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of try ... endtry - func Test4() - let @a = join(repeat(['try'], 51), "\n") - let @a ..= "\necho v:true\n" - let @a ..= join(repeat(['endtry'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of function ... endfunction - func Test5() - let @a = join(repeat(['function X()'], 51), "\n") - let @a ..= "\necho v:true\n" - let @a ..= join(repeat(['endfunction'], 51), "\n") - @a - let @a = '' - endfunc - ]]) - screen:expect({any = '%[No Name%]'}) - feed(':call Test1()') - screen:expect({any = 'E579: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test2()') - screen:expect({any = 'E585: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test3()') - screen:expect({any = 'E585: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test4()') - screen:expect({any = 'E601: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test5()') - screen:expect({any = 'E1058: '}) -end) - describe("uncaught exception", function() before_each(clear) after_each(function() -- cgit From d337814906b1377e34aa2c2dfd8aa16285328692 Mon Sep 17 00:00:00 2001 From: Victor Blanchard <48864055+Viblanc@users.noreply.github.com> Date: Mon, 7 Nov 2022 04:31:50 +0100 Subject: feat: ":write ++p" creates parent dirs #20835 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `:write ++p foo/bar/baz.txt` should create parent directories `foo/bar/` if they do not exist - Note: `:foo ++…` is usually for options. No existing options have a single-char abbreviation (presumably by design), so it's safe to special-case `++p` here. - Same for `writefile(…, 'foo/bar/baz.txt', 'p')` - `BufWriteCmd` can see the ++p flag via `v:cmdarg`. closes #19884 --- test/functional/vimscript/writefile_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 5f693249a9..8c8da9dc88 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -111,6 +111,26 @@ describe('writefile()', function() pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail))) end) + it('writefile(..., "p") creates missing parent directories', function() + os.remove(dname) + eq(nil, read_file(dfname)) + eq(0, funcs.writefile({'abc', 'def', 'ghi'}, dfname, 'p')) + eq('abc\ndef\nghi\n', read_file(dfname)) + os.remove(dfname) + os.remove(dname) + eq(nil, read_file(dfname)) + eq(0, funcs.writefile({'\na\nb\n'}, dfname, 'pb')) + eq('\0a\0b\0', read_file(dfname)) + os.remove(dfname) + os.remove(dname) + eq('Vim(call):E32: No file name', + pcall_err(command, ('call writefile([], "%s", "p")'):format(dfname .. '.d/'))) + eq(('Vim(call):E482: Can\'t open file ./ for writing: illegal operation on a directory'), + pcall_err(command, 'call writefile([], "./", "p")')) + eq(('Vim(call):E482: Can\'t open file . for writing: illegal operation on a directory'), + pcall_err(command, 'call writefile([], ".", "p")')) + end) + it('errors out with invalid arguments', function() write_file(fname, 'TEST') eq('Vim(call):E119: Not enough arguments for function: writefile', -- cgit From e8cc489accc435076afb4fdf89778b64f0a48473 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 14 Nov 2022 10:01:35 +0000 Subject: feat(test): add Lua forms for API methods (#20152) --- test/functional/vimscript/eval_spec.lua | 2 +- test/functional/vimscript/map_functions_spec.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 9b0ace0882..d50c252569 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -195,7 +195,7 @@ describe('listing functions using :function', function() it('does not crash if another function is deleted while listing', function() local screen = Screen.new(80, 24) screen:attach() - matches('.*: Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[ + matches('Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[ vim.cmd([[ func Func1() endfunc diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index 8645b1e506..ba1b4d7a76 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -246,9 +246,9 @@ describe('mapset()', function() end) it('does not leak memory if lhs is missing', function() - eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + eq('Vim:E460: entries missing in mapset() dict argument', pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]])) - eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + eq('Vim:E460: entries missing in mapset() dict argument', pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]])) end) end) -- 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/vimscript/eval_spec.lua | 4 +-- test/functional/vimscript/executable_spec.lua | 22 +++++++++------- test/functional/vimscript/execute_spec.lua | 4 +-- test/functional/vimscript/exepath_spec.lua | 13 +++++----- test/functional/vimscript/fnamemodify_spec.lua | 6 ++--- test/functional/vimscript/functions_spec.lua | 4 +-- test/functional/vimscript/has_spec.lua | 4 +-- test/functional/vimscript/hostname_spec.lua | 6 ++--- .../vimscript/msgpack_functions_spec.lua | 4 +-- test/functional/vimscript/server_spec.lua | 10 ++++---- test/functional/vimscript/system_spec.lua | 30 +++++++++++----------- 11 files changed, 56 insertions(+), 51 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index d50c252569..a8a901042b 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -71,13 +71,13 @@ describe("backtick expansion", function() end) it("with default 'shell'", function() - if helpers.iswin() then + if helpers.is_os('win') then command(":silent args `dir /b *2`") else command(":silent args `echo ***2`") end eq({ "file2", }, eval("argv()")) - if helpers.iswin() then + if helpers.is_os('win') then command(":silent args `dir /s/b *4`") eq({ "subdir\\file4", }, eval("map(argv(), 'fnamemodify(v:val, \":.\")')")) else diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index b49eb09512..43e4a29e1a 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -1,15 +1,16 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call, iswin, write_file, command = - helpers.eq, helpers.clear, helpers.call, helpers.iswin, helpers.write_file, +local eq, clear, call, write_file, command = + helpers.eq, helpers.clear, helpers.call, helpers.write_file, helpers.command local exc_exec = helpers.exc_exec local eval = helpers.eval +local is_os = helpers.is_os describe('executable()', function() before_each(clear) it('returns 1 for commands in $PATH', function() - local exe = iswin() and 'ping' or 'ls' + local exe = is_os('win') and 'ping' or 'ls' eq(1, call('executable', exe)) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') eq(1, call('executable', 'null')) @@ -17,7 +18,7 @@ describe('executable()', function() eq(1, call('executable', 'false')) end) - if iswin() then + if is_os('win') then it('exepath respects shellslash', function() command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') eq([[test\functional\fixtures\bin\null.CMD]], call('fnamemodify', call('exepath', 'null'), ':.')) @@ -56,8 +57,8 @@ describe('executable()', function() -- Some executable in build/bin/, *not* in $PATH nor CWD. local sibling_exe = 'printargs-test' -- Windows: siblings are in Nvim's "pseudo-$PATH". - local expected = iswin() and 1 or 0 - if iswin() then + local expected = is_os('win') and 1 or 0 + if is_os('win') then eq('arg1=lemon;arg2=sky;arg3=tree;', call('system', sibling_exe..' lemon sky tree')) end @@ -69,7 +70,7 @@ describe('executable()', function() clear() write_file('Xtest_not_executable', 'non-executable file') write_file('Xtest_executable', 'executable file (exec-bit set)') - if not iswin() then -- N/A for Windows. + if not is_os('win') then -- N/A for Windows. call('system', {'chmod', '-x', 'Xtest_not_executable'}) call('system', {'chmod', '+x', 'Xtest_executable'}) end @@ -90,14 +91,17 @@ describe('executable()', function() end) it('set, qualified as a path', function() - local expected = iswin() and 0 or 1 + local expected = is_os('win') and 0 or 1 eq(expected, call('executable', './Xtest_executable')) end) end) end) describe('executable() (Windows)', function() - if not iswin() then return end -- N/A for Unix. + if not is_os('win') then + pending('N/A for non-windows') + return + end local exts = {'bat', 'exe', 'com', 'cmd'} setup(function() diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index a733b098f5..5fe3d787cb 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -8,7 +8,7 @@ local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed -local iswin = helpers.iswin +local is_os = helpers.is_os describe('execute()', function() before_each(clear) @@ -265,7 +265,7 @@ describe('execute()', function() -- This deviates from vim behavior, but is consistent -- with how nvim currently displays the output. it('captures shell-command output', function() - local win_lf = iswin() and '\13' or '' + local win_lf = is_os('win') and '\13' or '' eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) end) diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua index db96b79743..056f67e0ad 100644 --- a/test/functional/vimscript/exepath_spec.lua +++ b/test/functional/vimscript/exepath_spec.lua @@ -1,19 +1,20 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call, iswin = - helpers.eq, helpers.clear, helpers.call, helpers.iswin +local eq, clear, call = + helpers.eq, helpers.clear, helpers.call local command = helpers.command local exc_exec = helpers.exc_exec local matches = helpers.matches +local is_os = helpers.is_os describe('exepath()', function() before_each(clear) it('returns 1 for commands in $PATH', function() - local exe = iswin() and 'ping' or 'ls' - local ext_pat = iswin() and '%.EXE$' or '$' + local exe = is_os('win') and 'ping' or 'ls' + local ext_pat = is_os('win') and '%.EXE$' or '$' matches(exe .. ext_pat, call('exepath', exe)) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') - ext_pat = iswin() and '%.CMD$' or '$' + ext_pat = is_os('win') and '%.CMD$' or '$' matches('null' .. ext_pat, call('exepath', 'null')) matches('true' .. ext_pat, call('exepath', 'true')) matches('false' .. ext_pat, call('exepath', 'false')) @@ -30,7 +31,7 @@ describe('exepath()', function() end end) - if iswin() then + if is_os('win') then it('append extension if omitted', function() local filename = 'cmd' local pathext = '.exe' diff --git a/test/functional/vimscript/fnamemodify_spec.lua b/test/functional/vimscript/fnamemodify_spec.lua index d54a6db417..c3ecdd853c 100644 --- a/test/functional/vimscript/fnamemodify_spec.lua +++ b/test/functional/vimscript/fnamemodify_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local iswin = helpers.iswin local fnamemodify = helpers.funcs.fnamemodify local getcwd = helpers.funcs.getcwd local command = helpers.command local write_file = helpers.write_file local alter_slashes = helpers.alter_slashes +local is_os = helpers.is_os local function eq_slashconvert(expected, got) eq(alter_slashes(expected), alter_slashes(got)) @@ -27,7 +27,7 @@ describe('fnamemodify()', function() local root = helpers.pathroot() eq(root, fnamemodify([[/]], ':p:h')) eq(root, fnamemodify([[/]], ':p')) - if iswin() then + if is_os('win') then eq(root, fnamemodify([[\]], ':p:h')) eq(root, fnamemodify([[\]], ':p')) command('set shellslash') @@ -114,7 +114,7 @@ describe('fnamemodify()', function() it('handles shell escape', function() local expected - if iswin() then + if is_os('win') then -- we expand with double-quotes on Windows expected = [["hello there! quote ' newline]] .. '\n' .. [["]] else diff --git a/test/functional/vimscript/functions_spec.lua b/test/functional/vimscript/functions_spec.lua index 20c1400030..09b3334989 100644 --- a/test/functional/vimscript/functions_spec.lua +++ b/test/functional/vimscript/functions_spec.lua @@ -9,12 +9,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eval = helpers.eval -local iswin = helpers.iswin local matches = helpers.matches +local is_os = helpers.is_os before_each(clear) it('windowsversion()', function() clear() - matches(iswin() and '^%d+%.%d+$' or '^$', eval('windowsversion()')) + matches(is_os('win') and '^%d+%.%d+$' or '^$', eval('windowsversion()')) end) diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua index 4d9b226434..2e26d603b3 100644 --- a/test/functional/vimscript/has_spec.lua +++ b/test/functional/vimscript/has_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local clear = helpers.clear local funcs = helpers.funcs -local iswin = helpers.iswin +local is_os = helpers.is_os describe('has()', function() before_each(clear) @@ -51,7 +51,7 @@ describe('has()', function() end) it('"unnamedplus"', function() - if (not iswin()) and funcs.has("clipboard") == 1 then + if (not is_os('win')) and funcs.has("clipboard") == 1 then eq(1, funcs.has("unnamedplus")) else eq(0, funcs.has("unnamedplus")) diff --git a/test/functional/vimscript/hostname_spec.lua b/test/functional/vimscript/hostname_spec.lua index 6112cf64e3..7d4baa7213 100644 --- a/test/functional/vimscript/hostname_spec.lua +++ b/test/functional/vimscript/hostname_spec.lua @@ -3,7 +3,7 @@ local eq = helpers.eq local ok = helpers.ok local call = helpers.call local clear = helpers.clear -local iswin = helpers.iswin +local is_os = helpers.is_os describe('hostname()', function() before_each(clear) @@ -13,8 +13,8 @@ describe('hostname()', function() ok(string.len(actual) > 0) if call('executable', 'hostname') == 1 then local expected = string.gsub(call('system', 'hostname'), '[\n\r]', '') - eq((iswin() and expected:upper() or expected), - (iswin() and actual:upper() or actual)) + eq((is_os('win') and expected:upper() or expected), + (is_os('win') and actual:upper() or actual)) end end) end) diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua index cab67d77e4..de5a721efe 100644 --- a/test/functional/vimscript/msgpack_functions_spec.lua +++ b/test/functional/vimscript/msgpack_functions_spec.lua @@ -5,7 +5,7 @@ local eval, eq = helpers.eval, helpers.eq local command = helpers.command local nvim = helpers.nvim local exc_exec = helpers.exc_exec -local iswin = helpers.iswin +local is_os = helpers.is_os describe('msgpack*() functions', function() before_each(clear) @@ -467,7 +467,7 @@ describe('msgpackparse() function', function() eval(cmd) eval(cmd) -- do it again (try to force segfault) local api_info = eval(cmd) -- do it again - if iswin() then + if is_os('win') then helpers.assert_alive() pending('msgpackparse() has a bug on windows') return diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index 6e95459630..14c87d9d93 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths -local iswin = helpers.iswin local ok = helpers.ok local matches = helpers.matches local pcall_err = helpers.pcall_err local mkdir = helpers.mkdir +local is_os = helpers.is_os local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do @@ -19,7 +19,7 @@ describe('server', function() mkdir(dir) clear({ env={ XDG_RUNTIME_DIR=dir } }) matches(dir, funcs.stdpath('run')) - if not iswin() then + if not is_os('win') then matches(dir, funcs.serverstart()) end end) @@ -65,7 +65,7 @@ describe('server', function() eq('', meths.get_vvar('servername')) -- v:servername and $NVIM take the next available server. - local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]] + local servername = (is_os('win') and [[\\.\pipe\Xtest-functional-server-pipe]] or './Xtest-functional-server-socket') funcs.serverstart(servername) eq(servername, meths.get_vvar('servername')) @@ -130,7 +130,7 @@ describe('server', function() local n = eval('len(serverlist())') -- Add some servers. - local servs = (iswin() + local servs = (is_os('win') and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } or { [[./Xtest-pipe0934]], [[./Xtest-pipe4324]] }) for _, s in ipairs(servs) do @@ -164,7 +164,7 @@ describe('startup --listen', function() end) it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() - local addr = (iswin() and [[\\.\pipe\Xtest-listen-pipe]] + local addr = (is_os('win') and [[\\.\pipe\Xtest-listen-pipe]] or './Xtest-listen-pipe') clear({ env={ NVIM_LISTEN_ADDRESS='./Xtest-env-pipe' }, args={ '--listen', addr } }) diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index ed822add72..dbf734b51a 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -9,9 +9,9 @@ local command = helpers.command local insert = helpers.insert local expect = helpers.expect local exc_exec = helpers.exc_exec -local iswin = helpers.iswin local os_kill = helpers.os_kill local pcall_err = helpers.pcall_err +local is_os = helpers.is_os local Screen = require('test.functional.ui.screen') @@ -85,7 +85,7 @@ describe('system()', function() end) it('does NOT run in shell', function() - if iswin() then + if is_os('win') then eq("%PATH%\n", eval("system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'Write-Output', '%PATH%'])")) else eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])")) @@ -94,7 +94,7 @@ describe('system()', function() end) it('sets v:shell_error', function() - if iswin() then + if is_os('win') then eval([[system("cmd.exe /c exit")]]) eq(0, eval('v:shell_error')) eval([[system("cmd.exe /c exit 1")]]) @@ -123,7 +123,7 @@ describe('system()', function() screen:attach() end) - if iswin() then + if is_os('win') then local function test_more() eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]])) end @@ -184,7 +184,7 @@ describe('system()', function() -- * on Windows, expected to default to Western European enc -- * on Linux, expected to default to UTF8 command([[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']]) - eq(iswin() and '??\n' or 'ああ\n', eval([[system('Write-Output "ああ"')]])) + eq(is_os('win') and '??\n' or 'ああ\n', eval([[system('Write-Output "ああ"')]])) end) it('`echo` and waits for its return', function() @@ -213,7 +213,7 @@ describe('system()', function() screen:try_resize(72, 14) feed(':4verbose echo system("echo hi")') - if iswin() then + if is_os('win') then screen:expect{any=[[Executing command: "'fake_shell' 'cmdflag' '"echo hi"'"]]} else screen:expect{any=[[Executing command: "'fake_shell' 'cmdflag' 'echo hi'"]]} @@ -243,7 +243,7 @@ describe('system()', function() end) it('`yes` interrupted with CTRL-C', function() - feed(':call system("' .. (iswin() + feed(':call system("' .. (is_os('win') and 'for /L %I in (1,0,2) do @echo y' or 'yes') .. '")') screen:expect([[ @@ -260,7 +260,7 @@ describe('system()', function() ~ | ~ | ~ | -]] .. (iswin() +]] .. (is_os('win') and [[ :call system("for /L %I in (1,0,2) do @echo y") |]] or [[ @@ -286,7 +286,7 @@ describe('system()', function() it('`yes` interrupted with mapped CTRL-C', function() command('nnoremap i') - feed(':call system("' .. (iswin() + feed(':call system("' .. (is_os('win') and 'for /L %I in (1,0,2) do @echo y' or 'yes') .. '")') screen:expect([[ @@ -303,7 +303,7 @@ describe('system()', function() ~ | ~ | ~ | -]] .. (iswin() +]] .. (is_os('win') and [[ :call system("for /L %I in (1,0,2) do @echo y") |]] or [[ @@ -330,7 +330,7 @@ describe('system()', function() describe('passing no input', function() it('returns the program output', function() - if iswin() then + if is_os('win') then eq("echoed\n", eval('system("echo echoed")')) else eq("echoed", eval('system("echo -n echoed")')) @@ -438,7 +438,7 @@ describe('systemlist()', function() before_each(clear) it('sets v:shell_error', function() - if iswin() then + if is_os('win') then eval([[systemlist("cmd.exe /c exit")]]) eq(0, eval('v:shell_error')) eval([[systemlist("cmd.exe /c exit 1")]]) @@ -617,12 +617,12 @@ describe('systemlist()', function() return end helpers.set_shell_powershell() - eq({iswin() and 'あ\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) + eq({is_os('win') and 'あ\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc -- * on Linux, expected to default to UTF8 command([[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']]) - eq({iswin() and '?\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) + eq({is_os('win') and '?\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) end) end) @@ -639,7 +639,7 @@ describe('shell :!', function() 1 4 2]]) - if iswin() then + if is_os('win') then feed(':4verbose %!sort /R') screen:expect{ any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]] -- 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/vimscript/system_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index dbf734b51a..f099b4a36e 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -1,3 +1,5 @@ +-- Tests for system() and :! shell. + local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive -- cgit From 2f1fd15554921dc2375c2ad136e727229e72348a Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Thu, 12 Jan 2023 23:25:29 +0600 Subject: fix(powershell): wrong length allocation for ":%w !" #20530 Problem: The calculation of `len` in `make_filter_cmd` for powershell falls short by one character for the following ex command: :%w !sort This command satisfies these conditions: - `itmp` is not null - `otmp` is null __NOTE__ that other shells circumvent this bug only because of `len` allocation for six extra characters: a pair of curly braces and four spaces: https://github.com/neovim/neovim/blob/cfdb4cbada8c65aa57e69776bcc0f7b8b298317a/src/nvim/ex_cmds.c#L1551-L1554 If allocation for these six characters are removed, then bash also faces the same bug. Solution: Add allocation for 6 extra bytes. 1 would do, but let's keep powershell in sync with other shells as much as possible. --- test/functional/vimscript/system_spec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index f099b4a36e..7ada1c4bea 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -662,4 +662,33 @@ describe('shell :!', function() 1]]) end end) + + it(':{range}! without redirecting to buffer', function() + local screen = Screen.new(500, 10) + screen:attach() + insert([[ + 3 + 1 + 4 + 2]]) + feed(':4verbose %w !sort') + if is_os('win') then + screen:expect{ + any=[[Executing command: .?sort %< .*]] + } + else + screen:expect{ + any=[[Executing command: .?%(sort%) %< .*]] + + } + end + feed('') + helpers.set_shell_powershell(true) + feed(':4verbose %w !sort') + screen:expect{ + any=[[Executing command: .?& { Get%-Content .* | & sort }]] + } + feed('') + helpers.expect_exit(command, 'qall!') + end) end) -- cgit From 61d5bd561addfd4cc9917712bdf983e77137089e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 16 Jan 2023 06:38:50 +0800 Subject: refactor: remove E5500, adjust tests Now with try_end() including more exception info, E5500 looks like redundant information. Adjust tests for more exception information. --- test/functional/vimscript/api_functions_spec.lua | 3 ++- test/functional/vimscript/ctx_functions_spec.lua | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 8ca245f61a..c032ac3030 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -5,6 +5,7 @@ local neq, eq, command = helpers.neq, helpers.eq, helpers.command local clear, curbufmeths = helpers.clear, helpers.curbufmeths local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local insert, pcall_err = helpers.insert, helpers.pcall_err +local matches = helpers.matches local meths = helpers.meths describe('eval-API', function() @@ -49,7 +50,7 @@ describe('eval-API', function() it('cannot change texts if textlocked', function() command("autocmd TextYankPost ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])") - eq('Vim(call):E5555: API call: E565: Not allowed to change text or change window', + matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', pcall_err(command, "normal! yy")) end) diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index d92a81c55b..773ec8d0f7 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -173,9 +173,9 @@ describe('context functions', function() call('SaveSFuncs') call('DeleteSFuncs') - eq('Vim(call):E117: Unknown function: s:greet', + eq('function Greet, line 1: Vim(call):E117: Unknown function: s:greet', pcall_err(command, [[call Greet('World')]])) - eq('Vim(call):E117: Unknown function: s:greet_all', + eq('function GreetAll, line 1: Vim(call):E117: Unknown function: s:greet_all', pcall_err(command, [[call GreetAll('World', 'One', 'Two', 'Three')]])) call('RestoreFuncs') -- cgit From 6ec7bcb6184f562157eebc8d0f25f78ba333c6a5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 16 Jan 2023 20:43:13 +0100 Subject: test: avoid noise in NVIM_LOG_FILE Problem: Tests that _intentionally_ fail certain conditions cause noise in $NVIM_LOG_FILE: $NVIM_LOG_FILE: /home/runner/work/neovim/neovim/build/.nvimlog (last 100 lines) WRN 2023-01-16T18:26:27.673 T599.7799.0 unsubscribe:519: RPC: ch 1: tried to unsubscribe unknown event 'doesnotexist' WRN 2023-01-16T18:29:00.557 ?.11151 server_start:163: Failed to start server: no such file or directory: /X/X/X/... WRN 2023-01-16T18:33:07.269 127.0.0.1:12345 server_start:163: Failed to start server: address already in use: 127.0.0.1 ... -- Output to stderr: module 'vim.shared' not found: no field package.preload['vim.shared'] no file './vim/shared.lua' no file '/home/runner/nvim-deps/usr/share/lua/5.1/vim/shared.lua' no file '/home/runner/nvim-deps/usr/share/lua/5.1/vim/shared/init.lua' no file '/home/runner/nvim-deps/usr/lib/lua/5.1/vim/shared.lua' no file '/home/runner/nvim-deps/usr/lib/lua/5.1/vim/shared/init.lua' no file './vim/shared.so' ... E970: Failed to initialize builtin lua modules Solution: - Log to a private $NVIM_LOG_FILE in tests that intentionally fail and cause ERR log messages. - Assert that the expected messages are actually logged. --- test/functional/vimscript/server_spec.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index 14c87d9d93..a2d99c7d45 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -1,4 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) +local assert_log = helpers.assert_log +local retry = helpers.retry local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths local ok = helpers.ok @@ -7,6 +9,8 @@ local pcall_err = helpers.pcall_err local mkdir = helpers.mkdir local is_os = helpers.is_os +local testlog = 'Xtest-server-log' + local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do funcs.serverstop(server) @@ -14,6 +18,10 @@ local function clear_serverlist() end describe('server', function() + after_each(function() + os.remove(testlog) + end) + it('serverstart() stores sockets in $XDG_RUNTIME_DIR', function() local dir = 'Xtest_xdg_run' mkdir(dir) @@ -74,13 +82,22 @@ describe('server', function() end) it('serverstop() returns false for invalid input', function() - clear() + clear{env={ + NVIM_LOG_FILE=testlog, + NVIM_LISTEN_ADDRESS='.', + }} eq(0, eval("serverstop('')")) eq(0, eval("serverstop('bogus-socket-name')")) + retry(nil, 1000, function() + assert_log('Not listening on bogus%-socket%-name', testlog, 10) + end) end) it('parses endpoints', function() - clear() + clear{env={ + NVIM_LOG_FILE=testlog, + NVIM_LISTEN_ADDRESS='.', + }} clear_serverlist() eq({}, funcs.serverlist()) @@ -104,6 +121,9 @@ describe('server', function() if status then table.insert(expected, v4) pcall(funcs.serverstart, v4) -- exists already; ignore + retry(nil, 1000, function() + assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10) + end) end local v6 = '::1:12345' @@ -111,6 +131,9 @@ describe('server', function() if status then table.insert(expected, v6) pcall(funcs.serverstart, v6) -- exists already; ignore + retry(nil, 1000, function() + assert_log('Failed to start server: address already in use: ::1', testlog, 10) + end) end eq(expected, funcs.serverlist()) clear_serverlist() -- cgit From 665a7dafaf892b31285f35a43a90fc6e968fd7da Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 17 Jan 2023 00:12:59 +0100 Subject: refactor(tests): lift retry() into assert_log() --- test/functional/vimscript/server_spec.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index a2d99c7d45..c89a0c4e93 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log -local retry = helpers.retry local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths local ok = helpers.ok @@ -88,9 +87,7 @@ describe('server', function() }} eq(0, eval("serverstop('')")) eq(0, eval("serverstop('bogus-socket-name')")) - retry(nil, 1000, function() - assert_log('Not listening on bogus%-socket%-name', testlog, 10) - end) + assert_log('Not listening on bogus%-socket%-name', testlog, 10) end) it('parses endpoints', function() @@ -121,9 +118,7 @@ describe('server', function() if status then table.insert(expected, v4) pcall(funcs.serverstart, v4) -- exists already; ignore - retry(nil, 1000, function() - assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10) - end) + assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10) end local v6 = '::1:12345' @@ -131,9 +126,7 @@ describe('server', function() if status then table.insert(expected, v6) pcall(funcs.serverstart, v6) -- exists already; ignore - retry(nil, 1000, function() - assert_log('Failed to start server: address already in use: ::1', testlog, 10) - end) + assert_log('Failed to start server: address already in use: ::1', testlog, 10) end eq(expected, funcs.serverlist()) clear_serverlist() -- cgit From 3b7548504344d72b0228e1bd29a7f28df813a3bd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 23 Jan 2023 19:32:27 +0800 Subject: revert: "shada/context: fully remove jumplist duplicates #10898" (#21874) This reverts commit 8b8ecf44f2cda43bbd710ec22ef99439b71888cd. It is causing performance problems on exit. Fix #21082. --- test/functional/vimscript/ctx_functions_spec.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index 773ec8d0f7..5ee84a6d13 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -287,9 +287,11 @@ describe('context functions', function() local with_jumps = { ['jumps'] = eval(([[ - filter(map(getjumplist()[0], 'filter( - { "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, - { k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') + filter(map(add( + getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }), + 'filter( + { "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, + { k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') ]]):gsub('\n', '')) } -- cgit