test: use spawn_wait() instead of system() #31852

Problem:
Tests that need to check `nvim` CLI behavior (no RPC session) create
their own ad-hoc `system()` wrappers.

Solution:
- Use `n.spawn_wait` instead of `system()`.
- Bonus: this also improves the tests by explicitly checking for
  `stdout` or `stderr`. And if a signal is raised, `ProcStream.status`
  will reflect it.
This commit is contained in:
Justin M. Keyes
2025-01-04 06:29:13 -08:00
committed by GitHub
parent 7ddadd0fee
commit 975c2124a6
8 changed files with 78 additions and 146 deletions

View File

@@ -318,16 +318,6 @@ function M.stop()
assert(session):stop()
end
function M.nvim_prog_abs()
-- system(['build/bin/nvim']) does not work for whatever reason. It must
-- be executable searched in $PATH or something starting with / or ./.
if M.nvim_prog:match('[/\\]') then
return M.request('nvim_call_function', 'fnamemodify', { M.nvim_prog, ':p' })
else
return M.nvim_prog
end
end
-- Use for commands which expect nvim to quit.
-- The first argument can also be a timeout.
function M.expect_exit(fn_or_timeout, ...)
@@ -526,7 +516,7 @@ function M.spawn_argv(keep, ...)
return M.spawn(argv, nil, env, keep, io_extra)
end
--- Starts a (`--headless`, non-RPC) Nvim process, waits for exit, and returns output + info.
--- Starts a (non-RPC, `--headless --listen "Tx"`) Nvim process, waits for exit, and returns result.
---
--- @param ... string Nvim CLI args
--- @return test.ProcStream
@@ -537,6 +527,7 @@ function M.spawn_wait(...)
table.insert(opts.args_rm, '--embed')
local argv, env, io_extra = M.new_argv(opts)
local proc = ProcStream.spawn(argv, env, io_extra)
proc.collect_text = true
proc:read_start()
proc:wait()
proc:close()