From 2d6735d8cecc587eb5549f65260ee9ddeb8e1d78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 9 Sep 2022 00:12:42 +0200 Subject: ci: move BSD jobs from sourcehut to Cirrus CI #19616 dispatch.sr.ht is being deprecated, meaning that using sourcehut CI won't be possible (see https://github.com/neovim/neovim/issues/19609). Since Github Actions doesn't provide any BSD runners an external service is required and Cirrus CI seems like a good replacement for sourcehut. Initially experimented with using FreeBSD and OpenBSD virtual machines in GitHub Actions, but Cirrus has been a much better fit with better performance, logs and overall experience. Failing tests are automatically skipped on FreeBSD regardless if it's on CI or not. Ideally these tests should only be skipped in CI with the help of `isCI` helper function. Unfortunately, the tests don't recognize the environment variable CIRRUS_CI even if it's set manually. This workaround is good enough for the time being, but we might want to only skip tests when using the CI (or even better, fix the failing tests). Closes: https://github.com/neovim/neovim/issues/19609 --- test/functional/core/fileio_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index a4d22685e8..e71131dcf8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -23,6 +23,7 @@ local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit local write_file = helpers.write_file +local uname = helpers.uname describe('fileio', function() before_each(function() @@ -83,6 +84,9 @@ describe('fileio', function() end) it('backup #9709', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -102,6 +106,9 @@ describe('fileio', function() end) it('backup with full path #11214', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end clear() mkdir('Xtest_backupdir') command('set backup') -- cgit From 3c3f3e7353ba2cb9071183cd05036ca2a98d3672 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 16:17:51 +0800 Subject: test(remote_spec): reduce flakiness in waiting for client exit (#20230) It is less likely for client to exit between jobstart() and jobwait() if they are invoked in the same RPC request instead of two separate ones. --- 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 d7bd075eb2..846d79abf3 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local exec_lua = helpers.exec_lua local expect = helpers.expect local funcs = helpers.funcs local insert = helpers.insert @@ -48,8 +49,8 @@ describe('Remote', function() -- our incoming --remote calls. local client_starter = spawn(new_argv(), false, nil, true) set_session(client_starter) - local client_job_id = funcs.jobstart(client_argv) - eq({ 0 }, funcs.jobwait({client_job_id})) + -- 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)) client_starter:close() set_session(server) end @@ -121,8 +122,8 @@ describe('Remote', function() -- the event loop. If the server event loop is blocked, it can't process -- our incoming --remote calls. clear() - local bogus_job_id = funcs.jobstart(bogus_argv) - eq({2}, funcs.jobwait({bogus_job_id})) + -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. + eq({ 2 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], bogus_argv)) end it('bogus subcommand', function() run_and_check_exit_code('--remote-bogus') -- cgit From 2a3cb0893b03aeff4d8c0b2116cbddda53bba5a2 Mon Sep 17 00:00:00 2001 From: Louis Sven Goulet <31444858+lorlouis@users.noreply.github.com> Date: Sat, 24 Sep 2022 21:57:10 -0400 Subject: feat: ":write!" skips "file changed" warning #18665 Problem: Cannot opt-out of "WARNING: The file has been changed since reading it!!!", even with ":write!". Solution: Change ":write!" to skip the warning. closes #7270 --- test/functional/core/fileio_spec.lua | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index e71131dcf8..a589d088a4 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -23,6 +23,8 @@ local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit local write_file = helpers.write_file +local Screen = require('test.functional.ui.screen') +local feed_command = helpers.feed_command local uname = helpers.uname describe('fileio', function() @@ -36,6 +38,7 @@ describe('fileio', function() os.remove('Xtest_startup_file2') os.remove('Xtest_тест.md') os.remove('Xtest-u8-int-max') + os.remove('Xtest-overwrite-forced') rmdir('Xtest_startup_swapdir') rmdir('Xtest_backupdir') end) @@ -151,6 +154,61 @@ describe('fileio', function() command('edit ++enc=utf32 Xtest-u8-int-max') assert_alive() end) + + it(':w! does not show "file has been changed" warning', function() + clear() + write_file("Xtest-overwrite-forced", 'foobar') + command('set nofixendofline') + local screen = Screen.new(40,4) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [3] = {bold = true, foreground = Screen.colors.SeaGreen4} + }) + screen:attach() + command("set display-=msgsep shortmess-=F") + + command("e Xtest-overwrite-forced") + screen:expect([[ + ^foobar | + {1:~ }| + {1:~ }| + "Xtest-overwrite-forced" [noeol] 1L, 6B | + ]]) + + -- Get current unix time. + local cur_unix_time = os.time(os.date("!*t")) + local future_time = cur_unix_time + 999999 + -- Set the file's access/update time to be + -- greater than the time at which it was created. + local uv = require("luv") + uv.fs_utime('Xtest-overwrite-forced', future_time, future_time) + -- use async feed_command because nvim basically hangs on the prompt + feed_command("w") + screen:expect([[ + {2:WARNING: The file has been changed since}| + {2: reading it!!!} | + {3:Do you really want to write to it (y/n)^?}| + | + ]]) + + feed("n") + feed("") + screen:expect([[ + ^foobar | + {1:~ }| + {1:~ }| + | + ]]) + -- Use a screen test because the warning does not set v:errmsg. + command("w!") + screen:expect([[ + ^foobar | + {1:~ }| + {1:~ }| + Date: Sun, 25 Sep 2022 02:20:47 +0200 Subject: feat(gen_help_html.lua): adapt to new parser - adapt to parser changes from https://github.com/vigoux/tree-sitter-vimdoc/pull/16 - numerous other generator improvements --- test/functional/core/startup_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 4f9df4010e..a32c801c97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -354,7 +354,9 @@ describe('startup', function() local function pack_clear(cmd) -- add packages after config dir in rtp but before config/after - clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} + clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}, + args_rm={'runtimepath'}, + } end -- cgit From 6ae144a92171cf9ae52bddddc3a081a4efaabe9f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 27 Sep 2022 16:19:15 +0200 Subject: feat(messages)!: graduate the 'msgsep' feature The old behaviour (e.g. via `set display-=msgsep`) will not be available. Assuming that messages always are being drawn on msg_grid (or not drawn at all, and forwarded to `ext_messages` enabled UI) will allows some simplifcations and enhancements moving forward. --- 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 a589d088a4..d1ff5b8036 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -166,7 +166,7 @@ describe('fileio', function() [3] = {bold = true, foreground = Screen.colors.SeaGreen4} }) screen:attach() - command("set display-=msgsep shortmess-=F") + command("set shortmess-=F") command("e Xtest-overwrite-forced") screen:expect([[ -- cgit From cfdb4cbada8c65aa57e69776bcc0f7b8b298317a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 7 Oct 2022 09:43:16 +0800 Subject: fix: find multibyte file name in line (#20519) And remove unnecessary unsigned casts in fold marker comparison. --- test/functional/core/path_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 669bc99136..61fae7622c 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -4,6 +4,8 @@ local eq = helpers.eq local eval = helpers.eval local command = helpers.command local iswin = helpers.iswin +local insert = helpers.insert +local feed = helpers.feed describe('path collapse', function() local targetdir @@ -54,3 +56,15 @@ describe('path collapse', function() eq(expected_path, eval('expand("%:p")')) end) end) + +describe('file search', function() + before_each(clear) + + it('find multibyte file name in line #20517', function() + command('cd test/functional/fixtures') + insert('filename_with_unicode_ααα') + eq('', eval('expand("%")')) + feed('gf') + eq('filename_with_unicode_ααα', eval('expand("%:t")')) + end) +end) -- cgit From 5046b4b4adb154bbdb50a5e96e29f777b5f807ac Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 17 Oct 2022 17:16:31 +0200 Subject: ci: add cirrus to isCI function to skip tests (#20526) The environment variable CIRRUS_CI is manually passed to RunTests.cmake as it doesn't get passed when using cmake script mode. --- test/functional/core/fileio_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index d1ff5b8036..07774866a8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -25,7 +25,7 @@ local expect_exit = helpers.expect_exit local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') local feed_command = helpers.feed_command -local uname = helpers.uname +local isCI = helpers.isCI describe('fileio', function() before_each(function() @@ -87,8 +87,8 @@ describe('fileio', function() end) it('backup #9709', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -109,8 +109,8 @@ describe('fileio', function() end) it('backup with full path #11214', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end clear() mkdir('Xtest_backupdir') -- cgit From 4716a578ae0c3516d685495bb55e40c939a4ac87 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 23 Oct 2022 10:17:45 +0200 Subject: docs: fix typos --- test/functional/core/startup_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index a32c801c97..2084d365a5 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -637,7 +637,7 @@ describe('runtime:', function() end) it('loads plugin/*.lua from start packages', function() - local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory', + local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category', 'start', 'test_plugin'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, -- cgit From 19a487bc86482392eb50c61375d20e440e6e16b7 Mon Sep 17 00:00:00 2001 From: Will Spurgin Date: Fri, 4 Nov 2022 20:24:34 -0500 Subject: fix(fileio): use first available directory in backupdir for backupcopy (#20655) Fix backups failing for symlink files Set backup to NULL prior to continuing & Clear backup prior to NULL set to avoid leaking Fixes #11349 Remove testing hacks in scripts for windows Skip FreeBSD Something appears up with these types of tests for FreeBSD on Circus, see 2d6735d8ce --- test/functional/core/fileio_spec.lua | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 07774866a8..795f639dad 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -1,3 +1,4 @@ +local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log @@ -5,6 +6,7 @@ local assert_nolog = helpers.assert_nolog local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local neq = helpers.neq local ok = helpers.ok local feed = helpers.feed local funcs = helpers.funcs @@ -132,6 +134,57 @@ describe('fileio', function() eq('foo', foo_contents); end) + it('backup symlinked files #11349', function() + if isCI('cirrus') then + pending('FIXME: cirrus') + end + clear() + + local initial_content = 'foo' + local link_file_name = 'Xtest_startup_file2' + local backup_file_name = link_file_name .. '~' + + write_file('Xtest_startup_file1', initial_content, false) + lfs.link('Xtest_startup_file1', link_file_name, true) + command('set backup') + command('set backupcopy=yes') + command('edit ' .. link_file_name) + feed('Abar') + command('write') + + local backup_raw = read_file(backup_file_name) + neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. "to exist but did not") + eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents') + end) + + + it('backup symlinked files in first avialable backupdir #11349', function() + if isCI('cirrus') then + pending('FIXME: cirrus') + end + clear() + + local initial_content = 'foo' + local backup_dir = 'Xtest_backupdir' + local sep = helpers.get_pathsep() + local link_file_name = 'Xtest_startup_file2' + 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) + mkdir(backup_dir) + command('set backup') + command('set backupcopy=yes') + command('set backupdir=.__this_does_not_exist__,' .. backup_dir) + command('edit ' .. link_file_name) + feed('Abar') + command('write') + + local backup_raw = read_file(backup_file_name) + neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. " to exist but did not") + eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents') + end) + it('readfile() on multibyte filename #10586', function() clear() local text = { -- cgit From 736c36c02f316c979da363c5120495179a2b6c2a Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 13 Nov 2022 14:52:19 +0100 Subject: test: introduce skip() #21010 This is essentially a convenience wrapper around the `pending()` function, similar to `skip_fragile()` but more general-purpose. Also remove `pending_win32` function as it can be replaced by `skip(iswin())`. --- test/functional/core/channels_spec.lua | 6 ++++-- test/functional/core/fileio_spec.lua | 21 ++++++--------------- test/functional/core/job_spec.lua | 11 ++++++----- test/functional/core/main_spec.lua | 4 +++- 4 files changed, 19 insertions(+), 23 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index ca52404d3b..63bd85ff43 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -12,6 +12,8 @@ local retry = helpers.retry local expect_twostreams = helpers.expect_twostreams local assert_alive = helpers.assert_alive local pcall_err = helpers.pcall_err +local iswin = helpers.iswin +local skip = helpers.skip describe('channels', function() local init = [[ @@ -145,7 +147,7 @@ describe('channels', function() end it('can use stdio channel with pty', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -199,7 +201,7 @@ describe('channels', function() it('stdio channel can use rpc and stderr simultaneously', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) source([[ let g:job_opts = { \ 'on_stderr': function('OnEvent'), diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 795f639dad..00b9074e29 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -28,6 +28,7 @@ local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') local feed_command = helpers.feed_command local isCI = helpers.isCI +local skip = helpers.skip describe('fileio', function() before_each(function() @@ -89,9 +90,7 @@ describe('fileio', function() end) it('backup #9709', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -111,9 +110,7 @@ describe('fileio', function() end) it('backup with full path #11214', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear() mkdir('Xtest_backupdir') command('set backup') @@ -135,9 +132,7 @@ describe('fileio', function() end) it('backup symlinked files #11349', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear() local initial_content = 'foo' @@ -159,9 +154,7 @@ describe('fileio', function() it('backup symlinked files in first avialable backupdir #11349', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear() local initial_content = 'foo' @@ -306,9 +299,7 @@ describe('tmpdir', function() end) -- "…/nvim./" has wrong permissions: - if iswin() then - return -- TODO(justinmk): need setfperm/getfperm on Windows. #8244 - end + skip(iswin(), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') os.remove(testlog) os.remove(tmproot) mkdir(tmproot) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 02ff18bdda..4e5c4ca351 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -23,6 +23,7 @@ local expect_msg_seq = helpers.expect_msg_seq local pcall_err = helpers.pcall_err local matches = helpers.matches local Screen = require('test.functional.ui.screen') +local skip = helpers.skip describe('jobs', function() local channel @@ -87,7 +88,7 @@ describe('jobs', function() end) it('append environment with pty #env', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.pty = v:true") @@ -225,7 +226,7 @@ describe('jobs', function() end) it('error on non-executable `cwd`', function() - if iswin() then return end -- N/A for Windows + skip(iswin(), 'Not applicable for Windows') local dir = 'Xtest_not_executable_dir' mkdir(dir) @@ -805,7 +806,7 @@ describe('jobs', function() end) it('can be called recursively', function() - if helpers.pending_win32(pending) then return end -- TODO: Need `cat`. + skip(iswin(), "TODO: Need `cat`") source([[ let g:opts = {} let g:counter = 0 @@ -1027,7 +1028,7 @@ describe('jobs', function() end) describe('running tty-test program', function() - if helpers.pending_win32(pending) then return end + if skip(iswin()) then return end local function next_chunk() local rv while true do @@ -1124,7 +1125,7 @@ describe("pty process teardown", function() end) it("does not prevent/delay exit. #4798 #4900", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) -- Use a nested nvim (in :term) to test without --headless. feed_command(":terminal '"..helpers.nvim_prog .."' -u NONE -i NONE --cmd '"..nvim_set.."' " diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index f6fb859ccc..782a03bfed 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -9,6 +9,8 @@ local clear = helpers.clear local funcs = helpers.funcs local nvim_prog_abs = helpers.nvim_prog_abs local write_file = helpers.write_file +local iswin = helpers.iswin +local skip = helpers.skip describe('Command-line option', function() describe('-s', function() @@ -49,7 +51,7 @@ describe('Command-line option', function() eq(#('100500\n'), attrs.size) end) it('does not crash after reading from stdin in non-headless mode', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) local screen = Screen.new(40, 8) screen:attach() local args = { -- cgit From 5eb5f4948826e9d47685ea9e257409cc3e693614 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 22 Nov 2022 01:13:30 +0100 Subject: test: simplify platform detection (#21020) Extend the capabilities of is_os to detect more platforms such as freebsd and openbsd. Also remove `iswin()` helper function as it can be replaced by `is_os("win")`. --- test/functional/core/channels_spec.lua | 9 +++---- test/functional/core/fileio_spec.lua | 16 ++++++------ test/functional/core/job_spec.lua | 48 +++++++++++++++++----------------- test/functional/core/main_spec.lua | 4 +-- test/functional/core/path_spec.lua | 4 +-- test/functional/core/startup_spec.lua | 12 ++++----- 6 files changed, 45 insertions(+), 48 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 63bd85ff43..8275575c24 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local uname = helpers.uname local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths @@ -12,7 +11,6 @@ local retry = helpers.retry local expect_twostreams = helpers.expect_twostreams local assert_alive = helpers.assert_alive local pcall_err = helpers.pcall_err -local iswin = helpers.iswin local skip = helpers.skip describe('channels', function() @@ -147,7 +145,7 @@ describe('channels', function() end it('can use stdio channel with pty', function() - skip(iswin()) + skip(is_os('win')) source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -180,8 +178,7 @@ describe('channels', function() command("call chansend(id, 'incomplet\004')") - local is_bsd = not not string.find(uname(), 'bsd') - local bsdlike = is_bsd or is_os('mac') + local bsdlike = is_os('bsd') or is_os('mac') local extra = bsdlike and "^D\008\008" or "" expect_twoline(id, "stdout", "incomplet"..extra, "[1, ['incomplet'], 'stdin']", true) @@ -201,7 +198,7 @@ describe('channels', function() it('stdio channel can use rpc and stderr simultaneously', function() - skip(iswin()) + skip(is_os('win')) source([[ let g:job_opts = { \ 'on_stderr': function('OnEvent'), diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 00b9074e29..51189b7c32 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -21,14 +21,14 @@ local read_file = helpers.read_file local tmpname = helpers.tmpname local trim = helpers.trim local currentdir = helpers.funcs.getcwd -local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') local feed_command = helpers.feed_command -local isCI = helpers.isCI local skip = helpers.skip +local is_os = helpers.is_os +local is_ci = helpers.is_ci describe('fileio', function() before_each(function() @@ -90,7 +90,7 @@ describe('fileio', function() end) it('backup #9709', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -110,7 +110,7 @@ describe('fileio', function() end) it('backup with full path #11214', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear() mkdir('Xtest_backupdir') command('set backup') @@ -123,7 +123,7 @@ describe('fileio', function() -- Backup filename = fullpath, separators replaced with "%". local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1', - iswin() and '[:/\\]' or '/', '%%') .. '~' + is_os('win') and '[:/\\]' or '/', '%%') .. '~' local foo_contents = trim(read_file('Xtest_backupdir/'..backup_file_name)) local foobar_contents = trim(read_file('Xtest_startup_file1')) @@ -132,7 +132,7 @@ describe('fileio', function() end) it('backup symlinked files #11349', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear() local initial_content = 'foo' @@ -154,7 +154,7 @@ describe('fileio', function() it('backup symlinked files in first avialable backupdir #11349', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear() local initial_content = 'foo' @@ -299,7 +299,7 @@ describe('tmpdir', function() end) -- "…/nvim./" has wrong permissions: - skip(iswin(), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') + skip(is_os('win'), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') os.remove(testlog) os.remove(tmproot) mkdir(tmproot) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 4e5c4ca351..1bae626b98 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -13,7 +13,6 @@ local retry = helpers.retry local meths = helpers.meths local NIL = helpers.NIL local poke_eventloop = helpers.poke_eventloop -local iswin = helpers.iswin local get_pathsep = helpers.get_pathsep local pathroot = helpers.pathroot local exec_lua = helpers.exec_lua @@ -24,6 +23,7 @@ local pcall_err = helpers.pcall_err local matches = helpers.matches local Screen = require('test.functional.ui.screen') local skip = helpers.skip +local is_os = helpers.is_os describe('jobs', function() local channel @@ -56,7 +56,7 @@ describe('jobs', function() it('must specify env option as a dict', function() command("let g:job_opts.env = v:true") local _, err = pcall(function() - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('set', g:job_opts)") else nvim('command', "let j = jobstart('env', g:job_opts)") @@ -69,7 +69,7 @@ describe('jobs', function() nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - if iswin() then + if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) @@ -88,12 +88,12 @@ describe('jobs', function() end) it('append environment with pty #env', function() - skip(iswin()) + skip(is_os('win')) nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.pty = v:true") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - if iswin() then + if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) @@ -123,7 +123,7 @@ describe('jobs', function() -- -- Rather than expecting a completely empty environment, ensure that $VAR -- is *not* in the environment but $TOTO is. - if iswin() then + if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) expect_msg_seq({ {'notification', 'stdout', {0, {'hello world %VAR%', ''}}} @@ -142,7 +142,7 @@ describe('jobs', function() -- Since $Toto is being set in the job, it should take precedence over the -- global $TOTO on Windows nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") - if iswin() then + if is_os('win') then nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]]) else nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) @@ -151,7 +151,7 @@ describe('jobs', function() nvim('command', "let g:output = Normalize(g:job_opts.stdout)") local actual = eval('g:output') local expected - if iswin() then + if is_os('win') then -- Toto is normalized to TOTO so we can detect duplicates, and because -- Windows doesn't care about case expected = {'TOTO=def', ''} @@ -165,7 +165,7 @@ describe('jobs', function() it('uses &shell and &shellcmdflag if passed a string', function() nvim('command', "let $VAR = 'abc'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('echo %VAR%', g:job_opts)") else nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") @@ -177,7 +177,7 @@ describe('jobs', function() it('changes to given / directory', function() nvim('command', "let g:job_opts.cwd = '/'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('cd', g:job_opts)") else nvim('command', "let j = jobstart('pwd', g:job_opts)") @@ -192,7 +192,7 @@ describe('jobs', function() local dir = eval("resolve(tempname())"):gsub("/", get_pathsep()) mkdir(dir) nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('cd', g:job_opts)") else nvim('command', "let j = jobstart('pwd', g:job_opts)") @@ -216,7 +216,7 @@ describe('jobs', function() local dir = eval('resolve(tempname())."-bogus"') local _, err = pcall(function() nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('cd', g:job_opts)") else nvim('command', "let j = jobstart('pwd', g:job_opts)") @@ -226,7 +226,7 @@ describe('jobs', function() end) it('error on non-executable `cwd`', function() - skip(iswin(), 'Not applicable for Windows') + skip(is_os('win'), 'Not applicable for Windows') local dir = 'Xtest_not_executable_dir' mkdir(dir) @@ -249,7 +249,7 @@ describe('jobs', function() end local executable_jobid = new_job() - local exe = iswin() and './test/functional/fixtures' or './test/functional/fixtures/non_executable.txt' + local exe = is_os('win') and './test/functional/fixtures' or './test/functional/fixtures/non_executable.txt' eq("Vim:E475: Invalid value for argument cmd: '"..exe.."' is not executable", pcall_err(eval, "jobstart(['"..exe.."'])")) eq("", eval("v:errmsg")) @@ -703,7 +703,7 @@ describe('jobs', function() describe('jobwait', function() before_each(function() - if iswin() then + if is_os('win') then helpers.set_shell_powershell() end end) @@ -787,7 +787,7 @@ describe('jobs', function() feed_command('call rpcnotify(g:channel, "ready") | '.. 'call rpcnotify(g:channel, "wait", '.. 'jobwait([jobstart("'.. - (iswin() and 'Start-Sleep 10' or 'sleep 10').. + (is_os('win') and 'Start-Sleep 10' or 'sleep 10').. '; exit 55")]))') eq({'notification', 'ready', {}}, next_msg()) feed('') @@ -798,7 +798,7 @@ describe('jobs', function() feed_command('call rpcnotify(g:channel, "ready") | '.. 'call rpcnotify(g:channel, "wait", '.. 'jobwait([jobstart("'.. - (iswin() and 'Start-Sleep 10' or 'sleep 10').. + (is_os('win') and 'Start-Sleep 10' or 'sleep 10').. '; exit 55")], 10000))') eq({'notification', 'ready', {}}, next_msg()) feed('') @@ -806,7 +806,7 @@ describe('jobs', function() end) it('can be called recursively', function() - skip(iswin(), "TODO: Need `cat`") + skip(is_os('win'), "TODO: Need `cat`") source([[ let g:opts = {} let g:counter = 0 @@ -931,7 +931,7 @@ describe('jobs', function() -- ..c.."', '-c', '"..c.."'])") -- Create child with several descendants. - if iswin() then + if is_os('win') then source([[ function! s:formatprocs(pid, prefix) let result = '' @@ -980,13 +980,13 @@ describe('jobs', function() endfunction ]]) end - local sleep_cmd = (iswin() + local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30') local j = eval("jobstart('"..sleep_cmd..' | '..sleep_cmd..' | '..sleep_cmd.."')") local ppid = funcs.jobpid(j) local children - if iswin() then + if is_os('win') then local status, result = pcall(retry, nil, nil, function() children = meths.get_proc_children(ppid) -- On Windows conhost.exe may exist, and @@ -1007,7 +1007,7 @@ describe('jobs', function() -- Assert that nvim_get_proc() sees the children. for _, child_pid in ipairs(children) do local info = meths.get_proc(child_pid) - -- eq((iswin() and 'nvim.exe' or 'nvim'), info.name) + -- eq((is_os('win') and 'nvim.exe' or 'nvim'), info.name) eq(ppid, info.ppid) end -- Kill the root of the tree. @@ -1028,7 +1028,7 @@ describe('jobs', function() end) describe('running tty-test program', function() - if skip(iswin()) then return end + if skip(is_os('win')) then return end local function next_chunk() local rv while true do @@ -1125,7 +1125,7 @@ describe("pty process teardown", function() end) it("does not prevent/delay exit. #4798 #4900", function() - skip(iswin()) + skip(is_os('win')) -- Use a nested nvim (in :term) to test without --headless. feed_command(":terminal '"..helpers.nvim_prog .."' -u NONE -i NONE --cmd '"..nvim_set.."' " diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 782a03bfed..53461f505a 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -9,7 +9,7 @@ local clear = helpers.clear local funcs = helpers.funcs local nvim_prog_abs = helpers.nvim_prog_abs local write_file = helpers.write_file -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip describe('Command-line option', function() @@ -51,7 +51,7 @@ describe('Command-line option', function() eq(#('100500\n'), attrs.size) end) it('does not crash after reading from stdin in non-headless mode', function() - skip(iswin()) + skip(is_os('win')) local screen = Screen.new(40, 8) screen:attach() local args = { diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 61fae7622c..a786887bbd 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -3,16 +3,16 @@ local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval local command = helpers.command -local iswin = helpers.iswin local insert = helpers.insert local feed = helpers.feed +local is_os = helpers.is_os describe('path collapse', function() local targetdir local expected_path local function join_path(...) - local pathsep = (iswin() and '\\' or '/') + local pathsep = (is_os('win') and '\\' or '/') return table.concat({...}, pathsep) end diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 2084d365a5..bab339e253 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -20,11 +20,11 @@ local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir local sleep = helpers.sleep -local iswin = helpers.iswin local startswith = helpers.startswith local write_file = helpers.write_file local meths = helpers.meths local alter_slashes = helpers.alter_slashes +local is_os = helpers.is_os local testfile = 'Xtest_startuptime' after_each(function() @@ -79,7 +79,7 @@ describe('startup', function() it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 4) screen:attach() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -95,7 +95,7 @@ describe('startup', function() ]]) end) it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -111,7 +111,7 @@ describe('startup', function() end) end) it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -130,7 +130,7 @@ describe('startup', function() it('input from pipe (implicit) #7679', function() local screen = Screen.new(25, 4) screen:attach() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -665,7 +665,7 @@ describe('runtime:', function() end) it('loads plugin/*.lua from site packages', function() - local nvimdata = iswin() and "nvim-data" or "nvim" + local nvimdata = is_os('win') and "nvim-data" or "nvim" local plugin_path = table.concat({xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) local plugin_after_path = table.concat({plugin_path, 'after', 'plugin'}, pathsep) -- cgit From 3f478547cfec72b9d3eb53efde2df45d85c44c18 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Sat, 26 Nov 2022 01:50:52 +0100 Subject: fix(startup): support .exrc or .nvimrc with init.lua (#21181) --- test/functional/core/startup_spec.lua | 64 +++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index bab339e253..41596f5416 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -12,6 +12,7 @@ local eval = helpers.eval local exec_lua = helpers.exec_lua local feed = helpers.feed local funcs = helpers.funcs +local pesc = helpers.pesc local mkdir = helpers.mkdir local mkdir_p = helpers.mkdir_p local nvim_prog = helpers.nvim_prog @@ -576,7 +577,66 @@ describe('user config init', function() eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) end) - describe 'with explicitly provided config'(function() + describe('with existing .exrc in cwd', function() + local exrc_path = '.exrc' + local xstate = 'Xstate' + + before_each(function() + write_file(init_lua_path, [[ + vim.o.exrc = true + vim.g.from_exrc = 0 + ]]) + mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + write_file(exrc_path, [[ + let g:from_exrc = 1 + ]]) + end) + + after_each(function() + os.remove(exrc_path) + rmdir(xstate) + end) + + it('loads .exrc #13501', function() + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The .exrc file is not trusted, and the prompt is skipped because there is no UI. + eq(0, eval('g:from_exrc')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) + -- `i` to enter Terminal mode, `a` to allow + feed('ia') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + | + -- TERMINAL -- | + ]]) + feed(':echo g:from_exrc') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + 1 | + -- TERMINAL -- | + ]]) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The .exrc file is now trusted. + eq(1, eval('g:from_exrc')) + end) + end) + + describe('with explicitly provided config', function() local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep) before_each(function() write_file(custom_lua_path, [[ @@ -591,7 +651,7 @@ describe('user config init', function() end) end) - describe 'VIMRC also exists'(function() + describe('VIMRC also exists', function() before_each(function() write_file(table.concat({xconfig, 'nvim', 'init.vim'}, pathsep), [[ let g:vim_rc = 1 -- cgit From 615f124003376c007442319b31a172360796974c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 29 Nov 2022 02:45:48 +0100 Subject: docs: fix typos (#21196) Co-authored-by: zeertzjq Co-authored-by: Raphael Co-authored-by: Gregory Anders --- 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 51189b7c32..ed37032f25 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -153,7 +153,7 @@ describe('fileio', function() end) - it('backup symlinked files in first avialable backupdir #11349', function() + it('backup symlinked files in first available backupdir #11349', function() skip(is_ci('cirrus')) clear() -- cgit From 03166838abf23e3c2de55333fb2b9b0af34a2c56 Mon Sep 17 00:00:00 2001 From: Munif Tanjim Date: Tue, 20 Dec 2022 06:38:24 +0600 Subject: test(exrc): add tests for .nvimrc and .nvim.lua (#21478) --- test/functional/core/startup_spec.lua | 97 ++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 41596f5416..7664401824 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -581,15 +581,26 @@ describe('user config init', function() local exrc_path = '.exrc' local xstate = 'Xstate' + local function setup_exrc_file(filename) + exrc_path = filename + + if string.find(exrc_path, "%.lua$") then + write_file(exrc_path, string.format([[ + vim.g.exrc_file = "%s" + ]], exrc_path)) + else + write_file(exrc_path, string.format([[ + let g:exrc_file = "%s" + ]], exrc_path)) + end + end + before_each(function() write_file(init_lua_path, [[ vim.o.exrc = true - vim.g.from_exrc = 0 + vim.g.exrc_file = '---' ]]) mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - write_file(exrc_path, [[ - let g:from_exrc = 1 - ]]) end) after_each(function() @@ -597,43 +608,47 @@ describe('user config init', function() rmdir(xstate) end) - it('loads .exrc #13501', function() - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } - -- The .exrc file is not trusted, and the prompt is skipped because there is no UI. - eq(0, eval('g:from_exrc')) - - local screen = Screen.new(50, 8) - screen:attach() - funcs.termopen({nvim_prog}) - screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) - -- `i` to enter Terminal mode, `a` to allow - feed('ia') - screen:expect([[ - | - ~ | - ~ | - ~ | - ~ | - [No Name] 0,0-1 All| - | - -- TERMINAL -- | - ]]) - feed(':echo g:from_exrc') - screen:expect([[ - | - ~ | - ~ | - ~ | - ~ | - [No Name] 0,0-1 All| - 1 | - -- TERMINAL -- | - ]]) - - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } - -- The .exrc file is now trusted. - eq(1, eval('g:from_exrc')) - end) + for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do + it('loads ' .. filename, function () + setup_exrc_file(filename) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI. + eq('---', eval('g:exrc_file')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) + -- `i` to enter Terminal mode, `a` to allow + feed('ia') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + | + -- TERMINAL -- | + ]]) + feed(':echo g:exrc_file') + screen:expect(string.format([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + %s%s| + -- TERMINAL -- | + ]], filename, string.rep(' ', 50 - #filename))) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The 'exrc' file is now trusted. + eq(filename, eval('g:exrc_file')) + end) + end end) describe('with explicitly provided config', function() -- cgit From d7855caa183f9eacc7cfd3f2ab7f071063ff84af Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 30 Dec 2022 15:06:47 +0800 Subject: test: add test for setting &columns from modeline with tabpages --- test/functional/core/startup_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 7664401824..9e22efa545 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -465,6 +465,19 @@ describe('startup', function() clear{args={'--cmd', 'set packpath^=test/functional/fixtures', '--cmd', [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]]}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} eq({'ordinary', 'FANCY', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) end) + + it('window widths are correct when modelines set &columns with tabpages', function() + write_file('tab1.noft', 'vim: columns=81') + write_file('tab2.noft', 'vim: columns=81') + finally(function() + os.remove('tab1.noft') + os.remove('tab2.noft') + end) + clear({args = {'-p', 'tab1.noft', 'tab2.noft'}}) + eq(81, meths.win_get_width(0)) + command('tabnext') + eq(81, meths.win_get_width(0)) + end) end) describe('sysinit', function() -- cgit From 43e8ec92de9e0850e7d202cb7ff9051bc408447e Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 2 May 2022 21:10:01 +0200 Subject: fix(tui): more work in the TUI --- test/functional/core/main_spec.lua | 2 +- test/functional/core/startup_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 53461f505a..ab11e14a67 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -56,7 +56,7 @@ describe('Command-line option', function() screen:attach() local args = { nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', - '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', + '--cmd', '"set noswapfile shortmess+=IFW fileformats=unix"', '-s', '-' } diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 9e22efa545..72d8f3a103 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -544,7 +544,7 @@ describe('sysinit', function() nvim_exec() | cmd: aunmenu * | > | - <" -u NONE -i NONE --cmd "set noruler" -D 1,1 All| + <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| | ]]) command([[call chansend(g:id, "cont\n")]]) -- cgit From 7c94bcd2d77e2e54b8836ab8325460a367b79eae Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 20 Sep 2021 19:00:50 -0700 Subject: feat(lua)!: execute Lua with "nvim -l" Problem: Nvim has Lua but the "nvim" CLI can't easily be used to execute Lua scripts, especially scripts that take arguments or produce output. Solution: - support "nvim -l [args...]" for running scripts. closes #15749 - exit without +q - remove lua2dox_filter - remove Doxyfile. This wasn't used anyway, because the doxygen config is inlined in gen_vimdoc.py (`Doxyfile` variable). - use "nvim -l" in docs-gen CI job Examples: $ nvim -l scripts/lua2dox.lua --help Lua2DoX (0.2 20130128) ... $ echo "print(vim.inspect(_G.arg))" | nvim -l - --arg1 --arg2 $ echo 'print(vim.inspect(vim.api.nvim_buf_get_text(1,0,0,-1,-1,{})))' | nvim +"put ='text'" -l - TODO? -e executes Lua code -l loads a module -i enters REPL _after running the other arguments_. --- test/functional/core/startup_spec.lua | 149 ++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 26 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 72d8f3a103..1df8d76c97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -26,6 +26,7 @@ local write_file = helpers.write_file local meths = helpers.meths local alter_slashes = helpers.alter_slashes local is_os = helpers.is_os +local dedent = helpers.dedent local testfile = 'Xtest_startuptime' after_each(function() @@ -47,6 +48,34 @@ describe('startup', function() assert_log("require%('vim%._editor'%)", testfile, 100) end) end) + + it('-D does not hang #12647', function() + clear() + local screen + screen = Screen.new(60, 7) + screen:attach() + command([[let g:id = termopen('"]]..nvim_prog.. + [[" -u NONE -i NONE --cmd "set noruler" -D')]]) + screen:expect([[ + ^ | + | + Entering Debug mode. Type "cont" to continue. | + nvim_exec() | + cmd: aunmenu * | + > | + | + ]]) + command([[call chansend(g:id, "cont\n")]]) + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + [No Name] | + | + | + ]]) + end) end) describe('startup', function() @@ -58,6 +87,94 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) + describe('-l Lua', function() + local function assert_l_out(expected, args_before, args_after) + local args = { nvim_prog, '--clean' } + vim.list_extend(args, args_before or {}) + vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) + vim.list_extend(args, args_after or {}) + local out = funcs.system(args):gsub('\r\n', '\n') + return eq(dedent(expected), out) + end + + it('failure modes', function() + -- nvim -l + matches('nvim: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + eq(1, eval('v:shell_error')) + end) + + it('os.exit() sets Nvim exitcode', function() + -- nvim -l foo.lua -arg1 -- a b c + assert_l_out([[ + bufs: + args: { "-arg1", "--exitcode", "73", "--arg2" }]], + {}, + { '-arg1', "--exitcode", "73", '--arg2' } + ) + eq(73, eval('v:shell_error')) + end) + + it('sets _G.arg', function() + -- nvim -l foo.lua -arg1 -- a b c + assert_l_out([[ + bufs: + args: { "-arg1", "--arg2", "arg3" }]], + {}, + { '-arg1', '--arg2', 'arg3' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua -- + assert_l_out([[ + bufs: + args: {}]], + {}, + { '--' } + ) + eq(0, eval('v:shell_error')) + + -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 + assert_l_out([[ + bufs: file1 file2 file3 file4 + args: { "-arg1", "arg 2" }]], + { 'file1', 'file2', }, + { '-arg1', 'arg 2', '--', 'file3', 'file4' } + ) + eq(0, eval('v:shell_error')) + + -- nvim file1 file2 -l foo.lua -arg1 -- + assert_l_out([[ + bufs: file1 file2 + args: { "-arg1" }]], + { 'file1', 'file2', }, + { '-arg1', '--' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua + assert_l_out([[ + bufs: + args: { "-c", "set wrap?" }]], + {}, + { '-c', 'set wrap?' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua + assert_l_out( + -- luacheck: ignore 611 (Line contains only whitespaces) + [[ + wrap + + bufs: + args: { "-c", "set wrap?" }]], + { '-c', 'set wrap?' }, + { '-c', 'set wrap?' } + ) + eq(0, eval('v:shell_error')) + end) + end) + it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() -- system() puts a pipe at both ends. local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', @@ -66,6 +183,7 @@ describe('startup', function() '+q' }) eq('0 0', out) end) + it('with --embed: has("ttyin")==0 has("ttyout")==0', function() local screen = Screen.new(25, 3) -- Remote UI connected by --embed. @@ -77,6 +195,7 @@ describe('startup', function() 0 0 | ]]) end) + it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 4) screen:attach() @@ -95,6 +214,7 @@ describe('startup', function() | ]]) end) + it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) @@ -111,6 +231,7 @@ describe('startup', function() read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) @@ -128,6 +249,7 @@ describe('startup', function() read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe (implicit) #7679', function() local screen = Screen.new(25, 4) screen:attach() @@ -147,6 +269,7 @@ describe('startup', function() | ]]) end) + it('input from pipe + file args #7679', function() eq('ohyeah\r\n0 0 bufs=3', funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', @@ -532,32 +655,6 @@ describe('sysinit', function() eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')) end) - it('fixed hang issue with -D (#12647)', function() - local screen - screen = Screen.new(60, 7) - screen:attach() - command([[let g:id = termopen('"]]..nvim_prog.. - [[" -u NONE -i NONE --cmd "set noruler" -D')]]) - screen:expect([[ - ^ | - Entering Debug mode. Type "cont" to continue. | - nvim_exec() | - cmd: aunmenu * | - > | - <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| - | - ]]) - command([[call chansend(g:id, "cont\n")]]) - screen:expect([[ - ^ | - ~ | - ~ | - [No Name] | - | - <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| - | - ]]) - end) end) describe('user config init', function() -- cgit From 45549f031ee52a01601c33acc411f3111cfc4e95 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 1 Jan 2023 03:14:13 +0100 Subject: feat(lua): send "--" literally to Lua "-l" script Problem: When "-l" is followed by "--", we stop sending args to the Lua script and treat "--" in the usual way. This was for flexibility but didn't have a strong use-case, and has these problems: - prevents Lua "-l" scripts from handling "--" in their own way. - complicates the startup logic (must call nlua_init before command_line_scan) Solution: Don't treat "--" specially if it follows "-l". --- test/functional/core/startup_spec.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 1df8d76c97..dbd517995c 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -107,7 +107,8 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - args: { "-arg1", "--exitcode", "73", "--arg2" }]], + nvim args: 8 + lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } ) @@ -118,7 +119,8 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - args: { "-arg1", "--arg2", "arg3" }]], + nvim args: 7 + lua args: { "-arg1", "--arg2", "arg3" }]], {}, { '-arg1', '--arg2', 'arg3' } ) @@ -127,7 +129,8 @@ describe('startup', function() -- nvim -l foo.lua -- assert_l_out([[ bufs: - args: {}]], + nvim args: 5 + lua args: { "--" }]], {}, { '--' } ) @@ -135,8 +138,9 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 assert_l_out([[ - bufs: file1 file2 file3 file4 - args: { "-arg1", "arg 2" }]], + bufs: file1 file2 + nvim args: 11 + lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) @@ -145,7 +149,8 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- assert_l_out([[ bufs: file1 file2 - args: { "-arg1" }]], + nvim args: 8 + lua args: { "-arg1", "--" }]], { 'file1', 'file2', }, { '-arg1', '--' } ) @@ -154,7 +159,8 @@ describe('startup', function() -- nvim -l foo.lua assert_l_out([[ bufs: - args: { "-c", "set wrap?" }]], + nvim args: 6 + lua args: { "-c", "set wrap?" }]], {}, { '-c', 'set wrap?' } ) @@ -167,7 +173,8 @@ describe('startup', function() wrap bufs: - args: { "-c", "set wrap?" }]], + nvim args: 8 + lua args: { "-c", "set wrap?" }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) -- cgit From adef308a5925a3b967af3bd7c598074e5b6cae18 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 2 Jan 2023 15:34:14 +0100 Subject: feat(lua): exit 1 on Lua "-l" script error --- test/functional/core/startup_spec.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index dbd517995c..455de08548 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -88,11 +88,11 @@ describe('startup', function() end) describe('-l Lua', function() - local function assert_l_out(expected, args_before, args_after) + local function assert_l_out(expected, nvim_args, lua_args) local args = { nvim_prog, '--clean' } - vim.list_extend(args, args_before or {}) + vim.list_extend(args, nvim_args or {}) vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) - vim.list_extend(args, args_after or {}) + vim.list_extend(args, lua_args or {}) local out = funcs.system(args):gsub('\r\n', '\n') return eq(dedent(expected), out) end @@ -115,6 +115,13 @@ describe('startup', function() eq(73, eval('v:shell_error')) end) + it('Lua error sets Nvim exitcode', function() + eq(0, eval('v:shell_error')) + matches('E5113: .* my pearls!!', + funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) + eq(1, eval('v:shell_error')) + end) + it('sets _G.arg', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ @@ -396,11 +403,13 @@ describe('startup', function() { 'put =mode(1)', 'print', '' })) end) - it('fails on --embed with -es/-Es', function() - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es', + it('fails on --embed with -es/-Es/-l', function() + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-es' })) - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es', + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-Es' })) + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', + funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' })) end) it('does not crash if --embed is given twice', function() -- cgit From f43de742e881e54a3602e00c8c247cecca65a266 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Jan 2023 02:54:53 +0100 Subject: feat(lua): execute stdin ("-") as Lua --- test/functional/core/startup_spec.lua | 58 +++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 455de08548..d7e64c6b54 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -88,18 +88,18 @@ describe('startup', function() end) describe('-l Lua', function() - local function assert_l_out(expected, nvim_args, lua_args) - local args = { nvim_prog, '--clean' } + local function assert_l_out(expected, nvim_args, lua_args, script, input) + local args = { nvim_prog } vim.list_extend(args, nvim_args or {}) - vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) + vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, lua_args or {}) - local out = funcs.system(args):gsub('\r\n', '\n') + local out = funcs.system(args, input):gsub('\r\n', '\n') return eq(dedent(expected), out) end it('failure modes', function() - -- nvim -l - matches('nvim: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + -- nvim -l + matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) eq(1, eval('v:shell_error')) end) @@ -107,7 +107,7 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - nvim args: 8 + nvim args: 7 lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } @@ -115,18 +115,35 @@ describe('startup', function() eq(73, eval('v:shell_error')) end) - it('Lua error sets Nvim exitcode', function() + it('Lua-error sets Nvim exitcode', function() eq(0, eval('v:shell_error')) matches('E5113: .* my pearls!!', funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) eq(1, eval('v:shell_error')) + matches('E5113: .* %[string "error%("whoa"%)"%]:1: whoa', + funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")')) + eq(1, eval('v:shell_error')) + end) + + it('executes stdin "-"', function() + assert_l_out('args=2 whoa', + nil, + { 'arg1', 'arg 2' }, + '-', + "print(('args=%d %s'):format(#_G.arg, 'whoa'))") + assert_l_out('biiig input: 1000042', + nil, + nil, + '-', + ('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42))) + eq(0, eval('v:shell_error')) end) it('sets _G.arg', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - nvim args: 7 + nvim args: 6 lua args: { "-arg1", "--arg2", "arg3" }]], {}, { '-arg1', '--arg2', 'arg3' } @@ -136,7 +153,7 @@ describe('startup', function() -- nvim -l foo.lua -- assert_l_out([[ bufs: - nvim args: 5 + nvim args: 4 lua args: { "--" }]], {}, { '--' } @@ -146,7 +163,7 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 assert_l_out([[ bufs: file1 file2 - nvim args: 11 + nvim args: 10 lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } @@ -156,7 +173,7 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- assert_l_out([[ bufs: file1 file2 - nvim args: 8 + nvim args: 7 lua args: { "-arg1", "--" }]], { 'file1', 'file2', }, { '-arg1', '--' } @@ -166,7 +183,7 @@ describe('startup', function() -- nvim -l foo.lua assert_l_out([[ bufs: - nvim args: 6 + nvim args: 5 lua args: { "-c", "set wrap?" }]], {}, { '-c', 'set wrap?' } @@ -180,13 +197,22 @@ describe('startup', function() wrap bufs: - nvim args: 8 + nvim args: 7 lua args: { "-c", "set wrap?" }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) eq(0, eval('v:shell_error')) end) + + it('disables swapfile/shada/config/plugins', function() + assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scriptnames=1', + nil, + nil, + '-', + [[print(('updatecount=%d shadafile=%s loadplugins=%s scriptnames=%d'):format( + vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.split(vim.fn.execute('scriptnames'),'\n'))))]]) + end) end) it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() @@ -375,11 +401,11 @@ describe('startup', function() it('-es/-Es disables swapfile, user config #8540', function() for _,arg in ipairs({'-es', '-Es'}) do local out = funcs.system({nvim_prog, arg, - '+set swapfile? updatecount? shada?', + '+set swapfile? updatecount? shadafile?', "+put =execute('scriptnames')", '+%print'}) local line1 = string.match(out, '^.-\n') -- updatecount=0 means swapfile was disabled. - eq(" swapfile updatecount=0 shada=!,'100,<50,s10,h\n", line1) + eq(" swapfile updatecount=0 shadafile=\n", line1) -- Standard plugins were loaded, but not user config. eq('health.vim', string.match(out, 'health.vim')) eq(nil, string.match(out, 'init.vim')) -- cgit From e17430c1cd97db5624e27515a4f5da17f9d926d6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 7 Jan 2023 02:12:54 +0100 Subject: feat(lua): store "nvim -l" scriptname in _G.arg[0] --- test/functional/core/startup_spec.lua | 50 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index d7e64c6b54..9dabcd28b3 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -108,7 +108,9 @@ describe('startup', function() assert_l_out([[ bufs: nvim args: 7 - lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], + lua args: { "-arg1", "--exitcode", "73", "--arg2", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } ) @@ -126,11 +128,11 @@ describe('startup', function() end) it('executes stdin "-"', function() - assert_l_out('args=2 whoa', + assert_l_out('arg0=- args=2 whoa', nil, { 'arg1', 'arg 2' }, '-', - "print(('args=%d %s'):format(#_G.arg, 'whoa'))") + "print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))") assert_l_out('biiig input: 1000042', nil, nil, @@ -140,23 +142,15 @@ describe('startup', function() end) it('sets _G.arg', function() - -- nvim -l foo.lua -arg1 -- a b c - assert_l_out([[ - bufs: - nvim args: 6 - lua args: { "-arg1", "--arg2", "arg3" }]], - {}, - { '-arg1', '--arg2', 'arg3' } - ) - eq(0, eval('v:shell_error')) - - -- nvim -l foo.lua -- + -- nvim -l foo.lua [args] assert_l_out([[ bufs: - nvim args: 4 - lua args: { "--" }]], + nvim args: 7 + lua args: { "-arg1", "--arg2", "--", "arg3", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, - { '--' } + { '-arg1', '--arg2', '--', 'arg3' } ) eq(0, eval('v:shell_error')) @@ -164,27 +158,21 @@ describe('startup', function() assert_l_out([[ bufs: file1 file2 nvim args: 10 - lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], + lua args: { "-arg1", "arg 2", "--", "file3", "file4", + [0] = "test/functional/fixtures/startup.lua" + }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) eq(0, eval('v:shell_error')) - -- nvim file1 file2 -l foo.lua -arg1 -- - assert_l_out([[ - bufs: file1 file2 - nvim args: 7 - lua args: { "-arg1", "--" }]], - { 'file1', 'file2', }, - { '-arg1', '--' } - ) - eq(0, eval('v:shell_error')) - -- nvim -l foo.lua assert_l_out([[ bufs: nvim args: 5 - lua args: { "-c", "set wrap?" }]], + lua args: { "-c", "set wrap?", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, { '-c', 'set wrap?' } ) @@ -198,7 +186,9 @@ describe('startup', function() bufs: nvim args: 7 - lua args: { "-c", "set wrap?" }]], + lua args: { "-c", "set wrap?", + [0] = "test/functional/fixtures/startup.lua" + }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) -- cgit From 6134c1e8a39a5e61d0593613343a5923a86e3545 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Jan 2023 09:34:21 +0800 Subject: test(fileio_spec): avoid expect_exit() without calling clear() (#21810) Since before_each() doesn't call clear() in these tests, after_each() may call expect_exit() without calling clear() if a test is skipped, causing frequent test failures on Cirrus CI. Close the session instead. --- test/functional/core/fileio_spec.lua | 5 +++-- 1 file changed, 3 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 ed37032f25..bbf2202f0d 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -22,6 +22,7 @@ local tmpname = helpers.tmpname local trim = helpers.trim local currentdir = helpers.funcs.getcwd local assert_alive = helpers.assert_alive +local check_close = helpers.check_close local expect_exit = helpers.expect_exit local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') @@ -34,7 +35,7 @@ describe('fileio', function() before_each(function() end) after_each(function() - expect_exit(command, ':qall!') + check_close() os.remove('Xtest_startup_shada') os.remove('Xtest_startup_file1') os.remove('Xtest_startup_file1~') @@ -270,7 +271,7 @@ describe('tmpdir', function() end) after_each(function() - expect_exit(command, ':qall!') + check_close() os.remove(testlog) end) -- cgit From 61d5bd561addfd4cc9917712bdf983e77137089e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 16 Jan 2023 06:38:50 +0800 Subject: refactor: remove E5500, adjust tests Now with try_end() including more exception info, E5500 looks like redundant information. Adjust tests for more exception information. --- test/functional/core/exit_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 8cad7adfa6..05a69e1992 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -89,14 +89,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, 'Vim(cquit):E488: Trailing characters: 2: cquit 1 2') + test_cq('cquit 1 2', nil, 'nvim_exec(): 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, 'Vim(cquit):E488: Trailing characters: X: cquit X') + test_cq('cquit X', nil, 'nvim_exec(): 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, 'Vim(cquit):E488: Trailing characters: -1: cquit -1') + test_cq('cquit -1', nil, 'nvim_exec(): Vim(cquit):E488: Trailing characters: -1: cquit -1') end) end) -- cgit From 665a7dafaf892b31285f35a43a90fc6e968fd7da Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 17 Jan 2023 00:12:59 +0100 Subject: refactor(tests): lift retry() into assert_log() --- test/functional/core/fileio_spec.lua | 8 ++------ test/functional/core/log_spec.lua | 9 ++------- test/functional/core/startup_spec.lua | 6 ++---- 3 files changed, 6 insertions(+), 17 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index bbf2202f0d..4e9891a4de 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -295,9 +295,7 @@ describe('tmpdir', function() clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. - retry(nil, 1000, function() - assert_log('tempdir root not a directory', testlog, 100) - end) + assert_log('tempdir root not a directory', testlog, 100) -- "…/nvim./" has wrong permissions: skip(is_os('win'), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') @@ -308,9 +306,7 @@ describe('tmpdir', function() clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. - retry(nil, 1000, function() - assert_log('tempdir root has invalid permissions', testlog, 100) - end) + assert_log('tempdir root has invalid permissions', testlog, 100) end) it('too long', function() diff --git a/test/functional/core/log_spec.lua b/test/functional/core/log_spec.lua index 3b1ccd9559..f682df4155 100644 --- a/test/functional/core/log_spec.lua +++ b/test/functional/core/log_spec.lua @@ -6,7 +6,6 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local expect_exit = helpers.expect_exit local request = helpers.request -local retry = helpers.retry describe('log', function() local testlog = 'Xtest_logging' @@ -40,9 +39,7 @@ describe('log', function() }}) local tid = _G._nvim_test_id - retry(nil, 1000, function() - assert_log(tid..'%.%d+%.%d +server_init:%d+: test log message', testlog, 100) - end) + assert_log(tid..'%.%d+%.%d +server_init:%d+: test log message', testlog, 100) exec_lua([[ local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1', '+foochild', '+qa!' }, vim.empty_dict()) @@ -50,8 +47,6 @@ describe('log', function() ]]) -- Child Nvim spawned by jobstart() appends "/c" to parent name. - retry(nil, 1000, function() - assert_log('%.%d+%.%d/c +server_init:%d+: test log message', testlog, 100) - end) + assert_log('%.%d+%.%d/c +server_init:%d+: test log message', testlog, 100) end) end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 9dabcd28b3..1be5de6488 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -43,10 +43,8 @@ describe('startup', function() it('--startuptime', function() clear({ args = {'--startuptime', testfile}}) - retry(nil, 1000, function() - assert_log('sourcing', testfile, 100) - assert_log("require%('vim%._editor'%)", testfile, 100) - end) + assert_log('sourcing', testfile, 100) + assert_log("require%('vim%._editor'%)", testfile, 100) end) it('-D does not hang #12647', function() -- cgit