From 72652cbc46f568128bfc296ba63fb2d26941da8e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Mar 2022 10:25:55 -0700 Subject: feat(test): use nvim_exec in helpers.source() #16064 helpers.source() was a hack to work around the lack of anonymous :source. Its "create tempfile" behavior is not a required part of most tests that use it. Some tests still need the old "create tempfile" behavior either because they test SID behavior, or because of missing nvim_exec features: #16071 --- test/functional/helpers.lua | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 1845786c4b..173fc54af5 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -21,7 +21,6 @@ local map = global_helpers.tbl_map local ok = global_helpers.ok local sleep = global_helpers.sleep local tbl_contains = global_helpers.tbl_contains -local write_file = global_helpers.write_file local fail = global_helpers.fail local module = { @@ -54,7 +53,6 @@ if module.nvim_dir == module.nvim_prog then module.nvim_dir = "." end -local tmpname = global_helpers.tmpname local iswin = global_helpers.iswin local prepend_argv @@ -494,24 +492,9 @@ function module.feed_command(...) end end -local sourced_fnames = {} +-- @deprecated use nvim_exec() function module.source(code) - local fname = tmpname() - write_file(fname, code) - module.command('source '..fname) - -- DO NOT REMOVE FILE HERE. - -- do_source() has a habit of checking whether files are “same” by using inode - -- and device IDs. If you run two source() calls in quick succession there is - -- a good chance that underlying filesystem will reuse the inode, making files - -- appear as “symlinks” to do_source when it checks FileIDs. With current - -- setup linux machines (both QB, travis and mine(ZyX-I) with XFS) do reuse - -- inodes, Mac OS machines (again, both QB and travis) do not. - -- - -- Files appearing as “symlinks” mean that both the first and the second - -- source() calls will use same SID, which may fail some tests which check for - -- exact numbers after `` in e.g. function names. - sourced_fnames[#sourced_fnames + 1] = fname - return fname + module.exec(dedent(code)) end function module.has_powershell() @@ -525,7 +508,7 @@ function module.set_shell_powershell() local cmd = set_encoding..'Remove-Item -Force '..table.concat(iswin() and {'alias:cat', 'alias:echo', 'alias:sleep'} or {'alias:echo'}, ',')..';' - module.source([[ + module.exec([[ let &shell = ']]..shell..[[' set shellquote= shellxquote= let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' @@ -887,9 +870,6 @@ module = global_helpers.tbl_extend('error', module, global_helpers) return function(after_each) if after_each then after_each(function() - for _, fname in ipairs(sourced_fnames) do - os.remove(fname) - end check_logs() check_cores('build/bin/nvim') if session then -- cgit From ad63b94b03c166f37bda477db6cbac2a9583d586 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 22 Apr 2022 20:56:31 +0200 Subject: refactor(ui): simplify stdin handling --- test/functional/helpers.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 173fc54af5..b0b2dac9fd 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -361,14 +361,15 @@ local function remove_args(args, args_rm) return new_args end -function module.spawn(argv, merge, env, keep) +--- @param io_extra used for stdin_fd, see :help ui-option +function module.spawn(argv, merge, env, keep, io_extra) if session and not keep then session:close() end local child_stream = ChildProcessStream.spawn( merge and module.merge_args(prepend_argv, argv) or argv, - env) + env, io_extra) return Session.new(child_stream) end @@ -415,8 +416,8 @@ end -- clear('-e') -- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}} function module.clear(...) - local argv, env = module.new_argv(...) - module.set_session(module.spawn(argv, nil, env)) + local argv, env, io_extra = module.new_argv(...) + module.set_session(module.spawn(argv, nil, env, nil, io_extra)) end -- Builds an argument list for use in clear(). @@ -426,6 +427,7 @@ function module.new_argv(...) local args = {unpack(module.nvim_argv)} table.insert(args, '--headless') local new_args + local io_extra local env = nil local opts = select(1, ...) if type(opts) == 'table' then @@ -461,13 +463,14 @@ function module.new_argv(...) end end new_args = opts.args or {} + io_extra = opts.io_extra else new_args = {...} end for _, arg in ipairs(new_args) do table.insert(args, arg) end - return args, env + return args, env, io_extra end function module.insert(...) -- cgit From 4fb48c5654d9ffbffbdcdd80d0498b1ea3c8e68b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 May 2022 15:08:35 +0200 Subject: feat(server): set $NVIM, unset $NVIM_LISTEN_ADDRESS #11009 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROBLEM ------------------------------------------------------------------------ $NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the current process should listen on this address") and a descriptor ("the current process is a child of this address"). This contradiction means the presence of NVIM_LISTEN_ADDRESS is ambiguous, so child Nvim always tries to listen on its _parent's_ socket. This is the cause of lots of "Failed to start server" spam in our test/CI logs: WARN 2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0 WARN 2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0 SOLUTION ------------------------------------------------------------------------ 1. Set $NVIM to the parent v:servername, *only* in child processes. - Now the correct way to detect a "parent" Nvim is to check for $NVIM. 2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes. 3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after server init. 4. Open a channel to parent automatically, expose it as v:parent. Fixes #3118 Fixes #6764 Fixes #9336 Ref https://github.com/neovim/neovim/pull/8247#issuecomment-380275696 Ref #8696 --- test/functional/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index b0b2dac9fd..e9c3d4bd92 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -782,7 +782,7 @@ function module.pathroot() return iswin() and (module.nvim_dir:sub(1,2)..pathsep) or '/' end --- Returns a valid, platform-independent $NVIM_LISTEN_ADDRESS. +-- Returns a valid, platform-independent Nvim listen address. -- Useful for communicating with child instances. function module.new_pipename() -- HACK: Start a server temporarily, get the name, then stop it. -- cgit From 233c41cb8cfe1aa5a8520fe6104adacc53c0ece2 Mon Sep 17 00:00:00 2001 From: yamatsum <42740055+yamatsum@users.noreply.github.com> Date: Fri, 13 May 2022 09:28:10 +0900 Subject: feat(defaults): search selection by * and # in visual mode (#18538) --- test/functional/helpers.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index e9c3d4bd92..3d64625752 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -41,10 +41,8 @@ module.nvim_set = ( module.nvim_argv = { module.nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', module.nvim_set, - '--cmd', 'unmap Y', - '--cmd', 'unmap ', - '--cmd', 'iunmap ', - '--cmd', 'iunmap ', + '--cmd', 'mapclear', + '--cmd', 'mapclear!', '--embed'} -- Directory containing nvim. -- cgit From a4e1b76f555f40a105b934fe669fff015bf8906e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 8 Jun 2022 18:29:58 -0400 Subject: test: allow running CI without ts parsers installed --- test/functional/helpers.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 3d64625752..7c923351ab 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -720,14 +720,10 @@ function module.pending_win32(pending_fn) end function module.pending_c_parser(pending_fn) - local status, msg = unpack(module.exec_lua([[ return {pcall(vim.treesitter.require_language, 'c')} ]])) + local status, _ = unpack(module.exec_lua([[ return {pcall(vim.treesitter.require_language, 'c')} ]])) if not status then - if module.isCI() then - error("treesitter C parser not found, required on CI: " .. msg) - else - pending_fn 'no C parser, skipping' - return true - end + pending_fn 'no C parser, skipping' + return true end return false end -- cgit From e3281d992e1b9366d67a4b4399e3b5e11bb6c1cc Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 8 Jun 2022 23:22:50 +0200 Subject: fix(tests): check for EOF on exit of nvim properly --- test/functional/helpers.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 7c923351ab..ffb5694c15 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -270,6 +270,13 @@ function module.command(cmd) module.request('nvim_command', cmd) end + +-- use for commands which expect nvim to quit +function module.expect_exit(...) + eq("EOF was received from Nvim. Likely the Nvim process crashed.", + module.pcall_err(...)) +end + -- Evaluates a VimL expression. -- Fails on VimL error, but does not update v:errmsg. function module.eval(expr) -- cgit From 8f065205946844d87f00d6c55517521e3809f821 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 May 2022 21:44:15 -0700 Subject: feat(logging): include test-id in log messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: 1. Log messages (especially in CI) are hard to correlate with tests. 2. Since b353a5c05f02 #11886, dumplog() prints the logs next to test failures. This is noisy and gets in the way of the test results. Solution: 1. Associate an incrementing id with each test and include it in log messages. - FUTURE: add v:name so Nvim instances can be formally "named"? 2. Mention "child" in log messages if the current Nvim is a child (based on the presence of $NVIM). BEFORE: DBG … 12345 UI: event DBG … 12345 log_server_msg:722: RPC ->ch 1: … DBG … 12345 UI: flush DBG … 12345 inbuf_poll:444: blocking... events_enabled=1 events_pending=0 DBG … 23454 UI: stop INF … 23454 os_exit:594: Nvim exit: 0 AFTER: DBG … T57 UI: event DBG … T57 log_server_msg:722: RPC ->ch 1: … DBG … T57 UI: flush DBG … T57 inbuf_poll:444: blocking... events_enabled=1 events_pending=0 DBG … T57/child UI: stop INF … T57/child os_exit:594: Nvim exit: 0 --- test/functional/helpers.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index ffb5694c15..0122229e77 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -433,16 +433,19 @@ function module.new_argv(...) table.insert(args, '--headless') local new_args local io_extra - local env = nil + local env = {} local opts = select(1, ...) - if type(opts) == 'table' then + if type(opts) ~= 'table' then + new_args = {...} + else args = remove_args(args, opts.args_rm) if opts.env then - local env_tbl = {} + opts.env['NVIM_TEST'] = nil + local env_opt = {} for k, v in pairs(opts.env) do assert(type(k) == 'string') assert(type(v) == 'string') - env_tbl[k] = v + env_opt[k] = v end for _, k in ipairs({ 'HOME', @@ -458,23 +461,25 @@ function module.new_argv(...) 'TMPDIR', 'VIMRUNTIME', }) do - if not env_tbl[k] then - env_tbl[k] = os.getenv(k) + -- Set these from the environment only if not in opts.env. + if not env_opt[k] then + env_opt[k] = os.getenv(k) end end - env = {} - for k, v in pairs(env_tbl) do + for k, v in pairs(env_opt) do env[#env + 1] = k .. '=' .. v end end new_args = opts.args or {} io_extra = opts.io_extra - else - new_args = {...} end for _, arg in ipairs(new_args) do table.insert(args, arg) end + + -- TODO(justinmk): introduce v:name and use that instead. + table.insert(env, ('NVIM_TEST=%s'):format(_G._nvim_test_id or '?')) + return args, env, io_extra end -- cgit From 1f2c2a35ad14cfac002d87073471bd84a52860bf Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 1 Jun 2022 11:28:14 -0700 Subject: feat(server): instance "name", store pipes in stdpath(state) Problem: - Unix sockets are created in random /tmp dirs. - /tmp is messy, unclear when OSes actually clear it. - The generated paths are very ugly. This adds friction to reasoning about which paths belong to which Nvim instances. - No way to provide a human-friendly way to identify Nvim instances in logs or server addresses. Solution: - Store unix sockets in stdpath('state') - Allow --listen "name" and serverstart("name") to given a name (which is appended to a generated path). TODO: - is stdpath(state) the right place? --- test/functional/helpers.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 0122229e77..d31d337b63 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -431,16 +431,20 @@ end function module.new_argv(...) local args = {unpack(module.nvim_argv)} table.insert(args, '--headless') + if _G._nvim_test_id then + -- Set the server name to the test-id for logging. #8519 + table.insert(args, '--listen') + table.insert(args, _G._nvim_test_id) + end local new_args local io_extra - local env = {} + local env = nil local opts = select(1, ...) if type(opts) ~= 'table' then new_args = {...} else args = remove_args(args, opts.args_rm) if opts.env then - opts.env['NVIM_TEST'] = nil local env_opt = {} for k, v in pairs(opts.env) do assert(type(k) == 'string') @@ -461,11 +465,12 @@ function module.new_argv(...) 'TMPDIR', 'VIMRUNTIME', }) do - -- Set these from the environment only if not in opts.env. + -- Set these from the environment unless the caller defined them. if not env_opt[k] then env_opt[k] = os.getenv(k) end end + env = {} for k, v in pairs(env_opt) do env[#env + 1] = k .. '=' .. v end @@ -476,10 +481,6 @@ function module.new_argv(...) for _, arg in ipairs(new_args) do table.insert(args, arg) end - - -- TODO(justinmk): introduce v:name and use that instead. - table.insert(env, ('NVIM_TEST=%s'):format(_G._nvim_test_id or '?')) - return args, env, io_extra end -- cgit From 0b9664f5240be4d9e9d6882fcd398970fd3a9532 Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Tue, 9 Nov 2021 20:22:21 +0600 Subject: fix: make_filter_cmd for :! powershell #15913 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Nvim fails to create tempfile "…/nvim6UJx04/7" when 'shell' is set to pwsh (PowerShell Core). This breaks filtered shell commands ":{range}!". With shell set to cmd, it works. Solution: PowerShell doesn't use "<" for stdin redirection. Instead, use "-RedirectStandardInput". Closes #15913 --- test/functional/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index d31d337b63..2018f80052 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -525,9 +525,9 @@ function module.set_shell_powershell() module.exec([[ let &shell = ']]..shell..[[' set shellquote= shellxquote= - let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' - let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ]]..cmd..[[' + let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' + let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait' ]]) end -- cgit From f977f9445f7689fc32a136108ff92b3c2137968c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 22 Jun 2022 05:51:52 -0700 Subject: refactor(tests): introduce testprg() Also: - Add a describe('shell :!') section to system_spec. - Make the test for #16271 work on systems without powershell. --- test/functional/helpers.lua | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'test/functional/helpers.lua') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 2018f80052..0c616e73fb 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -515,9 +515,17 @@ function module.has_powershell() return module.eval('executable("'..(iswin() and 'powershell' or 'pwsh')..'")') == 1 end -function module.set_shell_powershell() - local shell = iswin() and 'powershell' or 'pwsh' - assert(module.has_powershell()) +--- Sets Nvim shell to powershell. +--- +--- @param fake (boolean) If true, a fake will be used if powershell is not +--- found on the system. +--- @returns true if powershell was found on the system, else false. +function module.set_shell_powershell(fake) + local found = module.has_powershell() + if not fake then + assert(found) + end + local shell = found and (iswin() and 'powershell' or 'pwsh') or module.testprg('pwsh-test') local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;' local cmd = set_encoding..'Remove-Item -Force '..table.concat(iswin() and {'alias:cat', 'alias:echo', 'alias:sleep'} @@ -529,6 +537,7 @@ function module.set_shell_powershell() let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait' ]]) + return found end function module.nvim(method, ...) @@ -784,11 +793,21 @@ function module.get_pathsep() return iswin() and '\\' or '/' end +--- Gets the filesystem root dir, namely "/" or "C:/". function module.pathroot() local pathsep = package.config:sub(1,1) return iswin() and (module.nvim_dir:sub(1,2)..pathsep) or '/' end +--- Gets the full `…/build/bin/{name}` path of a test program produced by +--- `test/functional/fixtures/CMakeLists.txt`. +--- +--- @param name (string) Name of the test program. +function module.testprg(name) + local ext = module.iswin() and '.exe' or '' + return ('%s/%s%s'):format(module.nvim_dir, name, ext) +end + -- Returns a valid, platform-independent Nvim listen address. -- Useful for communicating with child instances. function module.new_pipename() -- cgit