From 05faa8f30ad770d4e4ead41cec601ccced8fb97f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 15 Feb 2023 07:26:55 +0800 Subject: test: make expect_unchanged() less confusing (#22255) Problem: The sleep before collecting the initial screen state is confusing and may lead to unexpected success if it comes after a blocking RPC call. Solution: Remove that sleep and add an "intermediate" argument. --- test/functional/vimscript/timer_spec.lua | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 1818a71ea2..a58cd6ae7f 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -251,15 +251,7 @@ describe('timers', function() :good^ | ]]) command('let g:val = 1') - - screen:expect{grid=[[ - | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - :good^ | - ]], intermediate=true, timeout=load_adjust(200)} + screen:expect_unchanged(true, load_adjust(200)) eq(2, eval('g:val')) end) -- cgit From ce597235a26839826de88ecd8b949ec54c310fbd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Feb 2023 16:31:05 +0100 Subject: feat(ui): restore has('gui_running') Problem: has('gui_running') is still common in the wild and our answer has changed over time, causing frustration. https://github.com/vimpostor/vim-tpipeline/commit/95a6ccbe9f33bc42dd4cee45731d8bc3fbcd92d1 Solution: Use stdin_tty/stdout_tty to decide if a UI is (not) a GUI. --- test/functional/vimscript/has_spec.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua index 2e26d603b3..78a761d370 100644 --- a/test/functional/vimscript/has_spec.lua +++ b/test/functional/vimscript/has_spec.lua @@ -1,8 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq +local Screen = require('test.functional.ui.screen') local clear = helpers.clear +local connect = helpers.connect +local eq = helpers.eq local funcs = helpers.funcs local is_os = helpers.is_os +local nvim_prog = helpers.nvim_prog describe('has()', function() before_each(clear) @@ -69,8 +72,22 @@ describe('has()', function() end end) + it('"gui_running"', function() + eq(0, funcs.has('gui_running')) + local tui = Screen.new(50,15) + local gui_session = connect(funcs.serverstart()) + local gui = Screen.new(50,15) + eq(0, funcs.has('gui_running')) + tui:attach({ext_linegrid=true, rgb=true, stdin_tty=true, stdout_tty=true}) + gui:attach({ext_multigrid=true, rgb=true}, gui_session) + eq(1, funcs.has('gui_running')) + tui:detach() + eq(1, funcs.has('gui_running')) + gui:detach() + eq(0, funcs.has('gui_running')) + end) + it('does not change v:shell_error', function() - local nvim_prog = helpers.nvim_prog funcs.system({nvim_prog, '-es', '+73cquit'}) funcs.has('python3') -- use a call whose implementation shells out eq(73, funcs.eval('v:shell_error')) -- 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/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 7ada1c4bea..158dfe86d7 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -644,12 +644,12 @@ describe('shell :!', function() 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"]] + any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | %%{ "$_" } | Out%-File .*; 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 .*; exit $LastExitCode"]] } end feed('') -- 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/vimscript/api_functions_spec.lua | 4 ++-- test/functional/vimscript/buf_functions_spec.lua | 11 ++++++----- test/functional/vimscript/eval_spec.lua | 6 +++--- test/functional/vimscript/glob_spec.lua | 7 ++++--- test/functional/vimscript/writefile_spec.lua | 11 ++++++----- 5 files changed, 21 insertions(+), 18 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 c032ac3030..dc591c3e0d 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local lfs = require('lfs') +local luv = require('luv') 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 @@ -118,7 +118,7 @@ describe('eval-API', function() end) it('are highlighted by vim.vim syntax file', function() - if lfs.attributes("build/runtime/syntax/vim/generated.vim",'uid') == nil then + if luv.fs_stat("build/runtime/syntax/vim/generated.vim").uid == nil then pending("runtime was not built, skipping test") return end diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index b521620320..7a54f479e0 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') local eq = helpers.eq local clear = helpers.clear @@ -16,6 +16,7 @@ local curtabmeths = helpers.curtabmeths local get_pathsep = helpers.get_pathsep local rmdir = helpers.rmdir local pcall_err = helpers.pcall_err +local mkdir = helpers.mkdir local fname = 'Xtest-functional-eval-buf_functions' local fname2 = fname .. '.2' @@ -62,7 +63,7 @@ describe('bufname() function', function() eq('', funcs.bufname('X')) end) before_each(function() - lfs.mkdir(dirname) + mkdir(dirname) end) after_each(function() rmdir(dirname) @@ -70,7 +71,7 @@ describe('bufname() function', function() it('returns expected buffer name', function() eq('', funcs.bufname('%')) -- Buffer has no name yet command('file ' .. fname) - local wd = lfs.currentdir() + local wd = luv.cwd() local sep = get_pathsep() local curdirname = funcs.fnamemodify(wd, ':t') for _, arg in ipairs({'%', 1, 'X', wd}) do @@ -103,7 +104,7 @@ describe('bufnr() function', function() it('returns expected buffer number', function() eq(1, funcs.bufnr('%')) command('file ' .. fname) - local wd = lfs.currentdir() + local wd = luv.cwd() local curdirname = funcs.fnamemodify(wd, ':t') eq(1, funcs.bufnr(fname)) eq(1, funcs.bufnr(wd)) @@ -144,7 +145,7 @@ describe('bufwinnr() function', function() eq(-1, funcs.bufwinnr('X')) end) before_each(function() - lfs.mkdir(dirname) + mkdir(dirname) end) after_each(function() rmdir(dirname) diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index a8a901042b..b995aaa5a6 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -12,7 +12,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local lfs = require('lfs') +local mkdir = helpers.mkdir local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec @@ -56,11 +56,11 @@ end) describe("backtick expansion", function() setup(function() clear() - lfs.mkdir("test-backticks") + mkdir("test-backticks") write_file("test-backticks/file1", "test file 1") write_file("test-backticks/file2", "test file 2") write_file("test-backticks/file3", "test file 3") - lfs.mkdir("test-backticks/subdir") + mkdir("test-backticks/subdir") write_file("test-backticks/subdir/file4", "test file 4") -- Long path might cause "Press ENTER" prompt; use :silent to avoid it. command('silent cd test-backticks') diff --git a/test/functional/vimscript/glob_spec.lua b/test/functional/vimscript/glob_spec.lua index b8807ecfcc..948a63f050 100644 --- a/test/functional/vimscript/glob_spec.lua +++ b/test/functional/vimscript/glob_spec.lua @@ -1,17 +1,18 @@ -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local clear, command, eval, eq = helpers.clear, helpers.command, helpers.eval, helpers.eq +local mkdir = helpers.mkdir before_each(function() clear() - lfs.mkdir('test-glob') + mkdir('test-glob') -- Long path might cause "Press ENTER" prompt; use :silent to avoid it. command('silent cd test-glob') end) after_each(function() - lfs.rmdir('test-glob') + luv.fs_rmdir('test-glob') end) describe('glob()', function() diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 8c8da9dc88..c816efd37b 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') +local luv = require('luv') +local mkdir = helpers.mkdir local clear = helpers.clear local eq = helpers.eq local funcs = helpers.funcs @@ -19,16 +20,16 @@ local ddname_tail = '2' local ddname = dname .. '/' .. ddname_tail before_each(function() - lfs.mkdir(dname) - lfs.mkdir(ddname) + mkdir(dname) + mkdir(ddname) clear() end) after_each(function() os.remove(fname) os.remove(dfname) - lfs.rmdir(ddname) - lfs.rmdir(dname) + luv.fs_rmdir(ddname) + luv.fs_rmdir(dname) end) describe('writefile()', function() -- cgit From 0e4086b74189c2b31ce63c6c5e85124edaf20d08 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Apr 2023 18:06:59 +0800 Subject: fix(eval): prevent double-free in garbage collection (#22990) --- test/functional/vimscript/eval_spec.lua | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index b995aaa5a6..b411b1e379 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -220,3 +220,38 @@ describe('listing functions using :function', function() assert_alive() end) end) + +it('no double-free in garbage collection #16287', function() + clear() + -- Don't use exec() here as using a named script reproduces the issue better. + write_file('Xgarbagecollect.vim', [[ + func Foo() abort + let s:args = [a:000] + let foo0 = "" + let foo1 = "" + let foo2 = "" + let foo3 = "" + let foo4 = "" + let foo5 = "" + let foo6 = "" + let foo7 = "" + let foo8 = "" + let foo9 = "" + let foo10 = "" + let foo11 = "" + let foo12 = "" + let foo13 = "" + let foo14 = "" + endfunc + + set updatetime=1 + call Foo() + call Foo() + ]]) + finally(function() + os.remove('Xgarbagecollect.vim') + end) + command('source Xgarbagecollect.vim') + sleep(10) + assert_alive() +end) -- cgit From aab95ec67e4d80e63cc5c5acc42f3832e76e0781 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 11 Apr 2023 11:18:54 +0200 Subject: test: avoid name collisions with Xtest directory (#23019) --- 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 158dfe86d7..130d5d81fa 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -393,7 +393,7 @@ describe('system()', function() end) describe('with output containing NULs', function() - local fname = 'Xtest' + local fname = 'Xtest_functional_vimscript_system_nuls' before_each(create_file_with_nuls(fname)) after_each(delete_file(fname)) @@ -549,7 +549,7 @@ describe('systemlist()', function() end) describe('with output containing NULs', function() - local fname = 'Xtest' + local fname = 'Xtest_functional_vimscript_systemlist_nuls' before_each(function() command('set ff=unix') -- cgit From 1355861b926a05e411ba3d42fa85a2fe238aea8d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Apr 2023 17:44:08 +0800 Subject: fix(typval): don't treat v:null as truthy (#23281) --- test/functional/vimscript/special_vars_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/special_vars_spec.lua b/test/functional/vimscript/special_vars_spec.lua index 14ccbc3827..217f0b2c2b 100644 --- a/test/functional/vimscript/special_vars_spec.lua +++ b/test/functional/vimscript/special_vars_spec.lua @@ -130,6 +130,12 @@ describe('Special values', function() eq("v:false", eval('"" . v:false')) end) + it('work with ?? (falsy operator)', function() + eq(true, eval('v:true ?? 42')) + eq(42, eval('v:false ?? 42')) + eq(42, eval('v:null ?? 42')) + end) + it('work with type()', function() eq(6, funcs.type(true)) eq(6, funcs.type(false)) -- cgit From ac9f8669a8e4bd0cf13468d316d1746be65d3cdc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 25 Apr 2023 23:19:00 +0800 Subject: vim-patch:9.0.0875: using freed memory when executing delfunc at more prompt (#23314) Problem: Using freed memory when executing delfunc at the more prompt. Solution: Check function list not changed in another place. (closes vim/vim#11437) https://github.com/vim/vim/commit/398a26f7fcd58fbc6e2329f892edbb7479a971bb Co-authored-by: Bram Moolenaar --- test/functional/vimscript/eval_spec.lua | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 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 b411b1e379..b3f2c1bfeb 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -191,11 +191,10 @@ describe('listing functions using :function', function() 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, [=[ + matches('Vim%(function%):E454: Function list was modified$', pcall_err(exec_lua, [=[ vim.cmd([[ func Func1() endfunc @@ -219,6 +218,34 @@ describe('listing functions using :function', function() ]=])) assert_alive() end) + + it('does not crash if the same 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 Func2') + end + end) + + vim.cmd('function') + + vim.ui_detach(ns) + ]=])) + assert_alive() + end) end) it('no double-free in garbage collection #16287', function() -- cgit From d321deb4a9b05e9d81b79ac166274f4a6e7981bf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Apr 2023 15:51:44 +0800 Subject: test: fix dependencies between test cases (#23343) Discovered using --shuffle argument of busted. --- test/functional/vimscript/environ_spec.lua | 2 ++ test/functional/vimscript/executable_spec.lua | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/environ_spec.lua b/test/functional/vimscript/environ_spec.lua index 9e19568249..52218d3cc9 100644 --- a/test/functional/vimscript/environ_spec.lua +++ b/test/functional/vimscript/environ_spec.lua @@ -26,6 +26,8 @@ end) describe('empty $HOME', function() local original_home = os.getenv('HOME') + before_each(clear) + -- recover $HOME after each test after_each(function() if original_home ~= nil then diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index 43e4a29e1a..2b8e3f6218 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -137,12 +137,16 @@ describe('executable() (Windows)', function() end) it('system([…]), jobstart([…]) use $PATHEXT #9569', function() + -- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd". + clear({env={PATHEXT=''}}) -- Invoking `cmdscript` should find/execute `cmdscript.cmd`. eq('much success\n', call('system', {'test/functional/fixtures/cmdscript'})) assert(0 < call('jobstart', {'test/functional/fixtures/cmdscript'})) end) it('full path with extension', function() + -- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd". + clear({env={PATHEXT=''}}) -- Some executable we can expect in the test env. local exe = 'printargs-test' local exedir = eval("fnamemodify(v:progpath, ':h')") @@ -153,6 +157,8 @@ describe('executable() (Windows)', function() end) it('full path without extension', function() + -- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd". + clear({env={PATHEXT=''}}) -- Some executable we can expect in the test env. local exe = 'printargs-test' local exedir = eval("fnamemodify(v:progpath, ':h')") -- cgit From 75119fcc86e055895af824f7fdbba2f42c1cbbe8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:02:43 +0800 Subject: vim-patch:8.2.3135: Vim9: builtin function arguments not checked at compile time Problem: Vim9: builtin function arguments not checked at compile time. Solution: Add more type checks. (Yegappan Lakshmanan, closes vim/vim#8539) https://github.com/vim/vim/commit/5b73992d8f82be7ac4b6f46c17f53ffb9640e5fa Co-authored-by: Yegappan Lakshmanan --- test/functional/vimscript/execute_spec.lua | 10 +++++----- test/functional/vimscript/input_spec.lua | 30 ++++++++++++++-------------- test/functional/vimscript/writefile_spec.lua | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index 5fe3d787cb..b9893a5150 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -95,15 +95,15 @@ describe('execute()', function() ret = exc_exec('call execute(0.0)') eq('Vim(call):E806: using Float as a String', ret) ret = exc_exec('call execute(v:_null_dict)') - eq('Vim(call):E731: using Dictionary as a String', ret) + eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(function("tr"))') - eq('Vim(call):E729: using Funcref as a String', ret) + eq('Vim(call):E729: Using a Funcref as a String', ret) ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])') eq('Vim:E806: using Float as a String', ret) ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])') - eq('Vim:E731: using Dictionary as a String', ret) + eq('Vim:E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])') - eq('Vim:E729: using Funcref as a String', ret) + eq('Vim:E729: Using a Funcref as a String', ret) end) it('captures output with highlights', function() @@ -325,7 +325,7 @@ describe('execute()', function() eq('Vim(call):E806: using Float as a String', ret) ret = exc_exec('call execute(v:_null_dict, "silent")') - eq('Vim(call):E731: using Dictionary as a String', ret) + eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute("echo add(1, 1)", "")') eq('Vim(echo):E897: List or Blob required', ret) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index f50b39c2c5..d1643a799a 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -222,17 +222,17 @@ describe('input()', function() eq('DEF2', meths.get_var('var')) end) it('errors out on invalid inputs', function() - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", "", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"prompt": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"default": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"completion": []})')) eq('Vim(call):E5050: {opts} must be the only argument', exc_exec('call input({}, "default")')) @@ -418,17 +418,17 @@ describe('inputdialog()', function() eq('DEF2', meths.get_var('var')) end) it('errors out on invalid inputs', function() - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", "", [])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"prompt": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"default": []})')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"completion": []})')) eq('Vim(call):E5050: {opts} must be the only argument', exc_exec('call inputdialog({}, "default")')) @@ -512,13 +512,13 @@ describe('confirm()', function() eq(1, meths.get_var('a')) end - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm([])')) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a 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', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", 0, [])')) end) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index c816efd37b..3cd1052968 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -147,11 +147,11 @@ describe('writefile()', function() for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do eq('Vim(call):E806: using Float as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) - eq('Vim(call):E730: using List as a String', + eq('Vim(call):E730: Using a List as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) - eq('Vim(call):E731: using Dictionary as a String', + eq('Vim(call):E731: Using a Dictionary as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('{}')))) - eq('Vim(call):E729: using Funcref as a String', + eq('Vim(call):E729: Using a Funcref as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")')))) end eq('Vim(call):E5060: Unknown flag: «»', -- 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/vimscript/execute_spec.lua | 6 +++--- test/functional/vimscript/map_functions_spec.lua | 4 ++-- test/functional/vimscript/null_spec.lua | 4 ++-- test/functional/vimscript/writefile_spec.lua | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index b9893a5150..bf86f1623e 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -93,13 +93,13 @@ describe('execute()', function() it('captures errors', function() local ret ret = exc_exec('call execute(0.0)') - eq('Vim(call):E806: using Float as a String', ret) + eq('Vim(call):E806: Using Float as a String', ret) ret = exc_exec('call execute(v:_null_dict)') eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(function("tr"))') eq('Vim(call):E729: Using a Funcref as a String', ret) ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])') - eq('Vim:E806: using Float as a String', ret) + eq('Vim:E806: Using Float as a String', ret) ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])') eq('Vim:E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])') @@ -322,7 +322,7 @@ describe('execute()', function() it('propagates errors for "" and "silent"', function() local ret ret = exc_exec('call execute(0.0, "")') - eq('Vim(call):E806: using Float as a String', ret) + eq('Vim(call):E806: Using Float as a String', ret) ret = exc_exec('call execute(v:_null_dict, "silent")') eq('Vim(call):E731: Using a Dictionary as a String', ret) diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index ba1b4d7a76..2c8fe69428 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('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('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) diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index 1153baac46..4ba5dd6b45 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -65,7 +65,7 @@ describe('NULL', function() -- Correct behaviour null_expr_test('can be indexed with error message for empty list', 'L[0]', - 'E684: list index out of range: 0', nil) + 'E684: List index out of range: 0', nil) 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) @@ -80,7 +80,7 @@ describe('NULL', function() null_expr_test('can be copied', 'copy(L)', 0, {}) null_expr_test('can be deepcopied', 'deepcopy(L)', 0, {}) null_expr_test('does not crash when indexed', 'L[1]', - 'E684: list index out of range: 1', nil) + 'E684: List index out of range: 1', nil) null_expr_test('does not crash call()', 'call("arglistid", L)', 0, 0) null_expr_test('does not crash col()', 'col(L)', 0, 0) null_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 3cd1052968..da06671fe5 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -145,7 +145,7 @@ describe('writefile()', function() pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname))) end for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do - eq('Vim(call):E806: using Float as a String', + eq('Vim(call):E806: Using Float as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) eq('Vim(call):E730: Using a List as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) -- cgit From bdaaf2e8e113f8c32c70f83b60e0bf3f648357c1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 09:00:35 +0800 Subject: vim-patch:9.0.0250: slightly inconsistent error messages Problem: Slightly inconsistent error messages. Solution: Make it "Using a Float". (closes vim/vim#10959) https://github.com/vim/vim/commit/dde77a7c4d72622284dc5fb72557bde42c314fa6 Co-authored-by: Bram Moolenaar --- test/functional/vimscript/execute_spec.lua | 6 +++--- test/functional/vimscript/writefile_spec.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index bf86f1623e..17edf5c93e 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -93,13 +93,13 @@ describe('execute()', function() it('captures errors', function() local ret ret = exc_exec('call execute(0.0)') - eq('Vim(call):E806: Using Float as a String', ret) + eq('Vim(call):E806: Using a Float as a String', ret) ret = exc_exec('call execute(v:_null_dict)') eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(function("tr"))') eq('Vim(call):E729: Using a Funcref as a String', ret) ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])') - eq('Vim:E806: Using Float as a String', ret) + eq('Vim:E806: Using a Float as a String', ret) ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])') eq('Vim:E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])') @@ -322,7 +322,7 @@ describe('execute()', function() it('propagates errors for "" and "silent"', function() local ret ret = exc_exec('call execute(0.0, "")') - eq('Vim(call):E806: Using Float as a String', ret) + eq('Vim(call):E806: Using a Float as a String', ret) ret = exc_exec('call execute(v:_null_dict, "silent")') eq('Vim(call):E731: Using a Dictionary as a String', ret) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index da06671fe5..521a4eb2b1 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -145,7 +145,7 @@ describe('writefile()', function() pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname))) end for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do - eq('Vim(call):E806: Using Float as a String', + eq('Vim(call):E806: Using a Float as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) eq('Vim(call):E730: Using a List as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) -- cgit From 3a1e17e3a1767b4ff8a082150f7f9d6bda50cc8f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 19:03:08 +0800 Subject: test: add tests for executing commands with backwards range --- test/functional/vimscript/execute_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index 17edf5c93e..a9a4ad4811 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -4,6 +4,7 @@ local eval = helpers.eval local clear = helpers.clear local source = helpers.source local exc_exec = helpers.exc_exec +local pcall_err = helpers.pcall_err local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local command = helpers.command @@ -284,6 +285,14 @@ describe('execute()', function() eq('42', eval('g:mes')) end) + it('gives E493 instead of prompting on backwards range for ""', function() + command('split') + eq('Vim(windo):E493: Backwards range given: 2,1windo echo', + pcall_err(funcs.execute, '2,1windo echo', '')) + eq('Vim(windo):E493: Backwards range given: 2,1windo echo', + pcall_err(funcs.execute, {'2,1windo echo'}, '')) + end) + it('captures but does not display output for "silent"', function() local screen = Screen.new(40, 5) screen:attach() -- 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/vimscript/api_functions_spec.lua | 4 ++-- test/functional/vimscript/buf_functions_spec.lua | 22 +++++++++++----------- test/functional/vimscript/input_spec.lua | 4 ++-- test/functional/vimscript/json_functions_spec.lua | 2 +- test/functional/vimscript/system_spec.lua | 4 ++-- 5 files changed, 18 insertions(+), 18 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 dc591c3e0d..3404b06a55 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -32,8 +32,8 @@ describe('eval-API', function() local err = exc_exec('call nvim_get_current_buf("foo")') eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err) - err = exc_exec('call nvim_set_option("hlsearch")') - eq('Vim(call):E119: Not enough arguments for function: nvim_set_option', err) + err = exc_exec('call nvim_set_option_value("hlsearch")') + eq('Vim(call):E119: Not enough arguments for function: nvim_set_option_value', err) err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])') eq('Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', err) diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index 7a54f479e0..2d6d4b8e04 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -9,7 +9,6 @@ local meths = helpers.meths local command = helpers.command local exc_exec = helpers.exc_exec local bufmeths = helpers.bufmeths -local winmeths = helpers.winmeths local curbufmeths = helpers.curbufmeths local curwinmeths = helpers.curwinmeths local curtabmeths = helpers.curtabmeths @@ -189,7 +188,7 @@ describe('getbufline() function', function() eq({}, funcs.getbufline(1, -1, 9999)) end) it('returns expected lines', function() - meths.set_option('hidden', true) + meths.set_option_value('hidden', true, {}) command('file ' .. fname) curbufmeths.set_lines(0, 1, false, {'foo\0', '\0bar', 'baz'}) command('edit ' .. fname2) @@ -269,24 +268,25 @@ describe('setbufvar() function', function() end) it('may set options, including window-local and global values', function() local buf1 = meths.get_current_buf() - eq(false, curwinmeths.get_option('number')) + eq(false, meths.get_option_value('number', {win=0})) command('split') command('new') eq(2, bufmeths.get_number(curwinmeths.get_buf())) funcs.setbufvar(1, '&number', true) local windows = curtabmeths.list_wins() - eq(false, winmeths.get_option(windows[1], 'number')) - eq(true, winmeths.get_option(windows[2], 'number')) - eq(false, winmeths.get_option(windows[3], 'number')) - eq(false, winmeths.get_option(meths.get_current_win(), 'number')) + eq(false, meths.get_option_value('number', {win=windows[1].id})) + eq(true, meths.get_option_value('number', {win=windows[2].id})) + eq(false, meths.get_option_value('number', {win=windows[3].id})) + eq(false, meths.get_option_value('number', {win=meths.get_current_win().id})) - eq(true, meths.get_option('hidden')) + + eq(true, meths.get_option_value('hidden', {})) funcs.setbufvar(1, '&hidden', 0) - eq(false, meths.get_option('hidden')) + eq(false, meths.get_option_value('hidden', {})) - eq(false, bufmeths.get_option(buf1, 'autoindent')) + eq(false, meths.get_option_value('autoindent', {buf=buf1.id})) funcs.setbufvar(1, '&autoindent', true) - eq(true, bufmeths.get_option(buf1, 'autoindent')) + eq(true, meths.get_option_value('autoindent', {buf=buf1.id})) eq('Vim(call):E355: Unknown option: xxx', exc_exec('call setbufvar(1, "&xxx", 0)')) end) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index d1643a799a..bd9f7e5381 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -452,8 +452,8 @@ end) describe('confirm()', function() -- oldtest: Test_confirm() it('works', function() - meths.set_option('more', false) -- Avoid hit-enter prompt - meths.set_option('laststatus', 2) + meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt + meths.set_option_value('laststatus', 2, {}) -- screen:expect() calls are needed to avoid feeding input too early screen:expect({any = '%[No Name%]'}) diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua index 70d0934756..a9dab8431c 100644 --- a/test/functional/vimscript/json_functions_spec.lua +++ b/test/functional/vimscript/json_functions_spec.lua @@ -754,7 +754,7 @@ describe('json_encode() function', function() end) it('ignores improper values in &isprint', function() - meths.set_option('isprint', '1') + meths.set_option_value('isprint', '1', {}) eq(1, eval('"\1" =~# "\\\\p"')) eq('"\\u0001"', funcs.json_encode('\1')) end) diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index 130d5d81fa..762e8877ce 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -210,8 +210,8 @@ describe('system()', function() end) it('prints verbose information', function() - nvim('set_option', 'shell', 'fake_shell') - nvim('set_option', 'shellcmdflag', 'cmdflag') + nvim('set_option_value', 'shell', 'fake_shell', {}) + nvim('set_option_value', 'shellcmdflag', 'cmdflag', {}) screen:try_resize(72, 14) feed(':4verbose echo system("echo hi")') -- 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/vimscript/buf_functions_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index 2d6d4b8e04..2a5720fbd7 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -268,7 +268,7 @@ describe('setbufvar() function', function() end) it('may set options, including window-local and global values', function() local buf1 = meths.get_current_buf() - eq(false, meths.get_option_value('number', {win=0})) + eq(false, meths.get_option_value('number', {})) command('split') command('new') eq(2, bufmeths.get_number(curwinmeths.get_buf())) -- cgit From 55f6a1cab031ecc28c5a7f2558a0cac9df2145e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 May 2023 07:18:12 +0800 Subject: vim-patch:9.0.1588: Incsearch not triggered when pasting clipboard register (#23817) Problem: Incsearch not triggered when pasting clipboard register on the command line. Solution: Also set "literally" when using a clipboard register. (Ken Takata, closes vim/vim#12460) https://github.com/vim/vim/commit/9cf6ab133227ac7e9169941752293bb7178d8e38 Co-authored-by: K.Takata --- test/functional/vimscript/api_functions_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 3404b06a55..14678a966d 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -133,7 +133,7 @@ describe('eval-API', function() }) command("set ft=vim") - command("let &rtp='build/runtime/,'.&rtp") + command("set rtp^=build/runtime/") command("syntax on") insert([[ call bufnr('%') -- cgit From 7955c90621bb679f9c16b6788fbcb6145739886f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Jun 2023 06:58:44 +0800 Subject: fix(plines): folded lines with virt_lines attached to line above --- test/functional/vimscript/screenpos_spec.lua | 50 ++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/screenpos_spec.lua b/test/functional/vimscript/screenpos_spec.lua index 75e5c02298..8b8276457d 100644 --- a/test/functional/vimscript/screenpos_spec.lua +++ b/test/functional/vimscript/screenpos_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, meths = helpers.clear, helpers.eq, helpers.meths local command, funcs = helpers.command, helpers.funcs +local feed = helpers.feed before_each(clear) describe('screenpos() function', function() it('works in floating window with border', function() - local bufnr = meths.create_buf(false, true) local opts = { relative='editor', height=8, @@ -18,34 +18,56 @@ describe('screenpos() function', function() border='none', focusable=1 } - local float = meths.open_win(bufnr, false, opts) + local float = meths.open_win(meths.create_buf(false, true), false, opts) command('redraw') - local pos = funcs.screenpos(bufnr, 1, 1) - eq(7, pos.row) - eq(9, pos.col) + eq({row = 7, col = 9, endcol = 9, curscol = 9}, funcs.screenpos(float, 1, 1)) -- only left border opts.border = {'', '', '', '', '', '', '', '|'} meths.win_set_config(float, opts) command('redraw') - pos = funcs.screenpos(bufnr, 1, 1) - eq(7, pos.row) - eq(10, pos.col) + eq({row = 7, col = 10, endcol = 10, curscol = 10}, funcs.screenpos(float, 1, 1)) -- only top border opts.border = {'', '_', '', '', '', '', '', ''} meths.win_set_config(float, opts) command('redraw') - pos = funcs.screenpos(bufnr, 1, 1) - eq(8, pos.row) - eq(9, pos.col) + eq({row = 8, col = 9, endcol = 9, curscol = 9}, funcs.screenpos(float, 1, 1)) -- both left and top border opts.border = 'single' meths.win_set_config(float, opts) command('redraw') - pos = funcs.screenpos(bufnr, 1, 1) - eq(8, pos.row) - eq(10, pos.col) + eq({row = 8, col = 10, endcol = 10, curscol = 10}, funcs.screenpos(float, 1, 1)) + end) + + it('works for folded line with virt_lines attached to line above', function() + meths.buf_set_lines(0, 0, -1, true, {'aaa', 'bbb', 'ccc', 'ddd'}) + local ns = meths.create_namespace('') + meths.buf_set_extmark(0, ns, 0, 0, { virt_lines = {{{'abb'}}, {{'acc'}}, {{'add'}}} }) + command('2,3fold') + eq({row = 5, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1)) + eq({row = 5, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1)) + eq({row = 6, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1)) + + feed('') + eq({row = 4, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1)) + eq({row = 4, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1)) + eq({row = 5, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1)) + + feed('') + eq({row = 3, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1)) + eq({row = 3, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1)) + eq({row = 4, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1)) + + feed('') + eq({row = 2, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1)) + eq({row = 2, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1)) + eq({row = 3, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1)) + + feed('') + eq({row = 1, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 2, 1)) + eq({row = 1, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 3, 1)) + eq({row = 2, col = 1, endcol = 1, curscol = 1}, funcs.screenpos(0, 4, 1)) end) end) -- cgit From 7abfb1f86e25efcbe6ec31c8d3f196a60d718123 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Jun 2023 12:48:14 +0800 Subject: vim-patch:8.2.2949: tests failing because no error for float to string conversion Problem: Tests failing because there is no error for float to string conversion. Solution: Change the check for failure to check for correct result. Make some conversions strict in Vim9 script. https://github.com/vim/vim/commit/3cfa5b16b06bcc034f6de77070fa779d698ab5e9 Co-authored-by: Bram Moolenaar --- test/functional/vimscript/execute_spec.lua | 7 ------- test/functional/vimscript/writefile_spec.lua | 2 -- 2 files changed, 9 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index a9a4ad4811..bb28938708 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -93,14 +93,10 @@ describe('execute()', function() it('captures errors', function() local ret - ret = exc_exec('call execute(0.0)') - eq('Vim(call):E806: Using a Float as a String', ret) ret = exc_exec('call execute(v:_null_dict)') eq('Vim(call):E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(function("tr"))') eq('Vim(call):E729: Using a Funcref as a String', ret) - ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])') - eq('Vim:E806: Using a Float as a String', ret) ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])') eq('Vim:E731: Using a Dictionary as a String', ret) ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])') @@ -330,9 +326,6 @@ describe('execute()', function() it('propagates errors for "" and "silent"', function() local ret - ret = exc_exec('call execute(0.0, "")') - eq('Vim(call):E806: Using a Float as a String', ret) - ret = exc_exec('call execute(v:_null_dict, "silent")') eq('Vim(call):E731: Using a Dictionary as a String', ret) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 521a4eb2b1..88c19bd839 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -145,8 +145,6 @@ describe('writefile()', function() pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname))) end for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do - eq('Vim(call):E806: Using a Float as a String', - pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) eq('Vim(call):E730: Using a List as a String', pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) eq('Vim(call):E731: Using a Dictionary as a String', -- cgit From 1f8fb7c00048bc217bb9a2bf29c58630d1810d6e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 15 Jun 2023 12:36:21 +0800 Subject: fix(:let): fix error when applying operator to boolean option (#24030) --- test/functional/vimscript/let_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua index 164fa86452..11417c5846 100644 --- a/test/functional/vimscript/let_spec.lua +++ b/test/functional/vimscript/let_spec.lua @@ -92,6 +92,20 @@ describe(':let', function() ]]) eq(1, eval('1')) end) + + it('can apply operator to boolean option', function() + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways -= 1') + eq(false, meths.get_option_value('equalalways', {})) + command('let &equalalways += 1') + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways *= 1') + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways /= 1') + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways %= 1') + eq(false, meths.get_option_value('equalalways', {})) + end) end) describe(':let and :const', function() -- cgit From 2f17ef1fc4b96cf1106fd95ba090d34a2e4b977b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 22 Jun 2023 04:09:14 -0700 Subject: fix(messages): use "Vimscript" instead of "VimL" #24111 followup to #24109 fix #16150 --- test/functional/vimscript/input_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index bd9f7e5381..e1179d29cc 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -552,7 +552,7 @@ describe('confirm()', function() feed(':silent edit foo') check_and_clear(':silent edit foo |\n') - -- With API (via eval/VimL) call and shortmess+=F + -- With API (via eval/Vimscript) call and shortmess+=F feed(':call nvim_command("edit x")') check_and_clear(':call nvim_command("edit |\n') -- cgit From 77118d0da8badc4135be430f4cbb15bc95bc760f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 20 Apr 2023 21:17:25 +0100 Subject: fix(api): use text_locked() to check textlock Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in #22634 that made functions checking textlock usable in `` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK. --- test/functional/vimscript/api_functions_spec.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 14678a966d..683ae2446c 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -7,6 +7,7 @@ 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 +local feed = helpers.feed describe('eval-API', function() before_each(clear) @@ -48,10 +49,25 @@ describe('eval-API', function() eq('Vim(call):E5555: API call: Invalid buffer id: 17', err) end) - it('cannot change texts if textlocked', function() + it('cannot change text or window if textlocked', function() command("autocmd TextYankPost ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])") matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', pcall_err(command, "normal! yy")) + + -- Functions checking textlock should also not be usable from mappings. + command("inoremap nvim_win_close(0, 1)") + eq('Vim(normal):E5555: API call: E565: Not allowed to change text or change window', + pcall_err(command, [[execute "normal i\"]])) + + -- Some functions checking textlock (usually those that may change the current window or buffer) + -- also ought to not be usable in the cmdwin. + feed("q:") + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_hide, 0)) + + -- But others, like nvim_buf_set_lines(), which just changes text, is OK. + curbufmeths.set_lines(0, -1, 1, {"wow!"}) + eq({'wow!'}, curbufmeths.get_lines(0, -1, 1)) end) it("use buffer numbers and windows ids as handles", function() -- cgit From aa4e47f704c53ab1d825260d2bf34e2872e3ca89 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 23 Jun 2023 22:32:07 +0100 Subject: fix(api): disallow some more functions during textlock Problem: nvim_buf_set_text(), nvim_open_term() and termopen() all change buffer text, which is forbidden during textlock. Additionally, nvim_open_term() and termopen() may be used to convert the cmdwin buffer into a terminal buffer, which is weird. Solution: Allow nvim_buf_set_text() and nvim_open_term() in the cmdwin, but disallow nvim_open_term() from converting the cmdwin buffer into a terminal buffer. termopen() is not allowed in the cmdwin (as it always operates on curbuf), so just check text_locked(). Also happens to improve the error in #21055: nvim_buf_set_text() was callable during textlock, but happened to check textlock indirectly via u_save(); however, this caused the error to be overwritten by an unhelpful "Failed to save undo information" message when msg_list == NULL (e.g: an `` mapping invoked outside of do_cmdline()). --- test/functional/vimscript/api_functions_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 683ae2446c..6548548a9e 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -54,11 +54,23 @@ describe('eval-API', function() matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', pcall_err(command, "normal! yy")) + command("autocmd TextYankPost ++once call nvim_open_term(0, {})") + matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', + pcall_err(command, "normal! yy")) + -- Functions checking textlock should also not be usable from mappings. command("inoremap nvim_win_close(0, 1)") eq('Vim(normal):E5555: API call: E565: Not allowed to change text or change window', pcall_err(command, [[execute "normal i\"]])) + -- Text-changing functions gave a "Failed to save undo information" error when called from an + -- mapping outside do_cmdline() (msg_list == NULL), so use feed() to test this. + command("inoremap nvim_buf_set_text(0, 0, 0, 0, 0, ['hi'])") + meths.set_vvar('errmsg', '') + feed("i") + eq('E5555: API call: E565: Not allowed to change text or change window', + meths.get_vvar('errmsg')) + -- Some functions checking textlock (usually those that may change the current window or buffer) -- also ought to not be usable in the cmdwin. feed("q:") @@ -68,6 +80,15 @@ describe('eval-API', function() -- But others, like nvim_buf_set_lines(), which just changes text, is OK. curbufmeths.set_lines(0, -1, 1, {"wow!"}) eq({'wow!'}, curbufmeths.get_lines(0, -1, 1)) + + -- Turning the cmdwin buffer into a terminal buffer would be pretty weird. + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.open_term, 0, {})) + + -- But turning a different buffer into a terminal from the cmdwin is OK. + local term_buf = meths.create_buf(false, true) + meths.open_term(term_buf, {}) + eq('terminal', meths.get_option_value("buftype", {buf = term_buf})) end) it("use buffer numbers and windows ids as handles", function() -- cgit From 472271199e483d3f23d62c272b20c5290eec5474 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 24 Jul 2023 14:19:01 +0100 Subject: feat(api): allow win_hide to close cmdwin or non-previous windows This aligns its behaviour better with `nvim_win_close`. Note that `:hide` is actually incapable of closing the cmdwin, unlike `:close` and `:quit`, so this is a bit of a difference in behaviour. --- test/functional/vimscript/api_functions_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 6548548a9e..0a7e7c1137 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -73,9 +73,10 @@ describe('eval-API', function() -- Some functions checking textlock (usually those that may change the current window or buffer) -- also ought to not be usable in the cmdwin. + local old_win = meths.get_current_win() feed("q:") eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_hide, 0)) + pcall_err(meths.set_current_win, old_win)) -- But others, like nvim_buf_set_lines(), which just changes text, is OK. curbufmeths.set_lines(0, -1, 1, {"wow!"}) -- cgit From 6bf5b2428b146330688922d66438357c0568725d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 12:26:02 +0800 Subject: vim-patch:8.1.2066: no tests for state() Problem: No tests for state(). Solution: Add tests. Clean up some feature checks. Make "a" flag work. https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c Co-authored-by: Bram Moolenaar --- test/functional/vimscript/state_spec.lua | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/functional/vimscript/state_spec.lua (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua new file mode 100644 index 0000000000..dcff3c8d7e --- /dev/null +++ b/test/functional/vimscript/state_spec.lua @@ -0,0 +1,69 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eq = helpers.eq +local exec = helpers.exec +local exec_lua = helpers.exec_lua +local feed = helpers.feed +local meths = helpers.meths +local poke_eventloop = helpers.poke_eventloop + +before_each(clear) + +describe('state() function', function() + it('works', function() + meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt + + exec_lua([[ + function _G.Get_state_mode() + _G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) } + end + + function _G.Run_timer() + local timer = vim.uv.new_timer() + timer:start(0, 0, function() + _G.Get_state_mode() + timer:close() + end) + end + ]]) + exec([[ + call setline(1, ['one', 'two', 'three']) + map ;; gg + func RunTimer() + call timer_start(0, {id -> v:lua.Get_state_mode()}) + endfunc + au Filetype foobar call v:lua.Get_state_mode() + ]]) + + -- Using a ":" command Vim is busy, thus "S" is returned + feed([[:call v:lua.Get_state_mode()]]) + eq({ 'S', 'n' }, exec_lua('return _G.res')) + + -- Using a timer callback + feed([[:call RunTimer()]]) + poke_eventloop() -- Allow polling for events + eq({ 'c', 'n' }, exec_lua('return _G.res')) + + -- Halfway a mapping + feed([[:call v:lua.Run_timer();]]) + meths.get_mode() -- Allow polling for fast events + feed(';') + eq({ 'mS', 'n' }, exec_lua('return _G.res')) + + -- Insert mode completion + feed([[:call RunTimer()Got]]) + poke_eventloop() -- Allow polling for events + feed('') + eq({ 'aSc', 'i' }, exec_lua('return _G.res')) + + -- Autocommand executing + feed([[:set filetype=foobar]]) + eq({ 'xS', 'n' }, exec_lua('return _G.res')) + + -- messages scrolled + feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"]]) + meths.get_mode() -- Allow polling for fast events + feed('') + eq({ 'Ss', 'r' }, exec_lua('return _G.res')) + end) +end) -- cgit From 71acb7104344e3631e995b973416776aeadda0e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 13:21:28 +0800 Subject: vim-patch:8.1.2099: state() test fails on some Mac systems Problem: state() test fails on some Mac systems. Solution: Increase the wait time. (closes vim/vim#4983) https://github.com/vim/vim/commit/b7a97ef340f03ca08df8c8e00cd5580f61aac824 Co-authored-by: Bram Moolenaar --- test/functional/vimscript/state_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index dcff3c8d7e..fd38a8ad5b 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -29,6 +29,7 @@ describe('state() function', function() exec([[ call setline(1, ['one', 'two', 'three']) map ;; gg + set complete=. func RunTimer() call timer_start(0, {id -> v:lua.Get_state_mode()}) endfunc @@ -51,7 +52,7 @@ describe('state() function', function() eq({ 'mS', 'n' }, exec_lua('return _G.res')) -- Insert mode completion - feed([[:call RunTimer()Got]]) + feed([[:call RunTimer()Got]]) poke_eventloop() -- Allow polling for events feed('') eq({ 'aSc', 'i' }, exec_lua('return _G.res')) -- cgit From 6aa29d0f01e715fe51de4f66dee377e4c1726229 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 13:45:26 +0800 Subject: test: add some tests for SafeState autocommand --- test/functional/vimscript/state_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index fd38a8ad5b..70f68a7494 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -17,7 +17,6 @@ describe('state() function', function() function _G.Get_state_mode() _G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) } end - function _G.Run_timer() local timer = vim.uv.new_timer() timer:start(0, 0, function() -- cgit From 20f76ebf2b5aec799b0f90e5e892a4b88597d427 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Aug 2023 00:00:57 +0800 Subject: test: fix state() test flakiness (#24839) --- test/functional/vimscript/state_spec.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index 70f68a7494..1acfb1337d 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -41,18 +41,20 @@ describe('state() function', function() -- Using a timer callback feed([[:call RunTimer()]]) - poke_eventloop() -- Allow polling for events + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event eq({ 'c', 'n' }, exec_lua('return _G.res')) -- Halfway a mapping feed([[:call v:lua.Run_timer();]]) - meths.get_mode() -- Allow polling for fast events + meths.get_mode() -- Process pending input and luv timer callback feed(';') eq({ 'mS', 'n' }, exec_lua('return _G.res')) -- Insert mode completion feed([[:call RunTimer()Got]]) - poke_eventloop() -- Allow polling for events + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event feed('') eq({ 'aSc', 'i' }, exec_lua('return _G.res')) @@ -62,7 +64,7 @@ describe('state() function', function() -- messages scrolled feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"]]) - meths.get_mode() -- Allow polling for fast events + meths.get_mode() -- Process pending input and luv timer callback feed('') eq({ 'Ss', 'r' }, exec_lua('return _G.res')) end) -- cgit From 6462ee1c10f9f1aa66ffc4d4fe1b7b3d9f0f91af Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Aug 2023 06:42:10 +0800 Subject: vim-patch:9.0.1779: Need more state() tests (#24840) Problem: Need more state() tests Solution: Add a few more tests for operater pending mode and register yank command closes: vim/vim#12883 https://github.com/vim/vim/commit/8dabccd295271104ad5af0abc48e283d644cff59 --- test/functional/vimscript/state_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index 1acfb1337d..0508b8b1da 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -10,6 +10,7 @@ local poke_eventloop = helpers.poke_eventloop before_each(clear) describe('state() function', function() + -- oldtest: Test_state() it('works', function() meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt @@ -51,6 +52,20 @@ describe('state() function', function() feed(';') eq({ 'mS', 'n' }, exec_lua('return _G.res')) + -- An operator is pending + feed([[:call RunTimer()y]]) + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event + feed('y') + eq({ 'oSc', 'n' }, exec_lua('return _G.res')) + + -- A register was specified + feed([[:call RunTimer()"r]]) + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event + feed('yy') + eq({ 'oSc', 'n' }, exec_lua('return _G.res')) + -- Insert mode completion feed([[:call RunTimer()Got]]) poke_eventloop() -- Process pending input -- cgit From f859d16aea0d58e572edc9aaf1de3542569e10a9 Mon Sep 17 00:00:00 2001 From: Sergey Slipchenko Date: Mon, 11 Sep 2023 21:01:00 +0400 Subject: fix(tests): set SHELL=sh #24941 Problem: Some tests fail with $SHELL=fish #6172 Related: https://github.com/neovim/neovim/pull/6176 Solution: Replace "echo -n" with "printf", because "echo" in sh may be provided as a shell builtin, which does not accept an "-n" flag to avoid a trailing newline (e.g. on macos). "printf" is more portable (defined by POSIX) and it does not output a trailing newline by itself. Fixes #6172 TODO: Other test failures may be related to "session leader" issue: https://github.com/neovim/neovim/issues/2354 Checked by running `:terminal ./build/bin/tty-test` from Nvim with `shell=/bin/fish` (inherited from `$SHELL`) and it indeed complains about "process does not own the terminal". With `shell=sh` it doesn't complain. And unsetting `$SHELL` seems to make `nvim` to fall back to `shell=sh`. FAILED test/functional/terminal/tui_spec.lua @ 1017: TUI paste: terminal mode test/functional/terminal/tui_spec.lua:1024: Row 1 did not match. Expected: |*tty ready | |*{1: } | |* | | | |{5:^^^^^^^ }| |{3:-- TERMINAL --} | |{3:-- TERMINAL --} | Actual: |*process does not own the terminal | |* | |*[Process exited 2]{1: } | | | |{5:^^^^^^^ }| |{3:-- TERMINAL --} | |{3:-- TERMINAL --} | To print the expect() call that would assert the current screen state, use screen:snapshot_util(). In case of non-deterministic failures, use screen:redraw_debug() to show all intermediate screen states. stack traceback: test/functional/ui/screen.lua:622: in function '_wait' test/functional/ui/screen.lua:352: in function 'expect' test/functional/terminal/tui_spec.lua:1024: in function FAILED test/functional/terminal/tui_spec.lua @ 1551: TUI forwards :term palette colors with termguicolors test/functional/terminal/tui_spec.lua:1567: Row 1 did not match. Expected: |*{1:t}ty ready | | | |* | | | |{2:^^^^^^^ }| | | |{3:-- TERMINAL --} | Actual: |*{1:p}rocess does not own the terminal | | | |*[Process exited 2] | | | |{2:^^^^^^^ }| | | |{3:-- TERMINAL --} | To print the expect() call that would assert the current screen state, use screen:snapshot_util(). In case of non-deterministic failures, use screen:redraw_debug() to show all intermediate screen states. stack traceback: test/functional/ui/screen.lua:622: in function '_wait' test/functional/ui/screen.lua:352: in function 'expect' test/functional/terminal/tui_spec.lua:1567: in function --- 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 762e8877ce..90aab48d61 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -335,12 +335,12 @@ describe('system()', function() if is_os('win') then eq("echoed\n", eval('system("echo echoed")')) else - eq("echoed", eval('system("echo -n echoed")')) + eq("echoed", eval('system("printf echoed")')) end end) it('to backgrounded command does not crash', function() -- This is indeterminate, just exercise the codepath. May get E5677. - feed_command('call system(has("win32") ? "start /b /wait cmd /c echo echoed" : "echo -n echoed &")') + feed_command('call system(has("win32") ? "start /b /wait cmd /c echo echoed" : "printf echoed &")') local v_errnum = string.match(eval("v:errmsg"), "^E%d*:") if v_errnum then eq("E5677:", v_errnum) -- cgit From 9e7c4fe5791559ff2c9ffe6329f1d7e2150385ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Sep 2023 08:23:24 +0800 Subject: fix(exception): remember whether message is multiline (#25351) --- test/functional/vimscript/eval_spec.lua | 40 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index b3f2c1bfeb..ab0ffccd4d 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -153,11 +153,6 @@ 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"') @@ -173,10 +168,45 @@ describe("uncaught exception", function() let result ..= 'X' ]]):format(i, i)) end + finally(function() + for i = 1, 3 do + os.remove('throw' .. i .. '.vim') + end + end) + command('set runtimepath+=. | let result = ""') eq('throw1', exc_exec('try | runtime! throw*.vim | endtry')) eq('123', eval('result')) end) + + it('multiline exception remains multiline #25350', function() + local screen = Screen.new(80, 11) + screen:set_default_attr_ids({ + [1] = {bold = true, reverse = true}; -- MsgSeparator + [2] = {foreground = Screen.colors.White, background = Screen.colors.Red}; -- ErrorMsg + [3] = {bold = true, foreground = Screen.colors.SeaGreen}; -- MoreMsg + }) + screen:attach() + exec_lua([[ + function _G.Oops() + error("oops") + end + ]]) + feed(':try\rlua _G.Oops()\rendtry\r') + screen:expect{grid=[[ + {1: }| + :try | + : lua _G.Oops() | + : endtry | + {2:Error detected while processing :} | + {2:E5108: Error executing lua [string ""]:2: oops} | + {2:stack traceback:} | + {2: [C]: in function 'error'} | + {2: [string ""]:2: in function 'Oops'} | + {2: [string ":lua"]:1: in main chunk} | + {3:Press ENTER or type command to continue}^ | + ]]} + end) end) describe('listing functions using :function', function() -- cgit From 3cbb02ce77087a820decd1a724a6e8b666e0ca36 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 12 Oct 2023 07:38:56 +0800 Subject: vim-patch:8.2.3064: Vim9: in script cannot set item in uninitialized list (#25605) Problem: Vim9: in script cannot set item in uninitialized list. Solution: When a list is NULL allocate an empty one. (closes vim/vim#8461) https://github.com/vim/vim/commit/e65081d1b591f16dc6e380a830d87565c5eb7b03 Co-authored-by: Bram Moolenaar --- test/functional/vimscript/null_spec.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index 4ba5dd6b45..d4c36d835b 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -53,17 +53,13 @@ describe('NULL', function() end) end describe('list', function() - -- Incorrect behaviour - -- FIXME Should error out with different message - null_test('makes :unlet act as if it is not a list', ':unlet L[0]', - 'Vim(unlet):E689: Can only index a List, Dictionary or Blob') - -- Subjectable behaviour - null_expr_test('is equal to empty list', 'L == []', 0, 1) null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 1) -- Correct behaviour + null_test('can be :unlet item with error message for empty list', ':unlet L[0]', + 'Vim(unlet):E684: List index out of range: 0') null_expr_test('can be indexed with error message for empty list', 'L[0]', 'E684: List index out of range: 0', nil) null_expr_test('can be splice-indexed', 'L[:]', 0, {}) -- cgit From a4b80c71eae09a5f6f76bce46be46efd247c7223 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 15:17:53 +0800 Subject: vim-patch:8.2.4140: maparg() does not indicate the type of script Problem: maparg() does not indicate the type of script where it was defined. Solution: Add "scriptversion". https://github.com/vim/vim/commit/a9528b39a666dbaa026320f73bae4b1628a7fe51 Co-authored-by: Bram Moolenaar --- test/functional/vimscript/map_functions_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index 2c8fe69428..3f8bf24505 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -26,6 +26,7 @@ describe('maparg()', function() rhs='bar', expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, mode='n', @@ -157,8 +158,9 @@ describe('maparg()', function() mode = 'n', noremap = 1, nowait = 0, - script=0, + script = 0, sid = 0, + scriptversion = 1, silent = 0, lnum = 0, } -- cgit From f748a73a357710db6094d4a428cd056f5df226a9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 19:48:50 +0800 Subject: vim-patch:8.2.4861: it is not easy to restore saved mappings Problem: It is not easy to restore saved mappings. Solution: Make mapset() accept a dict argument. (Ernie Rael, closes vim/vim#10295) https://github.com/vim/vim/commit/51d04d16f21e19d6eded98f9530d84089102f925 Co-authored-by: Ernie Rael --- test/functional/vimscript/map_functions_spec.lua | 2 ++ 1 file changed, 2 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 3f8bf24505..14818d9141 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -30,6 +30,7 @@ describe('maparg()', function() buffer=0, nowait=0, mode='n', + abbr=0, noremap=1, lnum=0, } @@ -156,6 +157,7 @@ describe('maparg()', function() buffer = 0, expr = 0, mode = 'n', + abbr = 0, noremap = 1, nowait = 0, script = 0, -- cgit From 04d299c17014b0802c79613252e4de26da84a7c9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 20:42:55 +0800 Subject: vim-patch:8.2.4932: not easy to filter the output of maplist() Problem: Not easy to filter the output of maplist(). Solution: Add mode_bits to the dictionary. (Ernie Rael, closes vim/vim#10356) https://github.com/vim/vim/commit/d8f5f766219273a8579947cc80b92580b6988a4b Co-authored-by: Ernie Rael --- test/functional/vimscript/map_functions_spec.lua | 2 ++ 1 file changed, 2 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 14818d9141..acba5e9708 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -30,6 +30,7 @@ describe('maparg()', function() buffer=0, nowait=0, mode='n', + mode_bits=0x01, abbr=0, noremap=1, lnum=0, @@ -157,6 +158,7 @@ describe('maparg()', function() buffer = 0, expr = 0, mode = 'n', + mode_bits = 0x01, abbr = 0, noremap = 1, nowait = 0, -- cgit From e9b9a86cd5a555943b87f0ba40c4527561c3c124 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Nov 2023 10:21:14 +0800 Subject: fix(context): don't crash on invalid arg to nvim_get_context (#25977) Note: The crash happens in the second test case when using uninitialized memory, and therefore doesn't happen with ASAN. --- test/functional/vimscript/ctx_functions_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index 5ee84a6d13..66a8ec3550 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -375,6 +375,12 @@ describe('context functions', function() eq(outofbounds, pcall_err(call, 'ctxset', {dummy = 1}, 0)) end) + it('errors when context dictionary is invalid', function() + call('ctxpush') + eq('Vim:E474: Failed to convert list to msgpack string buffer', + pcall_err(call, 'ctxset', { regs = { {} } })) + end) + it('sets context dictionary at index in context stack', function() nvim('set_var', 'one', 1) nvim('set_var', 'Two', 2) -- cgit From fdaf6bc5573f578d100321dfc084d513884fd73a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Nov 2023 13:10:26 +0800 Subject: fix(context): don't leak memory on multiple invalid objects (#25979) --- test/functional/vimscript/ctx_functions_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index 66a8ec3550..17607f0794 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -378,7 +378,7 @@ describe('context functions', function() it('errors when context dictionary is invalid', function() call('ctxpush') eq('Vim:E474: Failed to convert list to msgpack string buffer', - pcall_err(call, 'ctxset', { regs = { {} } })) + pcall_err(call, 'ctxset', { regs = { {} }, jumps = { {} } })) end) it('sets context dictionary at index in context stack', function() -- cgit