mirror of
https://github.com/neovim/neovim.git
synced 2026-04-25 08:44:06 +00:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user