From 1b379ce4302e727e01daa051c047e97359ee34e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Feb 2023 19:48:17 +0800 Subject: test(exit_spec): make sure that autocommands are triggered (#22188) Previously, if the autocommands are not triggered, the tests may still pass because no assertion is done. Add an assertion so that the tests will fail if the autocommands aren't triggered. --- test/functional/core/exit_spec.lua | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 05a69e1992..dc4b45b4d9 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -25,30 +25,34 @@ describe('v:exiting', function() eq(1, eval('v:exiting is v:null')) end) - it('is 0 on normal exit', function() + local function test_exiting(setup_fn) local function on_setup() - command('autocmd VimLeavePre * call rpcrequest('..cid..', "")') - command('autocmd VimLeave * call rpcrequest('..cid..', "")') - command('quit') + command('autocmd VimLeavePre * call rpcrequest('..cid..', "exit", "VimLeavePre")') + command('autocmd VimLeave * call rpcrequest('..cid..', "exit", "VimLeave")') + setup_fn() end - local function on_request() + local requests_args = {} + local function on_request(name, args) + eq('exit', name) + table.insert(requests_args, args) eq(0, eval('v:exiting')) return '' end run(on_request, nil, on_setup) + eq({{'VimLeavePre'}, {'VimLeave'}}, requests_args) + end + + it('is 0 on normal exit', function() + test_exiting(function() + command('quit') + end) end) + it('is 0 on exit from Ex mode involving try-catch vim-patch:8.0.0184', function() - local function on_setup() - command('autocmd VimLeavePre * call rpcrequest('..cid..', "")') - command('autocmd VimLeave * call rpcrequest('..cid..', "")') + test_exiting(function() feed('gQ') feed_command('try', 'call NoFunction()', 'catch', 'echo "bye"', 'endtry', 'quit') - end - local function on_request() - eq(0, eval('v:exiting')) - return '' - end - run(on_request, nil, on_setup) + end) end) end) -- cgit From ce0fddf5ae334f0c79dcd95b379999e11df1486b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 9 Mar 2023 08:07:36 -0500 Subject: feat: try to recover from missing tempdir #22573 Problem: If vim_tempdir mysteriously goes missing (typically by "antivirus" on Windows), any plugins using tempname() will be broken for the rest of the session. #1432 #9833 https://groups.google.com/g/vim_use/c/ef55jNm5czI Steps: mkdir foo TMPDIR=./foo nvim :echo tempname() !rm -r foo :echo tempname() tempname() still uses the foo path even though it was deleted. Solution: - Don't assume that vim_tempdir exists. - If it goes missing once, retry vim_mktempdir and log (silently) an error. - If it goes missing again, retry vim_mktempdir and show an error. Rejected in Vim for performance reasons: https://groups.google.com/g/vim_use/c/qgRob9SWDv8/m/FAOFVVcDTv0J https://groups.google.com/g/vim_dev/c/cogp-Vye4oo/m/d_SVFXBbnnoJ But, logging shows that `vim_gettempdir` is not called frequently. Fixes #1432 Fixes #9833 Fixes #11250 Related: stdpath("run") f50135a32e11c535e1dc3a8e9460c5b4e640ee86 --- test/functional/core/fileio_spec.lua | 64 +++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 12 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 4e9891a4de..153b53dce2 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -15,6 +15,7 @@ local request = helpers.request local retry = helpers.retry local rmdir = helpers.rmdir local matches = helpers.matches +local meths = helpers.meths local mkdir = helpers.mkdir local sleep = helpers.sleep local read_file = helpers.read_file @@ -261,13 +262,13 @@ end) describe('tmpdir', function() local tmproot_pat = [=[.*[/\\]nvim%.[^/\\]+]=] local testlog = 'Xtest_tmpdir_log' - local faketmp + local os_tmpdir before_each(function() -- Fake /tmp dir so that we can mess it up. - faketmp = tmpname() - os.remove(faketmp) - mkdir(faketmp) + os_tmpdir = tmpname() + os.remove(os_tmpdir) + mkdir(os_tmpdir) end) after_each(function() @@ -275,16 +276,21 @@ describe('tmpdir', function() os.remove(testlog) end) - it('failure modes', function() - clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) - assert_nolog('tempdir is not a directory', testlog) - assert_nolog('tempdir has invalid permissions', testlog) - + local function get_tmproot() -- Tempfiles typically look like: "…/nvim./xxx/0". -- - "…/nvim./xxx/" is the per-process tmpdir, not shared with other Nvims. -- - "…/nvim./" is the tmpdir root, shared by all Nvims (normally). local tmproot = (funcs.tempname()):match(tmproot_pat) ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot) + return tmproot + end + + it('failure modes', function() + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) + assert_nolog('tempdir is not a directory', testlog) + assert_nolog('tempdir has invalid permissions', testlog) + + local tmproot = get_tmproot() -- Test how Nvim handles invalid tmpdir root (by hostile users or accidents). -- @@ -292,7 +298,7 @@ describe('tmpdir', function() expect_exit(command, ':qall!') rmdir(tmproot) write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. - clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. assert_log('tempdir root not a directory', testlog, 100) @@ -303,18 +309,52 @@ describe('tmpdir', function() os.remove(tmproot) mkdir(tmproot) funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. - clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. assert_log('tempdir root has invalid permissions', testlog, 100) end) it('too long', function() - local bigname = ('%s/%s'):format(faketmp, ('x'):rep(666)) + local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666)) mkdir(bigname) clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=bigname, } }) matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). local len = (funcs.tempname()):len() ok(len > 4 and len < 256, '4 < len < 256', tostring(len)) end) + + it('disappeared #1432', function() + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=os_tmpdir, } }) + assert_nolog('tempdir disappeared', testlog) + + local function rm_tmpdir() + local tmpname1 = funcs.tempname() + local tmpdir1 = funcs.fnamemodify(tmpname1, ':h') + eq(funcs.stdpath('run'), tmpdir1) + + rmdir(tmpdir1) + retry(nil, 1000, function() + eq(0, funcs.isdirectory(tmpdir1)) + end) + local tmpname2 = funcs.tempname() + local tmpdir2 = funcs.fnamemodify(tmpname2, ':h') + neq(tmpdir1, tmpdir2) + end + + -- Your antivirus hates you... + rm_tmpdir() + assert_log('tempdir disappeared', testlog, 100) + funcs.tempname() + funcs.tempname() + funcs.tempname() + eq('', meths.get_vvar('errmsg')) + rm_tmpdir() + funcs.tempname() + funcs.tempname() + funcs.tempname() + eq('E5431: tempdir disappeared (2 times)', meths.get_vvar('errmsg')) + rm_tmpdir() + eq('E5431: tempdir disappeared (3 times)', meths.get_vvar('errmsg')) + end) end) -- cgit From b466e1d289180fad212a93b173034787fd6be9a8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 13 Mar 2023 04:15:24 +0100 Subject: test: unskip working Windows tests (#22537) Some tests that were previously not working have started to work again for unspecified reasons, so let's enable them. --- test/functional/core/job_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 1bae626b98..613dff577a 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -88,7 +88,6 @@ describe('jobs', function() end) it('append environment with pty #env', function() - skip(is_os('win')) nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.pty = v:true") @@ -806,7 +805,6 @@ describe('jobs', function() end) it('can be called recursively', function() - skip(is_os('win'), "TODO: Need `cat`") source([[ let g:opts = {} let g:counter = 0 -- cgit From 3e8955094a615f2a805350050bc1703a294b1b85 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 14 Mar 2023 02:12:26 +0100 Subject: test: re-bundle cat on windows (#21255) The builtin cat was removed in 4bc9229ecbec514e9a87cfc4be88ea27a971e9a1 as it is not used during runtime but only for tests. However, it is a very small and useful utility program that we need for a lot of our tests, so there's no harm in bundling it, and it helps us avoid complicating our build system by having two versions of neovim (neovim for users and neovim for testing). Also skip tests if "grep" or "sleep" isn't available. --- test/functional/core/channels_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 8275575c24..5771ddcb94 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -230,6 +230,7 @@ describe('channels', function() end) it('can use buffered output mode', function() + skip(funcs.executable('grep') == 0, 'missing "grep" command') source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -262,6 +263,7 @@ describe('channels', function() end) it('can use buffered output mode with no stream callback', function() + skip(funcs.executable('grep') == 0, 'missing "grep" command') source([[ function! OnEvent(id, data, event) dict call rpcnotify(1, a:event, a:id, a:data, self.stdout) -- cgit From fe9cbcb3a5c82932ecfb8f49d07e98a1fc2b31e5 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sat, 25 Mar 2023 18:58:48 +0200 Subject: feat(api): nvim_exec2(), deprecate nvim_exec() #19032 Problem: The signature of nvim_exec() is not extensible per ":help api-contract". Solution: Introduce nvim_exec2() and deprecate nvim_exec(). --- test/functional/core/exit_spec.lua | 6 +++--- test/functional/core/remote_spec.lua | 4 ++-- test/functional/core/startup_spec.lua | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index dc4b45b4d9..d474b77806 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -93,14 +93,14 @@ describe(':cquit', function() end) it('exits with redir msg for multiple exit codes after :cquit 1 2', function() - test_cq('cquit 1 2', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2') + test_cq('cquit 1 2', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2') end) it('exits with redir msg for non-number exit code after :cquit X', function() - test_cq('cquit X', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: X: cquit X') + test_cq('cquit X', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: X: cquit X') end) it('exits with redir msg for negative exit code after :cquit -1', function() - test_cq('cquit -1', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: -1: cquit -1') + test_cq('cquit -1', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: -1: cquit -1') end) end) diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index 846d79abf3..b2a1679023 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -101,7 +101,7 @@ describe('Remote', function() expect(contents) eq(1, #funcs.getbufinfo()) -- Since we didn't pass silent, we should get a complaint - neq(nil, string.find(meths.exec('messages', true), 'E247')) + neq(nil, string.find(meths.exec2('messages', { output = true }).output, 'E247')) end) it('creates server if not found with tabs', function() @@ -110,7 +110,7 @@ describe('Remote', function() eq(2, #funcs.gettabinfo()) eq(2, #funcs.getbufinfo()) -- We passed silent, so no message should be issued about the server not being found - eq(nil, string.find(meths.exec('messages', true), 'E247')) + eq(nil, string.find(meths.exec2('messages', { output = true }).output, 'E247')) end) pending('exits with error on', function() diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index e9b47a0251..4ae8b1c95e 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -58,7 +58,7 @@ describe('startup', function() ^ | | Entering Debug mode. Type "cont" to continue. | - nvim_exec() | + nvim_exec2() | cmd: aunmenu * | > | | @@ -691,7 +691,6 @@ describe('sysinit', function() eq('loaded 1 xdg 0 vim 1', eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')) end) - end) describe('user config init', function() @@ -824,7 +823,7 @@ describe('user config init', function() clear{ args_rm={'-u'}, env=xenv } feed('') -- Dismiss "Conflicting config …" message. eq(1, eval('g:lua_rc')) - matches('^E5422: Conflicting configs', meths.exec('messages', true)) + matches('^E5422: Conflicting configs', meths.exec2('messages', { output = true }).output) end) end) end) @@ -873,7 +872,7 @@ describe('runtime:', function() eq(2, eval('g:lua_plugin')) -- Check if plugin_file_path is listed in :scriptname - local scripts = meths.exec(':scriptnames', true) + local scripts = meths.exec2(':scriptnames', { output = true }).output assert(scripts:find(plugin_file_path)) -- Check if plugin_file_path is listed in startup profile -- cgit From 4863ca6b8902c5b0aab95f2af640118cd417d379 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Mar 2023 10:49:32 +0800 Subject: test: use exec_capture() in more places (#22787) Problem: Using `meths.exec2("code", { output = true })` is too verbose. Solution: Use exec_capture() in more places. --- test/functional/core/remote_spec.lua | 6 +++--- test/functional/core/startup_spec.lua | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index b2a1679023..f74bb65553 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -3,11 +3,11 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local expect = helpers.expect local funcs = helpers.funcs local insert = helpers.insert -local meths = helpers.meths local new_argv = helpers.new_argv local neq = helpers.neq local set_session = helpers.set_session @@ -101,7 +101,7 @@ describe('Remote', function() expect(contents) eq(1, #funcs.getbufinfo()) -- Since we didn't pass silent, we should get a complaint - neq(nil, string.find(meths.exec2('messages', { output = true }).output, 'E247')) + neq(nil, string.find(exec_capture('messages'), 'E247:')) end) it('creates server if not found with tabs', function() @@ -110,7 +110,7 @@ describe('Remote', function() eq(2, #funcs.gettabinfo()) eq(2, #funcs.getbufinfo()) -- We passed silent, so no message should be issued about the server not being found - eq(nil, string.find(meths.exec2('messages', { output = true }).output, 'E247')) + eq(nil, string.find(exec_capture('messages'), 'E247:')) end) pending('exits with error on', function() diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 4ae8b1c95e..cc94623df3 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -9,6 +9,7 @@ local ok = helpers.ok local eq = helpers.eq local matches = helpers.matches local eval = helpers.eval +local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local feed = helpers.feed local funcs = helpers.funcs @@ -823,7 +824,7 @@ describe('user config init', function() clear{ args_rm={'-u'}, env=xenv } feed('') -- Dismiss "Conflicting config …" message. eq(1, eval('g:lua_rc')) - matches('^E5422: Conflicting configs', meths.exec2('messages', { output = true }).output) + matches('^E5422: Conflicting configs', exec_capture('messages')) end) end) end) @@ -872,7 +873,7 @@ describe('runtime:', function() eq(2, eval('g:lua_plugin')) -- Check if plugin_file_path is listed in :scriptname - local scripts = meths.exec2(':scriptnames', { output = true }).output + local scripts = exec_capture('scriptnames') assert(scripts:find(plugin_file_path)) -- Check if plugin_file_path is listed in startup profile -- 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/core/fileio_spec.lua | 6 +++--- test/functional/core/main_spec.lua | 12 ++++++------ test/functional/core/spellfile_spec.lua | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 153b53dce2..4236a4ff47 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -1,4 +1,4 @@ -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log @@ -142,7 +142,7 @@ describe('fileio', function() local backup_file_name = link_file_name .. '~' write_file('Xtest_startup_file1', initial_content, false) - lfs.link('Xtest_startup_file1', link_file_name, true) + luv.fs_symlink('Xtest_startup_file1', link_file_name) command('set backup') command('set backupcopy=yes') command('edit ' .. link_file_name) @@ -166,7 +166,7 @@ describe('fileio', function() local backup_file_name = backup_dir .. sep .. link_file_name .. '~' write_file('Xtest_startup_file1', initial_content, false) - lfs.link('Xtest_startup_file1', link_file_name, true) + luv.fs_symlink('Xtest_startup_file1', link_file_name) mkdir(backup_dir) command('set backup') command('set backupcopy=yes') diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index ab11e14a67..efab40dd11 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -1,4 +1,4 @@ -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') @@ -28,18 +28,18 @@ describe('Command-line option', function() os.remove(dollar_fname) end) it('treats - as stdin', function() - eq(nil, lfs.attributes(fname)) + eq(nil, luv.fs_stat(fname)) funcs.system( {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', '-s', '-', fname}, {':call setline(1, "42")', ':wqall!', ''}) eq(0, eval('v:shell_error')) - local attrs = lfs.attributes(fname) + local attrs = luv.fs_stat(fname) eq(#('42\n'), attrs.size) end) it('does not expand $VAR', function() - eq(nil, lfs.attributes(fname)) + eq(nil, luv.fs_stat(fname)) eq(true, not not dollar_fname:find('%$%w+')) write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n') funcs.system( @@ -47,7 +47,7 @@ describe('Command-line option', function() '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', '-s', dollar_fname, fname}) eq(0, eval('v:shell_error')) - local attrs = lfs.attributes(fname) + local attrs = luv.fs_stat(fname) eq(#('100500\n'), attrs.size) end) it('does not crash after reading from stdin in non-headless mode', function() @@ -121,7 +121,7 @@ describe('Command-line option', function() '--cmd', 'language C', '-s', fname, '-s', dollar_fname, fname_2})) eq(2, eval('v:shell_error')) - eq(nil, lfs.attributes(fname_2)) + eq(nil, luv.fs_stat(fname_2)) end) end) end) diff --git a/test/functional/core/spellfile_spec.lua b/test/functional/core/spellfile_spec.lua index afd2c1bce4..378899eece 100644 --- a/test/functional/core/spellfile_spec.lua +++ b/test/functional/core/spellfile_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') local eq = helpers.eq local clear = helpers.clear @@ -7,6 +6,7 @@ local meths = helpers.meths local exc_exec = helpers.exc_exec local rmdir = helpers.rmdir local write_file = helpers.write_file +local mkdir = helpers.mkdir local testdir = 'Xtest-functional-spell-spellfile.d' @@ -14,8 +14,8 @@ describe('spellfile', function() before_each(function() clear() rmdir(testdir) - lfs.mkdir(testdir) - lfs.mkdir(testdir .. '/spell') + mkdir(testdir) + mkdir(testdir .. '/spell') end) after_each(function() rmdir(testdir) -- cgit From 2b35de386ee8854e1012feb4a6cc53b099220677 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 12 Apr 2023 00:01:34 +0200 Subject: refactor: remove :CheckHealth Using :CheckHealth invokes an error, and many of the features from :checkhealth doesn't even work such as calling only a specific check. Users should use :checkhealth instead. --- test/functional/core/startup_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index cc94623df3..2a9d3edb33 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -402,8 +402,6 @@ describe('startup', function() local line1 = string.match(out, '^.-\n') -- updatecount=0 means swapfile was disabled. eq(" swapfile updatecount=0 shadafile=\n", line1) - -- Standard plugins were loaded, but not user config. - eq('health.vim', string.match(out, 'health.vim')) eq(nil, string.match(out, 'init.vim')) end end) -- cgit From 57e9b7f2e5c82316661888a88cad711fc72d5043 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 12 Apr 2023 09:17:32 +0800 Subject: test(startup_spec): use getscriptinfo() instead of :scriptnames (#23034) --- test/functional/core/startup_spec.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 2a9d3edb33..b8a3c1dcd5 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -28,6 +28,9 @@ local meths = helpers.meths local alter_slashes = helpers.alter_slashes local is_os = helpers.is_os local dedent = helpers.dedent +local tbl_map = helpers.tbl_map +local tbl_filter = helpers.tbl_filter +local endswith = helpers.endswith local testfile = 'Xtest_startuptime' after_each(function() @@ -202,12 +205,12 @@ describe('startup', function() end) it('disables swapfile/shada/config/plugins', function() - assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scriptnames=1', + assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scripts=1', nil, nil, '-', - [[print(('updatecount=%d shadafile=%s loadplugins=%s scriptnames=%d'):format( - vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.split(vim.fn.execute('scriptnames'),'\n'))))]]) + [[print(('updatecount=%d shadafile=%s loadplugins=%s scripts=%d'):format( + vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.getscriptinfo())))]]) end) end) @@ -398,11 +401,13 @@ describe('startup', function() for _,arg in ipairs({'-es', '-Es'}) do local out = funcs.system({nvim_prog, arg, '+set swapfile? updatecount? shadafile?', - "+put =execute('scriptnames')", '+%print'}) + "+put =map(getscriptinfo(), {-> v:val.name})", '+%print'}) local line1 = string.match(out, '^.-\n') -- updatecount=0 means swapfile was disabled. eq(" swapfile updatecount=0 shadafile=\n", line1) - eq(nil, string.match(out, 'init.vim')) + -- Standard plugins were loaded, but not user config. + ok(string.find(out, 'man.lua') ~= nil) + ok(string.find(out, 'init.vim') == nil) end end) @@ -863,6 +868,10 @@ describe('runtime:', function() local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) local profiler_file = 'test_startuptime.log' + finally(function() + os.remove(profiler_file) + rmdir(plugin_path) + end) mkdir_p(plugin_folder_path) write_file(plugin_file_path, [[vim.g.lua_plugin = 2]]) @@ -870,18 +879,15 @@ describe('runtime:', function() clear{ args_rm={'-u'}, args={'--startuptime', profiler_file}, env=xenv } eq(2, eval('g:lua_plugin')) - -- Check if plugin_file_path is listed in :scriptname - local scripts = exec_capture('scriptnames') - assert(scripts:find(plugin_file_path)) + -- Check if plugin_file_path is listed in getscriptinfo() + local scripts = tbl_map(function(s) return s.name end, funcs.getscriptinfo()) + ok(#tbl_filter(function(s) return endswith(s, plugin_file_path) end, scripts) > 0) -- Check if plugin_file_path is listed in startup profile local profile_reader = io.open(profiler_file, 'r') local profile_log = profile_reader:read('*a') profile_reader:close() - assert(profile_log:find(plugin_file_path)) - - os.remove(profiler_file) - rmdir(plugin_path) + ok(profile_log:find(plugin_file_path) ~= nil) end) it('loads plugin/*.lua from site packages', function() -- 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/core/spellfile_spec.lua | 20 ++++++++++---------- test/functional/core/startup_spec.lua | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/spellfile_spec.lua b/test/functional/core/spellfile_spec.lua index 378899eece..e3a59085cf 100644 --- a/test/functional/core/spellfile_spec.lua +++ b/test/functional/core/spellfile_spec.lua @@ -24,7 +24,7 @@ describe('spellfile', function() -- │ ┌ Spell file version (#VIMSPELLVERSION) local spellheader = 'VIMspell\050' it('errors out when prefcond section is truncated', function() - meths.set_option('runtimepath', testdir) + meths.set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_PREFCOND) -- │ ┌ Section flags (#SNF_REQUIRED or zero) @@ -34,12 +34,12 @@ describe('spellfile', function() -- │ ┌ Condition length (1 byte) -- │ │ ┌ Condition regex (missing!) .. '\000\001\001') - meths.set_option('spelllang', 'en') + meths.set_option_value('spelllang', 'en', {}) eq('Vim(set):E758: Truncated spell file', exc_exec('set spell')) end) it('errors out when prefcond regexp contains NUL byte', function() - meths.set_option('runtimepath', testdir) + meths.set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_PREFCOND) -- │ ┌ Section flags (#SNF_REQUIRED or zero) @@ -54,12 +54,12 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option('spelllang', 'en') + meths.set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when region contains NUL byte', function() - meths.set_option('runtimepath', testdir) + meths.set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_REGION) -- │ ┌ Section flags (#SNF_REQUIRED or zero) @@ -71,12 +71,12 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option('spelllang', 'en') + meths.set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when SAL section contains NUL byte', function() - meths.set_option('runtimepath', testdir) + meths.set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_SAL) -- │ ┌ Section flags (#SNF_REQUIRED or zero) @@ -95,15 +95,15 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option('spelllang', 'en') + meths.set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when spell header contains NUL bytes', function() - meths.set_option('runtimepath', testdir) + meths.set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000') - meths.set_option('spelllang', 'en') + meths.set_option_value('spelllang', 'en', {}) eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell')) end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index b8a3c1dcd5..fe1b8e1c4e 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -40,9 +40,9 @@ end) describe('startup', function() it('--clean', function() clear() - ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) ~= nil) + ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) ~= nil) clear('--clean') - ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) == nil) + ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) == nil) end) it('--startuptime', function() @@ -589,7 +589,7 @@ describe('startup', function() ]] eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) - local rtp = meths.get_option'rtp' + local rtp = meths.get_option_value('rtp', {}) ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'), 'startswith(…)', 'rtp='..rtp) end) -- cgit From 2db719f6c2b677fcbc197b02fe52764a851523b2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 3 Jun 2023 11:06:00 +0100 Subject: feat(lua): rename vim.loop -> vim.uv (#22846) --- test/functional/core/startup_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index fe1b8e1c4e..54886d0c43 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -110,7 +110,7 @@ describe('startup', function() exec_lua [[ local asan_options = os.getenv 'ASAN_OPTIONS' if asan_options ~= nil and asan_options ~= '' then - vim.loop.os_setenv('ASAN_OPTIONS', asan_options..':detect_leaks=0') + vim.uv.os_setenv('ASAN_OPTIONS', asan_options..':detect_leaks=0') end ]] -- nvim -l foo.lua -arg1 -- a b c -- cgit From 16561dac39490921715a9a8a14dab884659ffc3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Jun 2023 14:09:25 +0800 Subject: test(core/startup_spec): add a test for #13720 (#23910) --- test/functional/core/startup_spec.lua | 210 +++++++++++++++++++--------------- 1 file changed, 119 insertions(+), 91 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 54886d0c43..58bf7f8681 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -32,11 +32,6 @@ local tbl_map = helpers.tbl_map local tbl_filter = helpers.tbl_filter local endswith = helpers.endswith -local testfile = 'Xtest_startuptime' -after_each(function() - os.remove(testfile) -end) - describe('startup', function() it('--clean', function() clear() @@ -46,6 +41,10 @@ describe('startup', function() end) it('--startuptime', function() + local testfile = 'Xtest_startuptime' + finally(function() + os.remove(testfile) + end) clear({ args = {'--startuptime', testfile}}) assert_log('sourcing', testfile, 100) assert_log("require%('vim%._editor'%)", testfile, 100) @@ -81,13 +80,7 @@ describe('startup', function() end) describe('startup', function() - before_each(function() - clear() - os.remove('Xtest_startup_ttyout') - end) - after_each(function() - os.remove('Xtest_startup_ttyout') - end) + before_each(clear) describe('-l Lua', function() local function assert_l_out(expected, nvim_args, lua_args, script, input) @@ -258,6 +251,10 @@ describe('startup', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end + os.remove('Xtest_startup_ttyout') + finally(function() + os.remove('Xtest_startup_ttyout') + end) -- Running in :terminal command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] ..nvim_set..[[\"]] @@ -275,6 +272,10 @@ describe('startup', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end + os.remove('Xtest_startup_ttyout') + finally(function() + os.remove('Xtest_startup_ttyout') + end) -- Running in :terminal command([[exe printf("terminal echo foo | ]] -- Input from a pipe. ..[[%s -u NONE -i NONE --cmd \"]] @@ -334,28 +335,6 @@ describe('startup', function() { '' })) end) - it('-e/-E interactive #7679', function() - clear('-e') - local screen = Screen.new(25, 3) - screen:attach() - feed("put ='from -e'") - screen:expect([[ - :put ='from -e' | - from -e | - :^ | - ]]) - - clear('-E') - screen = Screen.new(25, 3) - screen:attach() - feed("put ='from -E'") - screen:expect([[ - :put ='from -E' | - from -E | - :^ | - ]]) - end) - it('stdin with -es/-Es #7679', function() local input = { 'append', 'line1', 'line2', '.', '%print', '' } local inputstr = table.concat(input, '\n') @@ -411,23 +390,6 @@ describe('startup', function() end end) - it('-e sets ex mode', function() - local screen = Screen.new(25, 3) - clear('-e') - screen:attach() - -- Verify we set the proper mode both before and after :vi. - feed("put =mode(1)vi:put =mode(1)") - screen:expect([[ - cv | - ^n | - :put =mode(1) | - ]]) - - eq('cv\n', - funcs.system({nvim_prog, '-n', '-es' }, - { 'put =mode(1)', 'print', '' })) - end) - it('fails on --embed with -es/-Es/-l', function() matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-es' })) @@ -437,17 +399,6 @@ describe('startup', function() funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' })) end) - it('does not crash if --embed is given twice', function() - clear{args={'--embed'}} - assert_alive() - end) - - it('does not crash when expanding cdpath during early_init', function() - clear{env={CDPATH='~doesnotexist'}} - assert_alive() - eq(',~doesnotexist', eval('&cdpath')) - end) - it('ENTER dismisses early message #7967', function() local screen screen = Screen.new(60, 6) @@ -473,24 +424,6 @@ describe('startup', function() ]]) end) - it("sets 'shortmess' when loading other tabs", function() - clear({args={'-p', 'a', 'b', 'c'}}) - local screen = Screen.new(25, 4) - screen:attach() - screen:expect({grid=[[ - {1: a }{2: b c }{3: }{2:X}| - ^ | - {4:~ }| - | - ]], - attr_ids={ - [1] = {bold = true}, - [2] = {background = Screen.colors.LightGrey, underline = true}, - [3] = {reverse = true}, - [4] = {bold = true, foreground = Screen.colors.Blue1}, - }}) - end) - it('fixed hang issue with --headless (#11386)', function() local expected = '' local period = 100 @@ -516,7 +449,102 @@ describe('startup', function() '+q' }) eq('[\'+q\'] 1', out) end) +end) +describe('startup', function() + it('-e/-E interactive #7679', function() + clear('-e') + local screen = Screen.new(25, 3) + screen:attach() + feed("put ='from -e'") + screen:expect([[ + :put ='from -e' | + from -e | + :^ | + ]]) + + clear('-E') + screen = Screen.new(25, 3) + screen:attach() + feed("put ='from -E'") + screen:expect([[ + :put ='from -E' | + from -E | + :^ | + ]]) + end) + + it('-e sets ex mode', function() + local screen = Screen.new(25, 3) + clear('-e') + screen:attach() + -- Verify we set the proper mode both before and after :vi. + feed("put =mode(1)vi:put =mode(1)") + screen:expect([[ + cv | + ^n | + :put =mode(1) | + ]]) + + eq('cv\n', + funcs.system({nvim_prog, '-n', '-es' }, + { 'put =mode(1)', 'print', '' })) + end) + + it('-d does not diff non-arglist windows #13720 #21289', function() + write_file('Xdiff.vim', [[ + let bufnr = nvim_create_buf(0, 1) + let config = { + \ 'relative': 'editor', + \ 'focusable': v:false, + \ 'width': 1, + \ 'height': 1, + \ 'row': 3, + \ 'col': 3 + \ } + autocmd WinEnter * call nvim_open_win(bufnr, v:false, config)]]) + finally(function() + os.remove('Xdiff.vim') + end) + clear{args={'-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim'}} + eq(true, meths.get_option_value('diff', {win = funcs.win_getid(1)})) + eq(true, meths.get_option_value('diff', {win = funcs.win_getid(2)})) + local float_win = funcs.win_getid(3) + eq('editor', meths.win_get_config(float_win).relative) + eq(false, meths.get_option_value('diff', {win = float_win})) + end) + + it('does not crash if --embed is given twice', function() + clear{args={'--embed'}} + assert_alive() + end) + + it('does not crash when expanding cdpath during early_init', function() + clear{env={CDPATH='~doesnotexist'}} + assert_alive() + eq(',~doesnotexist', eval('&cdpath')) + end) + + it("sets 'shortmess' when loading other tabs", function() + clear({args={'-p', 'a', 'b', 'c'}}) + local screen = Screen.new(25, 4) + screen:attach() + screen:expect({grid=[[ + {1: a }{2: b c }{3: }{2:X}| + ^ | + {4:~ }| + | + ]], + attr_ids={ + [1] = {bold = true}, + [2] = {background = Screen.colors.LightGrey, underline = true}, + [3] = {reverse = true}, + [4] = {bold = true, foreground = Screen.colors.Blue1}, + }}) + end) +end) + +describe('startup', function() local function pack_clear(cmd) -- add packages after config dir in rtp but before config/after clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}, @@ -524,7 +552,6 @@ describe('startup', function() } end - it("handles &packpath during startup", function() pack_clear [[ let g:x = bar#test() @@ -631,13 +658,13 @@ describe('startup', function() end) it('window widths are correct when modelines set &columns with tabpages', function() - write_file('tab1.noft', 'vim: columns=81') - write_file('tab2.noft', 'vim: columns=81') + write_file('Xtab1.noft', 'vim: columns=81') + write_file('Xtab2.noft', 'vim: columns=81') finally(function() - os.remove('tab1.noft') - os.remove('tab2.noft') + os.remove('Xtab1.noft') + os.remove('Xtab2.noft') end) - clear({args = {'-p', 'tab1.noft', 'tab2.noft'}}) + clear({args = {'-p', 'Xtab1.noft', 'Xtab2.noft'}}) eq(81, meths.win_get_width(0)) command('tabnext') eq(81, meths.win_get_width(0)) @@ -721,15 +748,16 @@ describe('user config init', function() end) it('loads init.lua from XDG config home by default', function() - clear{ args_rm={'-u' }, env=xenv } + clear{ args_rm={'-u'}, env=xenv } eq(1, eval('g:lua_rc')) eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) end) - describe('with existing .exrc in cwd', function() + describe('loads existing', function() local exrc_path = '.exrc' local xstate = 'Xstate' + local xstateenv = { XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata, XDG_STATE_HOME=xstate } local function setup_exrc_file(filename) exrc_path = filename @@ -759,10 +787,10 @@ describe('user config init', function() end) for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do - it('loads ' .. filename, function () + it(filename .. ' in cwd', function() setup_exrc_file(filename) - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + clear{ args_rm={'-u'}, env=xstateenv } -- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI. eq('---', eval('g:exrc_file')) @@ -794,7 +822,7 @@ describe('user config init', function() -- TERMINAL -- | ]], filename, string.rep(' ', 50 - #filename))) - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + clear{ args_rm={'-u'}, env=xstateenv } -- The 'exrc' file is now trusted. eq(filename, eval('g:exrc_file')) end) -- cgit From cce9460524aa17bcd4daa095f4706220b81f8845 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 11 Jun 2023 15:29:51 +0800 Subject: fix(remote): make --remote-expr print to stdout (#23980) --- test/functional/core/remote_spec.lua | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index f74bb65553..23aab400df 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -8,6 +8,8 @@ local exec_lua = helpers.exec_lua local expect = helpers.expect local funcs = helpers.funcs local insert = helpers.insert +local is_os = helpers.is_os +local nvim_prog = helpers.nvim_prog local new_argv = helpers.new_argv local neq = helpers.neq local set_session = helpers.set_session @@ -38,10 +40,11 @@ describe('Remote', function() server:close() end) + -- Run a `nvim --remote*` command and return { stdout, stderr } of the process local function run_remote(...) set_session(server) local addr = funcs.serverlist()[1] - local client_argv = new_argv({args={'--server', addr, ...}}) + local client_argv = { nvim_prog, '--clean', '--headless', '--server', addr, ... } -- Create an nvim instance just to run the remote-invoking nvim. We want -- to wait for the remote instance to exit and calling jobwait blocks @@ -50,32 +53,43 @@ describe('Remote', function() local client_starter = spawn(new_argv(), false, nil, true) set_session(client_starter) -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. - eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], client_argv)) + eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(..., { + stdout_buffered = true, + stderr_buffered = true, + on_stdout = function(_, data, _) + _G.Remote_stdout = table.concat(data, '\n') + end, + on_stderr = function(_, data, _) + _G.Remote_stderr = table.concat(data, '\n') + end, + }) })]], client_argv)) + local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]]) client_starter:close() set_session(server) + return res end it('edit a single file', function() - run_remote('--remote', fname) + eq({ '', '' }, run_remote('--remote', fname)) expect(contents) eq(2, #funcs.getbufinfo()) end) it('tab edit a single file with a non-changed buffer', function() - run_remote('--remote-tab', fname) + eq({ '', '' }, run_remote('--remote-tab', fname)) expect(contents) eq(1, #funcs.gettabinfo()) end) it('tab edit a single file with a changed buffer', function() insert('hello') - run_remote('--remote-tab', fname) + eq({ '', '' }, run_remote('--remote-tab', fname)) expect(contents) eq(2, #funcs.gettabinfo()) end) it('edit multiple files', function() - run_remote('--remote', fname, other_fname) + eq({ '', '' }, run_remote('--remote', fname, other_fname)) expect(contents) command('next') expect(other_contents) @@ -83,7 +97,7 @@ describe('Remote', function() end) it('send keys', function() - run_remote('--remote-send', ':edit '..fname..'v') + eq({ '', '' }, run_remote('--remote-send', ':edit '..fname..'v')) expect(contents) eq(2, #funcs.getwininfo()) -- Only a single buffer as we're using edit and not drop like --remote does @@ -91,7 +105,9 @@ describe('Remote', function() end) it('evaluate expressions', function() - run_remote('--remote-expr', 'setline(1, "Yo")') + local linesep = is_os('win') and '\r\n' or '\n' + eq({ "function('get')" .. linesep, '' }, run_remote('--remote-expr', 'function("get")')) + eq({ '0' .. linesep, '' }, run_remote('--remote-expr', 'setline(1, "Yo")')) expect('Yo') end) end) @@ -113,7 +129,7 @@ describe('Remote', function() eq(nil, string.find(exec_capture('messages'), 'E247:')) end) - pending('exits with error on', function() + describe('exits with error on', function() local function run_and_check_exit_code(...) local bogus_argv = new_argv(...) -- cgit From bde59e81473f29944ef80ff98f6b2c88010b2df6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 11 Jun 2023 22:12:32 +0800 Subject: fix(remote): restore previous --remote-expr output formatting (#23988) - Use tostring() as that's what print() uses internally. - Do not append trailing new line. --- test/functional/core/remote_spec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index 23aab400df..20650bef52 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -8,7 +8,6 @@ local exec_lua = helpers.exec_lua local expect = helpers.expect local funcs = helpers.funcs local insert = helpers.insert -local is_os = helpers.is_os local nvim_prog = helpers.nvim_prog local new_argv = helpers.new_argv local neq = helpers.neq @@ -105,10 +104,12 @@ describe('Remote', function() end) it('evaluate expressions', function() - local linesep = is_os('win') and '\r\n' or '\n' - eq({ "function('get')" .. linesep, '' }, run_remote('--remote-expr', 'function("get")')) - eq({ '0' .. linesep, '' }, run_remote('--remote-expr', 'setline(1, "Yo")')) + eq({ '0', '' }, run_remote('--remote-expr', 'setline(1, "Yo")')) + eq({ 'Yo', '' }, run_remote('--remote-expr', 'getline(1)')) expect('Yo') + eq({ '1.25', '' }, run_remote('--remote-expr', '1.25')) + eq({ 'no', '' }, run_remote('--remote-expr', '0z6E6F')) + eq({ '\t', '' }, run_remote('--remote-expr', '"\t"')) end) end) -- cgit From aa65bd478a9860ff4d2490bb49049c78654e811d Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 26 Jun 2023 11:38:48 +0200 Subject: fix(startup): "nvim -l foo.lua" may not set arg0 #24161 Problem: Using "nvim -l args.lua" without passing extra script args, does not set `_G.arg[0]`. Steps to reproduce: ``` cat > args.lua< Date: Sat, 1 Jul 2023 08:16:34 +0800 Subject: fix(startup): don't truncate when printing with -l (#24216) --- test/functional/core/remote_spec.lua | 1 + test/functional/core/startup_spec.lua | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index 20650bef52..39b1ee2f5f 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -107,6 +107,7 @@ describe('Remote', function() eq({ '0', '' }, run_remote('--remote-expr', 'setline(1, "Yo")')) eq({ 'Yo', '' }, run_remote('--remote-expr', 'getline(1)')) expect('Yo') + eq({ ('k'):rep(1234), '' }, run_remote('--remote-expr', 'repeat("k", 1234)')) eq({ '1.25', '' }, run_remote('--remote-expr', '1.25')) eq({ 'no', '' }, run_remote('--remote-expr', '0z6E6F')) eq({ '\t', '' }, run_remote('--remote-expr', '"\t"')) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index ef3c2eadd9..3f284c5c9e 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -101,10 +101,11 @@ describe('startup', function() it('os.exit() sets Nvim exitcode', function() -- tricky: LeakSanitizer triggers on os.exit() and disrupts the return value, disable it exec_lua [[ - local asan_options = os.getenv 'ASAN_OPTIONS' - if asan_options ~= nil and asan_options ~= '' then - vim.uv.os_setenv('ASAN_OPTIONS', asan_options..':detect_leaks=0') + local asan_options = os.getenv('ASAN_OPTIONS') or '' + if asan_options ~= '' then + asan_options = asan_options .. ':' end + vim.uv.os_setenv('ASAN_OPTIONS', asan_options .. ':detect_leaks=0') ]] -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ @@ -143,6 +144,14 @@ describe('startup', function() eq(0, eval('v:shell_error')) end) + it('does not truncate long print() message', function() + assert_l_out(('k'):rep(1234), + nil, + nil, + '-', + "print(('k'):rep(1234))") + end) + it('sets _G.arg', function() -- nvim -l foo.lua assert_l_out([[ @@ -219,6 +228,15 @@ describe('startup', function() end) end) + it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function() + local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', + '--cmd', 'lua print(("A"):rep(1234))', + '-c', 'lua print(("B"):rep(1234))', + '+lua print(("C"):rep(1234))', + '+q' }) + eq(('A'):rep(1234) .. '\r\n' .. ('B'):rep(1234) .. '\r\n' .. ('C'):rep(1234), out) + end) + it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() -- system() puts a pipe at both ends. local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', -- cgit From 43ded8d3584477ab14731486cfb0e86534f2b2dc Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 1 Jul 2023 03:45:45 -0700 Subject: feat(version): unverbose ":version", ":verbose version" #24195 Problem: `nvim -v` and `:version` prints system vimrc, fallback files, and compilation info by default, which most people don't care about and just clutters up the output. Solution: Omit extra info unless 'verbose' is set. --- test/functional/core/main_spec.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index efab40dd11..19c7a93730 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq +local matches = helpers.matches local feed = helpers.feed local eval = helpers.eval local clear = helpers.clear @@ -12,21 +13,24 @@ local write_file = helpers.write_file local is_os = helpers.is_os local skip = helpers.skip -describe('Command-line option', function() +describe('command-line option', function() describe('-s', function() local fname = 'Xtest-functional-core-main-s' local fname_2 = fname .. '.2' local nonexistent_fname = fname .. '.nonexistent' local dollar_fname = '$' .. fname + before_each(function() clear() os.remove(fname) os.remove(dollar_fname) end) + after_each(function() os.remove(fname) os.remove(dollar_fname) end) + it('treats - as stdin', function() eq(nil, luv.fs_stat(fname)) funcs.system( @@ -38,6 +42,7 @@ describe('Command-line option', function() local attrs = luv.fs_stat(fname) eq(#('42\n'), attrs.size) end) + it('does not expand $VAR', function() eq(nil, luv.fs_stat(fname)) eq(true, not not dollar_fname:find('%$%w+')) @@ -50,6 +55,7 @@ describe('Command-line option', function() local attrs = luv.fs_stat(fname) eq(#('100500\n'), attrs.size) end) + it('does not crash after reading from stdin in non-headless mode', function() skip(is_os('win')) local screen = Screen.new(40, 8) @@ -100,6 +106,7 @@ describe('Command-line option', function() ]]) ]=] end) + it('errors out when trying to use nonexistent file with -s', function() eq( 'Cannot open for reading: "'..nonexistent_fname..'": no such file or directory\n', @@ -110,6 +117,7 @@ describe('Command-line option', function() '-s', nonexistent_fname})) eq(2, eval('v:shell_error')) end) + it('errors out when trying to use -s twice', function() write_file(fname, ':call setline(1, "1")\n:wqall!\n') write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n') @@ -124,4 +132,11 @@ describe('Command-line option', function() eq(nil, luv.fs_stat(fname_2)) end) end) + + it('nvim -v, :version', function() + matches('Run ":verbose version"', funcs.execute(':version')) + matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version')) + matches('Run "nvim %-V1 %-v"', funcs.system({nvim_prog_abs(), '-v'})) + matches('Compilation: .*Run :checkhealth', funcs.system({nvim_prog_abs(), '-V1', '-v'})) + end) end) -- cgit From db590e96d59381f873747e888c9afe3c6378678c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 2 Jul 2023 05:48:12 +0800 Subject: fix(startup)!: "nvim -l" message does not end with newline #24215 Close #24180 --- test/functional/core/startup_spec.lua | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 3f284c5c9e..3253854093 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -131,12 +131,12 @@ describe('startup', function() end) it('executes stdin "-"', function() - assert_l_out('arg0=- args=2 whoa', + assert_l_out('arg0=- args=2 whoa\n', nil, { 'arg1', 'arg 2' }, '-', "print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))") - assert_l_out('biiig input: 1000042', + assert_l_out('biiig input: 1000042\n', nil, nil, '-', @@ -145,11 +145,12 @@ describe('startup', function() end) it('does not truncate long print() message', function() - assert_l_out(('k'):rep(1234), - nil, - nil, - '-', - "print(('k'):rep(1234))") + assert_l_out(('k'):rep(1234) .. '\n', nil, nil, '-', "print(('k'):rep(1234))") + end) + + it('does not add newline when unnecessary', function() + assert_l_out('', nil, nil, '-', '') + assert_l_out('foobar\n', nil, nil, '-', [[print('foobar\n')]]) end) it('sets _G.arg', function() @@ -159,7 +160,8 @@ describe('startup', function() nvim args: 3 lua args: { [0] = "test/functional/fixtures/startup.lua" - }]], + } + ]], {}, {} ) @@ -171,7 +173,8 @@ describe('startup', function() nvim args: 7 lua args: { "-arg1", "--arg2", "--", "arg3", [0] = "test/functional/fixtures/startup.lua" - }]], + } + ]], {}, { '-arg1', '--arg2', '--', 'arg3' } ) @@ -183,7 +186,8 @@ describe('startup', function() nvim args: 10 lua args: { "-arg1", "arg 2", "--", "file3", "file4", [0] = "test/functional/fixtures/startup.lua" - }]], + } + ]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) @@ -195,7 +199,8 @@ describe('startup', function() nvim args: 5 lua args: { "-c", "set wrap?", [0] = "test/functional/fixtures/startup.lua" - }]], + } + ]], {}, { '-c', 'set wrap?' } ) @@ -211,7 +216,8 @@ describe('startup', function() nvim args: 7 lua args: { "-c", "set wrap?", [0] = "test/functional/fixtures/startup.lua" - }]], + } + ]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) @@ -219,7 +225,7 @@ describe('startup', function() end) it('disables swapfile/shada/config/plugins', function() - assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scripts=1', + assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scripts=1\n', nil, nil, '-', -- cgit From dbb840da01c72d8a311e0c55d3248d78a64b63a4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Jul 2023 06:46:16 +0800 Subject: fix(runtime): respect 'rtp' order for all runtime files (#24335) --- test/functional/core/startup_spec.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 3253854093..c541e32353 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -975,16 +975,23 @@ describe('runtime:', function() end) - it('loads ftdetect/*.lua', function() + it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function() local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep) - local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep) + local after_ftdetect_folder = table.concat({xconfig, 'nvim', 'after', 'ftdetect'}, pathsep) mkdir_p(ftdetect_folder) - write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]]) - - clear{ args_rm={'-u'}, env=xenv } - - eq(1, eval('g:lua_ftdetect')) - rmdir(ftdetect_folder) + mkdir_p(after_ftdetect_folder) + finally(function() + rmdir(ftdetect_folder) + rmdir(after_ftdetect_folder) + end) + -- A .lua file is loaded after a .vim file if they only differ in extension. + -- All files in after/ftdetect/ are loaded after all files in ftdetect/. + write_file(table.concat({ftdetect_folder, 'new-ft.vim'}, pathsep), [[let g:seq ..= 'A']]) + write_file(table.concat({ftdetect_folder, 'new-ft.lua'}, pathsep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({after_ftdetect_folder, 'new-ft.vim'}, pathsep), [[let g:seq ..= 'a']]) + write_file(table.concat({after_ftdetect_folder, 'new-ft.lua'}, pathsep), [[vim.g.seq = vim.g.seq .. 'b']]) + clear{ args_rm={'-u'}, args = {'--cmd', 'let g:seq = ""'}, env=xenv } + eq('ABab', eval('g:seq')) end) end) -- cgit From f660b794808ac809ee8cafe82ddd824840bc8e2c Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 16 Jul 2023 14:50:10 +0200 Subject: test(fs): get tmpdir robustly #23021 Problem: helpers.tmpname() may create a local file, depending on circumstances. Solution: Only use helpers.tmpname() for its parent directory (the "temp root"). Use fs_mkdtemp() to actually get a unique name. --- test/functional/core/fileio_spec.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 4236a4ff47..27a32ce6f8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -19,7 +19,6 @@ local meths = helpers.meths local mkdir = helpers.mkdir local sleep = helpers.sleep local read_file = helpers.read_file -local tmpname = helpers.tmpname local trim = helpers.trim local currentdir = helpers.funcs.getcwd local assert_alive = helpers.assert_alive @@ -266,9 +265,7 @@ describe('tmpdir', function() before_each(function() -- Fake /tmp dir so that we can mess it up. - os_tmpdir = tmpname() - os.remove(os_tmpdir) - mkdir(os_tmpdir) + os_tmpdir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') end) after_each(function() -- cgit From 98b22867c33a45aaaf057afbeda8acb0216494e3 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:27:55 +0200 Subject: test(fs): vim.loop was renamed to vim.uv (#24376) test(fs): vim.loop has been replaced with vim.uv --- test/functional/core/fileio_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 27a32ce6f8..d1236f2766 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -265,7 +265,7 @@ describe('tmpdir', function() before_each(function() -- Fake /tmp dir so that we can mess it up. - os_tmpdir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') + os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') end) after_each(function() -- cgit From 881d17a11393da75a27c072faa3fd45f510175fe Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Jul 2023 14:27:21 +0100 Subject: feat(options)!: remove compatible behaviours for vim 5.0 and earlier --- test/functional/core/fileio_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index d1236f2766..8de78234ce 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -45,6 +45,7 @@ describe('fileio', function() os.remove('Xtest-overwrite-forced') rmdir('Xtest_startup_swapdir') rmdir('Xtest_backupdir') + rmdir('Xtest_backupdir with spaces') end) it('fsync() codepaths #8304', function() @@ -132,6 +133,28 @@ describe('fileio', function() eq('foo', foo_contents); end) + it('backup with full path with spaces', function() + skip(is_ci('cirrus')) + clear() + mkdir('Xtest_backup with spaces') + command('set backup') + command('set backupdir=Xtest_backupdir\\ with\\ spaces//') + command('write Xtest_startup_file1') + feed('ifoo') + command('write') + feed('Abar') + command('write') + + -- Backup filename = fullpath, separators replaced with "%". + local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1', + is_os('win') and '[:/\\]' or '/', '%%') .. '~' + local foo_contents = trim(read_file('Xtest_backupdir with spaces/'..backup_file_name)) + local foobar_contents = trim(read_file('Xtest_startup_file1')) + + eq('foobar', foobar_contents); + eq('foo', foo_contents); + end) + it('backup symlinked files #11349', function() skip(is_ci('cirrus')) clear() -- cgit From ab5cdbd167353a0c6a0ef0b864d78af13029339c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Jul 2023 07:14:32 +0800 Subject: test(startup_spec): add a test for #18315 (#24391) --- test/functional/core/startup_spec.lua | 42 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index c541e32353..dcbb55a9d7 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -917,27 +917,27 @@ describe('runtime:', function() local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) mkdir_p(plugin_folder_path) + finally(function() + rmdir(plugin_folder_path) + end) write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]]) clear{ args_rm={'-u'}, env=xenv } eq(1, eval('g:lua_plugin')) - rmdir(plugin_folder_path) end) it('loads plugin/*.lua from start packages', function() - local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category', - 'start', 'test_plugin'}, pathsep) + local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category', 'start', 'test_plugin'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) - local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, - pathsep) + local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) local profiler_file = 'test_startuptime.log' + mkdir_p(plugin_folder_path) finally(function() os.remove(profiler_file) rmdir(plugin_path) end) - mkdir_p(plugin_folder_path) write_file(plugin_file_path, [[vim.g.lua_plugin = 2]]) clear{ args_rm={'-u'}, args={'--startuptime', profiler_file}, env=xenv } @@ -961,19 +961,41 @@ describe('runtime:', function() local plugin_after_path = table.concat({plugin_path, 'after', 'plugin'}, pathsep) local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep) local plugin_after_file_path = table.concat({plugin_after_path, 'helloo.lua'}, pathsep) - mkdir_p(plugin_folder_path) - write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]]) mkdir_p(plugin_after_path) + finally(function() + rmdir(plugin_path) + end) + + write_file(plugin_file_path, [[table.insert(_G.lista, "unos")]]) write_file(plugin_after_file_path, [[table.insert(_G.lista, "dos")]]) clear{ args_rm={'-u'}, args={'--cmd', 'lua _G.lista = {}'}, env=xenv } eq({'unos', 'dos'}, exec_lua "return _G.lista") - - rmdir(plugin_path) end) + it('no crash setting &rtp in plugins with :packloadall called before #18315', function() + local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep) + mkdir_p(plugin_folder_path) + finally(function() + rmdir(plugin_folder_path) + end) + + write_file(table.concat({plugin_folder_path, 'plugin.vim'}, pathsep), [[ + let &runtimepath = &runtimepath + let g:vim_plugin = 1 + ]]) + write_file(table.concat({plugin_folder_path, 'plugin.lua'}, pathsep), [[ + vim.o.runtimepath = vim.o.runtimepath + vim.g.lua_plugin = 1 + ]]) + + clear{ args_rm={'-u'}, args = {'--cmd', 'packloadall'}, env=xenv } + + eq(1, eval('g:vim_plugin')) + eq(1, eval('g:lua_plugin')) + end) it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function() local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep) -- cgit From c0fa721adeabf1d93ad71e598782b52c43d8e8f7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 25 Jul 2023 19:02:39 +0800 Subject: fix(startup): make recovery mode work without --headless (#24477) --- test/functional/core/remote_spec.lua | 5 ++--- test/functional/core/startup_spec.lua | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index 39b1ee2f5f..a0ec748446 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -43,7 +43,6 @@ describe('Remote', function() local function run_remote(...) set_session(server) local addr = funcs.serverlist()[1] - local client_argv = { nvim_prog, '--clean', '--headless', '--server', addr, ... } -- Create an nvim instance just to run the remote-invoking nvim. We want -- to wait for the remote instance to exit and calling jobwait blocks @@ -52,7 +51,7 @@ describe('Remote', function() local client_starter = spawn(new_argv(), false, nil, true) set_session(client_starter) -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. - eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(..., { + eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart({...}, { stdout_buffered = true, stderr_buffered = true, on_stdout = function(_, data, _) @@ -61,7 +60,7 @@ describe('Remote', function() on_stderr = function(_, data, _) _G.Remote_stderr = table.concat(data, '\n') end, - }) })]], client_argv)) + }) })]], nvim_prog, '--clean', '--headless', '--server', addr, ...)) local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]]) client_starter:close() set_session(server) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index dcbb55a9d7..c1e07f0c76 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -21,6 +21,7 @@ local nvim_set = helpers.nvim_set local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir +local skip = helpers.skip local sleep = helpers.sleep local startswith = helpers.startswith local write_file = helpers.write_file @@ -460,6 +461,18 @@ describe('startup', function() ]]) end) + it('-r works without --headless in PTY #23294', function() + skip(is_os('win')) + eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart({...}, { + pty = true, + stdout_buffered = true, + on_stdout = function(_, data, _) + _G.Recovery_stdout = data + end, + }) })]], nvim_prog, '-u', 'NONE', '-i', 'NONE', '-r')) + matches('Swap files found:\r*', exec_lua('return _G.Recovery_stdout[1]')) + end) + it('fixed hang issue with --headless (#11386)', function() local expected = '' local period = 100 -- cgit From 898384ac6900aa5cb8ef84d53ad586ecf424a25c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 25 Jul 2023 20:32:59 +0800 Subject: test(core/startup_spec): use retry() instead of jobwait() (#24481) This should work on Windows. --- test/functional/core/startup_spec.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index c1e07f0c76..fb30ddebb9 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -9,6 +9,7 @@ local ok = helpers.ok local eq = helpers.eq local matches = helpers.matches local eval = helpers.eval +local exec = helpers.exec local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local feed = helpers.feed @@ -21,7 +22,6 @@ local nvim_set = helpers.nvim_set local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir -local skip = helpers.skip local sleep = helpers.sleep local startswith = helpers.startswith local write_file = helpers.write_file @@ -462,15 +462,23 @@ describe('startup', function() end) it('-r works without --headless in PTY #23294', function() - skip(is_os('win')) - eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart({...}, { - pty = true, - stdout_buffered = true, - on_stdout = function(_, data, _) - _G.Recovery_stdout = data - end, - }) })]], nvim_prog, '-u', 'NONE', '-i', 'NONE', '-r')) - matches('Swap files found:\r*', exec_lua('return _G.Recovery_stdout[1]')) + exec([[ + func Normalize(data) abort + " Windows: remove ^M and term escape sequences + return map(a:data, 'substitute(substitute(v:val, "\r", "", "g"), "\x1b\\%(\\]\\d\\+;.\\{-}\x07\\|\\[.\\{-}[\x40-\x7E]\\)", "", "g")') + endfunc + func OnOutput(id, data, event) dict + let g:stdout = Normalize(a:data) + endfunc + call jobstart([v:progpath, '-u', 'NONE', '-i', 'NONE', '-r'], { + \ 'pty': v:true, + \ 'stdout_buffered': v:true, + \ 'on_stdout': function('OnOutput'), + \ }) + ]]) + retry(nil, nil, function() + eq('Swap files found:', eval('g:stdout[0]')) + end) end) it('fixed hang issue with --headless (#11386)', function() -- cgit From 7b0123dd6a06a032516cce66d82c064b1d942013 Mon Sep 17 00:00:00 2001 From: shafouz <38974831+shafouz@users.noreply.github.com> Date: Sun, 13 Aug 2023 02:14:08 -0400 Subject: feat(remote): avoid --remote-ui infinite loop (#24465) --- test/functional/core/startup_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index fb30ddebb9..94ec3d4907 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -41,6 +41,19 @@ describe('startup', function() ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) == nil) end) + it('prevents remote UI infinite loop', function() + clear() + local screen + screen = Screen.new(84, 3) + screen:attach() + funcs.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) + screen:expect([[ + ^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) | + | + | + ]]) + end) + it('--startuptime', function() local testfile = 'Xtest_startuptime' finally(function() -- cgit From a66b0fdfaa35715c832b98b8941cc5673505e0c2 Mon Sep 17 00:00:00 2001 From: Rory Nesbitt Date: Wed, 27 Sep 2023 18:09:55 +0100 Subject: feat: NVIM_APPNAME supports relative paths #25233 Problem: NVIM_APPNAME does not allow path separators in the name, so relative paths can't be used: NVIM_APPNAME="neovim-configs/first-config" nvim NVIM_APPNAME="neovim-configs/second-config" nvim Solution: Let NVIM_APPNAME be a relative path. Absolute paths are not supported. fix #23056 fix #24966 --- test/functional/core/fileio_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 8de78234ce..f2b360f0d8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -377,4 +377,14 @@ describe('tmpdir', function() rm_tmpdir() eq('E5431: tempdir disappeared (3 times)', meths.get_vvar('errmsg')) end) + + it('$NVIM_APPNAME relative path', function() + clear({ env={ + NVIM_APPNAME='a/b', + NVIM_LOG_FILE=testlog, + TMPDIR=os_tmpdir, + } }) + matches([=[.*[/\\]a%%b%.[^/\\]+]=], funcs.tempname()) + end) + end) -- cgit From 04af9d49ee9f29a578d0891af20857fea45b674b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 Oct 2023 12:13:04 +0800 Subject: test(fileio_spec): fix files not cleaned up properly (#25483) --- test/functional/core/fileio_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index f2b360f0d8..a1a90a59f3 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -40,6 +40,7 @@ describe('fileio', function() os.remove('Xtest_startup_file1') os.remove('Xtest_startup_file1~') os.remove('Xtest_startup_file2') + os.remove('Xtest_startup_file2~') os.remove('Xtest_тест.md') os.remove('Xtest-u8-int-max') os.remove('Xtest-overwrite-forced') @@ -136,7 +137,7 @@ describe('fileio', function() it('backup with full path with spaces', function() skip(is_ci('cirrus')) clear() - mkdir('Xtest_backup with spaces') + mkdir('Xtest_backupdir with spaces') command('set backup') command('set backupdir=Xtest_backupdir\\ with\\ spaces//') command('write Xtest_startup_file1') -- cgit From a9a48d6b5f00241e16e7131c997f0117bc5e9047 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 30 Sep 2023 10:31:55 +0200 Subject: refactor(message): simplify msg_puts_display and use batched grid updates msg_puts_display was more complex than necessary in nvim, as in nvim, it no longer talks directly with a terminal. In particular we don't need to scroll the grid before emiting the last char. The TUI already takes care of things like that, for terminals where it matters. --- test/functional/core/fileio_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index a1a90a59f3..a23dad226a 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -259,8 +259,8 @@ describe('fileio', function() screen:expect([[ {2:WARNING: The file has been changed since}| {2: reading it!!!} | - {3:Do you really want to write to it (y/n)^?}| - | + {3:Do you really want to write to it (y/n)?}| + ^ | ]]) feed("n") -- cgit From 1e7e9ee91f73c62b8c5ba9dbdabba3a3b6dc0130 Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Tue, 3 Oct 2023 19:04:19 -0300 Subject: fix(path): accept special characters on Windows (#25424) --- test/functional/core/path_spec.lua | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index a786887bbd..6c677d76d1 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -6,16 +6,19 @@ local command = helpers.command local insert = helpers.insert local feed = helpers.feed local is_os = helpers.is_os +local mkdir = helpers.mkdir +local rmdir = helpers.rmdir +local write_file = helpers.write_file + +local function join_path(...) + local pathsep = (is_os('win') and '\\' or '/') + return table.concat({...}, pathsep) +end describe('path collapse', function() local targetdir local expected_path - local function join_path(...) - local pathsep = (is_os('win') and '\\' or '/') - return table.concat({...}, pathsep) - end - before_each(function() targetdir = join_path('test', 'functional', 'fixtures') clear() @@ -57,6 +60,27 @@ describe('path collapse', function() end) end) +describe('expand wildcard', function() + before_each(clear) + + it('with special characters #24421', function() + local folders = is_os('win') and { + '{folder}', + 'folder$name' + } or { + 'folder-name', + 'folder#name' + } + for _, folder in ipairs(folders) do + mkdir(folder) + local file = join_path(folder, 'file.txt') + write_file(file, '') + eq(file, eval('expand("'..folder..'/*")')) + rmdir(folder) + end + end) +end) + describe('file search', function() before_each(clear) -- cgit From 1dd700a8d9275439fbc71ac5adeb59914bdbd5cf Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Mon, 18 Sep 2023 16:50:47 -0300 Subject: fix: gf fails on "foo/bar.txt:1:2" on Windows Problem: On Windows, "gf" fails on a filepath that has a line:column suffix. Example: E447: Can't find file "src/app/core/services/identity/identity.service.ts:64:23" Solution: - Remove ":" from 'isfname' on Windows. Colon is not a valid filename character (except for the drive-letter). - Handle drive letters specially in file_name_in_line(). Fixes #25160 --- test/functional/core/path_spec.lua | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 6c677d76d1..1c6faf8d60 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -91,4 +91,80 @@ describe('file search', function() feed('gf') eq('filename_with_unicode_ααα', eval('expand("%:t")')) end) + + it('matches Windows drive-letter filepaths (without ":" in &isfname)', function() + local os_win = is_os('win') + + insert([[c:/d:/foo/bar.txt]]) + eq([[c:/d:/foo/bar.txt]], eval('expand("")')) + command('%delete') + + insert([[//share/c:/foo/bar/]]) + eq([[//share/c:/foo/bar/]], eval('expand("")')) + command('%delete') + + insert([[file://c:/foo/bar]]) + eq([[file://c:/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[https://c:/foo/bar]]) + eq([[https://c:/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[\foo\bar]]) + eq(os_win and [[\foo\bar]] or [[bar]], eval('expand("")')) + command('%delete') + + insert([[/foo/bar]]) + eq([[/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[c:\foo\bar]]) + eq(os_win and [[c:\foo\bar]] or [[bar]], eval('expand("")')) + command('%delete') + + insert([[c:/foo/bar]]) + eq([[c:/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[c:foo\bar]]) + eq(os_win and [[foo\bar]] or [[bar]], eval('expand("")')) + command('%delete') + + insert([[c:foo/bar]]) + eq([[foo/bar]], eval('expand("")')) + command('%delete') + + insert([[c:foo]]) + eq([[foo]], eval('expand("")')) + command('%delete') + + -- Examples from: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#example-ways-to-refer-to-the-same-file + insert([[c:\temp\test-file.txt]]) + eq(os_win and [[c:\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\127.0.0.1\c$\temp\test-file.txt]]) + eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\LOCALHOST\c$\temp\test-file.txt]]) + eq(os_win and [[\\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\.\c:\temp\test-file.txt]]) -- not supported yet + eq(os_win and [[\\.\c]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\?\c:\temp\test-file.txt]]) -- not supported yet + eq(os_win and [[\c]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) + eq(os_win and [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\127.0.0.1\c$\temp\test-file.txt]]) + eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + end) end) -- cgit From 133e2990efa44cadf1410a452a08843dbd8ca86e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 6 Oct 2023 12:59:39 +0200 Subject: refactor: cleanup --- test/functional/core/path_spec.lua | 106 ++++++++++++------------------------- 1 file changed, 34 insertions(+), 72 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 1c6faf8d60..06fa13dca5 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -81,7 +81,7 @@ describe('expand wildcard', function() end) end) -describe('file search', function() +describe('file search (gf, )', function() before_each(clear) it('find multibyte file name in line #20517', function() @@ -93,78 +93,40 @@ describe('file search', function() end) it('matches Windows drive-letter filepaths (without ":" in &isfname)', function() - local os_win = is_os('win') - - insert([[c:/d:/foo/bar.txt]]) - eq([[c:/d:/foo/bar.txt]], eval('expand("")')) - command('%delete') - - insert([[//share/c:/foo/bar/]]) - eq([[//share/c:/foo/bar/]], eval('expand("")')) - command('%delete') - - insert([[file://c:/foo/bar]]) - eq([[file://c:/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[https://c:/foo/bar]]) - eq([[https://c:/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[\foo\bar]]) - eq(os_win and [[\foo\bar]] or [[bar]], eval('expand("")')) - command('%delete') - - insert([[/foo/bar]]) - eq([[/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[c:\foo\bar]]) - eq(os_win and [[c:\foo\bar]] or [[bar]], eval('expand("")')) - command('%delete') - - insert([[c:/foo/bar]]) - eq([[c:/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[c:foo\bar]]) - eq(os_win and [[foo\bar]] or [[bar]], eval('expand("")')) - command('%delete') - - insert([[c:foo/bar]]) - eq([[foo/bar]], eval('expand("")')) - command('%delete') - - insert([[c:foo]]) - eq([[foo]], eval('expand("")')) - command('%delete') + local iswin = is_os('win') + local function test_cfile(input, expected, expected_win) + expected = (iswin and expected_win or expected) or input + command('%delete') + insert(input) + command('norm! 0') + eq(expected, eval('expand("")')) + end + test_cfile([[c:/d:/foo/bar.txt]]) -- TODO(justinmk): should return "d:/foo/bar.txt" ? + test_cfile([[//share/c:/foo/bar/]]) + test_cfile([[file://c:/foo/bar]]) + test_cfile([[file://c:/foo/bar:42]]) + test_cfile([[file://c:/foo/bar:42:666]]) + test_cfile([[https://c:/foo/bar]]) + test_cfile([[\foo\bar]], [[foo]], [[\foo\bar]]) + test_cfile([[/foo/bar]], [[/foo/bar]]) + test_cfile([[c:\foo\bar]], [[c:]], [[c:\foo\bar]]) + test_cfile([[c:\foo\bar:42:666]], [[c:]], [[c:\foo\bar]]) + test_cfile([[c:/foo/bar]]) + test_cfile([[c:/foo/bar:42]], [[c:/foo/bar]]) + test_cfile([[c:/foo/bar:42:666]], [[c:/foo/bar]]) + test_cfile([[c:foo\bar]], [[c]]) + test_cfile([[c:foo/bar]], [[c]]) + test_cfile([[c:foo]], [[c]]) -- Examples from: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#example-ways-to-refer-to-the-same-file - insert([[c:\temp\test-file.txt]]) - eq(os_win and [[c:\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\127.0.0.1\c$\temp\test-file.txt]]) - eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\LOCALHOST\c$\temp\test-file.txt]]) - eq(os_win and [[\\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\.\c:\temp\test-file.txt]]) -- not supported yet - eq(os_win and [[\\.\c]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\?\c:\temp\test-file.txt]]) -- not supported yet - eq(os_win and [[\c]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) - eq(os_win and [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\127.0.0.1\c$\temp\test-file.txt]]) - eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + test_cfile([[c:\temp\test-file.txt]], [[c:]], [[c:\temp\test-file.txt]]) + test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) + test_cfile([[\\LOCALHOST\c$\temp\test-file.txt]], [[LOCALHOST]], [[\\LOCALHOST\c$\temp\test-file.txt]]) + -- not supported yet + test_cfile([[\\.\c:\temp\test-file.txt]], [[.]], [[\\.\c]]) + -- not supported yet + test_cfile([[\\?\c:\temp\test-file.txt]], [[c:]], [[\\]]) + test_cfile([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]], [[.]], [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) + test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) end) -- cgit From 81f67b79e8a307a45a996dbeee0213c7745aa358 Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Mon, 9 Oct 2023 19:08:58 -0300 Subject: fix(file_search): path with spaces in finddir() and findfile() (#25493) Co-authored-by: dundargoc --- test/functional/core/path_spec.lua | 41 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 06fa13dca5..215217e771 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -1,10 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear +local command = helpers.command local eq = helpers.eq local eval = helpers.eval -local command = helpers.command -local insert = helpers.insert local feed = helpers.feed +local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir local rmdir = helpers.rmdir @@ -130,3 +130,40 @@ describe('file search (gf, )', function() test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) end) + +describe('file search with vim functions', function() + local test_folder = "path_spec_folder" + + setup(function() + mkdir(test_folder) + end) + + teardown(function() + rmdir(test_folder) + end) + + ---@param option "dir" | "file" + local function test_find_func(option, folder, item) + local folder_path = join_path(test_folder, folder) + mkdir(folder_path) + local expected = join_path(folder_path, item) + if option == "dir" then + mkdir(expected) + else + write_file(expected, '') + end + eq(expected, eval('find'..option..'(fnameescape(\''..item..'\'),fnameescape(\''..folder_path..'\'))')) + end + + it('finddir()', function() + test_find_func('dir', 'directory', 'folder') + -- test_find_func('dir', 'directory', 'folder name') + test_find_func('dir', 'folder name', 'directory') + end) + + it('findfile()', function() + test_find_func('file', 'directory', 'file.txt') + -- test_find_func('file', 'directory', 'file name.txt') + test_find_func('file', 'folder name', 'file.txt') + end) +end) -- cgit From 4eea60939f9c079d4e1652e0ed1724c4f2ab6eda Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 11 Oct 2023 07:24:37 +0800 Subject: test(core/path_spec): don't use fnameescape() (#25593) Using fnameescape() for the path argument of findfile() and finddir() is wrong, as fnameescape() is intended to be used for parts of Ex commands, not function arguments. --- test/functional/core/path_spec.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 215217e771..268d557691 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -4,6 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed +local funcs = helpers.funcs local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir @@ -152,18 +153,18 @@ describe('file search with vim functions', function() else write_file(expected, '') end - eq(expected, eval('find'..option..'(fnameescape(\''..item..'\'),fnameescape(\''..folder_path..'\'))')) + eq(expected, funcs['find' .. option](item, folder_path:gsub(' ', [[\ ]]))) end it('finddir()', function() test_find_func('dir', 'directory', 'folder') - -- test_find_func('dir', 'directory', 'folder name') - test_find_func('dir', 'folder name', 'directory') + test_find_func('dir', 'directory', 'folder name') + test_find_func('dir', 'fold#er name', 'directory') end) it('findfile()', function() test_find_func('file', 'directory', 'file.txt') - -- test_find_func('file', 'directory', 'file name.txt') - test_find_func('file', 'folder name', 'file.txt') + test_find_func('file', 'directory', 'file name.txt') + test_find_func('file', 'fold#er name', 'file.txt') end) end) -- cgit From 2c9f22e7e4947e1865ab18c61fbc0199be8b323d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 12 Oct 2023 07:04:16 -0700 Subject: refactor(test): cleanup #25614 - unnecessary separate describe() group - clear() wasn't called in the describe() group - unnecessary indirection in function parameters --- test/functional/core/path_spec.lua | 54 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 268d557691..97c32f7de6 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -82,10 +82,20 @@ describe('expand wildcard', function() end) end) -describe('file search (gf, )', function() +describe('file search', function() + local testdir = 'Xtest_path_spec' + before_each(clear) - it('find multibyte file name in line #20517', function() + setup(function() + mkdir(testdir) + end) + + teardown(function() + rmdir(testdir) + end) + + it('gf finds multibyte filename in line #20517', function() command('cd test/functional/fixtures') insert('filename_with_unicode_ααα') eq('', eval('expand("%")')) @@ -93,7 +103,7 @@ describe('file search (gf, )', function() eq('filename_with_unicode_ααα', eval('expand("%:t")')) end) - it('matches Windows drive-letter filepaths (without ":" in &isfname)', function() + it('gf/ matches Windows drive-letter filepaths (without ":" in &isfname)', function() local iswin = is_os('win') local function test_cfile(input, expected, expected_win) expected = (iswin and expected_win or expected) or input @@ -130,41 +140,29 @@ describe('file search (gf, )', function() test_cfile([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]], [[.]], [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) -end) - -describe('file search with vim functions', function() - local test_folder = "path_spec_folder" - - setup(function() - mkdir(test_folder) - end) - - teardown(function() - rmdir(test_folder) - end) - ---@param option "dir" | "file" - local function test_find_func(option, folder, item) - local folder_path = join_path(test_folder, folder) - mkdir(folder_path) - local expected = join_path(folder_path, item) - if option == "dir" then + ---@param funcname 'finddir' | 'findfile' + local function test_find_func(funcname, folder, item) + local d = join_path(testdir, folder) + mkdir(d) + local expected = join_path(d, item) + if funcname == 'finddir' then mkdir(expected) else write_file(expected, '') end - eq(expected, funcs['find' .. option](item, folder_path:gsub(' ', [[\ ]]))) + eq(expected, funcs[funcname](item, d:gsub(' ', [[\ ]]))) end it('finddir()', function() - test_find_func('dir', 'directory', 'folder') - test_find_func('dir', 'directory', 'folder name') - test_find_func('dir', 'fold#er name', 'directory') + test_find_func('finddir', 'directory', 'folder') + test_find_func('finddir', 'directory', 'folder name') + test_find_func('finddir', 'fold#er name', 'directory') end) it('findfile()', function() - test_find_func('file', 'directory', 'file.txt') - test_find_func('file', 'directory', 'file name.txt') - test_find_func('file', 'fold#er name', 'file.txt') + test_find_func('findfile', 'directory', 'file.txt') + test_find_func('findfile', 'directory', 'file name.txt') + test_find_func('findfile', 'fold#er name', 'file.txt') end) end) -- cgit From 1c71c32b29100b3e2989447da9d94b97b2c9959e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 8 Nov 2023 06:29:58 +0800 Subject: fix(job-control): make jobwait() flush UI after hiding cursor (#25927) --- test/functional/core/job_spec.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 613dff577a..befbd4bc3b 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -700,7 +700,7 @@ describe('jobs', function() os.remove('Xtest_jobstart_env') end) - describe('jobwait', function() + describe('jobwait()', function() before_each(function() if is_os('win') then helpers.set_shell_powershell() @@ -874,6 +874,27 @@ describe('jobs', function() eq({'notification', 'wait', {{-1, -1}}}, next_msg()) end) end) + + it('hides cursor when waiting', function() + local screen = Screen.new(30, 3) + screen:set_default_attr_ids({ + [0] = {foreground = Screen.colors.Blue1, bold = true}; + }) + screen:attach() + command([[let g:id = jobstart([v:progpath, '--clean', '--headless'])]]) + feed_command('call jobwait([g:id], 300)') + screen:expect{grid=[[ + | + {0:~ }| + :call jobwait([g:id], 300) | + ]], timeout=100} + funcs.jobstop(meths.get_var('id')) + screen:expect{grid=[[ + ^ | + {0:~ }| + :call jobwait([g:id], 300) | + ]]} + end) end) pending('exit event follows stdout, stderr', function() -- cgit From d5a85d737aa2a5c3a64ef0aa5b01672b7ed49c09 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 15:24:36 +0800 Subject: fix(f_wait): flush UI before blocking (#25962) --- test/functional/core/job_spec.lua | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index befbd4bc3b..038368c387 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -875,25 +875,41 @@ describe('jobs', function() end) end) - it('hides cursor when waiting', function() - local screen = Screen.new(30, 3) + it('hides cursor and flushes messages before blocking', function() + local screen = Screen.new(50, 6) screen:set_default_attr_ids({ - [0] = {foreground = Screen.colors.Blue1, bold = true}; + [0] = {foreground = Screen.colors.Blue, bold = true}; -- NonText + [1] = {bold = true, reverse = true}; -- MsgSeparator + [2] = {bold = true, foreground = Screen.colors.SeaGreen}; -- MoreMsg }) screen:attach() command([[let g:id = jobstart([v:progpath, '--clean', '--headless'])]]) - feed_command('call jobwait([g:id], 300)') + source([[ + func PrintAndWait() + echon "aaa\nbbb" + call jobwait([g:id], 300) + echon "\nccc" + endfunc + ]]) + feed_command('call PrintAndWait()') screen:expect{grid=[[ - | - {0:~ }| - :call jobwait([g:id], 300) | + | + {0:~ }| + {0:~ }| + {1: }| + aaa | + bbb | ]], timeout=100} - funcs.jobstop(meths.get_var('id')) screen:expect{grid=[[ - ^ | - {0:~ }| - :call jobwait([g:id], 300) | + | + {1: }| + aaa | + bbb | + ccc | + {2:Press ENTER or type command to continue}^ | ]]} + feed('') + funcs.jobstop(meths.get_var('id')) end) end) -- cgit From 5b45efbee6ebb64269469b636baac5248e83421f Mon Sep 17 00:00:00 2001 From: Ploum <1233155+ploum@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:56:50 +0100 Subject: fix(defaults): set 'fsync' #26034 Problem: 'nofsync' may lose data if the system has a hard shutdown. #9888 Solution: Change default to 'fsync'. This may be revisited in the future when 'nofsync' can be made safer. --- test/functional/core/fileio_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index a23dad226a..65f947132e 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -51,6 +51,7 @@ describe('fileio', function() it('fsync() codepaths #8304', function() clear({ args={ '-i', 'Xtest_startup_shada', + '--cmd', 'set nofsync', '--cmd', 'set directory=Xtest_startup_swapdir' } }) -- These cases ALWAYS force fsync (regardless of 'fsync' option): -- cgit