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

@@ -14,7 +14,6 @@ local api = n.api
local command = n.command
local clear = n.clear
local exc_exec = n.exc_exec
local exec_lua = n.exec_lua
local eval = n.eval
local eq = t.eq
local ok = t.ok
@@ -929,17 +928,12 @@ describe('stdpath()', function()
assert_alive() -- Check for crash. #8393
-- Check that Nvim rejects invalid APPNAMEs
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
local function test_appname(testAppname, expected_exitcode)
local lua_code = string.format(
[[
local child = vim.fn.jobstart({ vim.v.progpath, '--clean', '--headless', '--listen', 'x', '+qall!' }, { env = { NVIM_APPNAME = %q } })
return vim.fn.jobwait({ child }, %d)[1]
]],
testAppname,
3000
)
eq(expected_exitcode, exec_lua(lua_code))
local p = n.spawn_wait({
args = { '--listen', 'x', '+qall!' },
env = { NVIM_APPNAME = testAppname },
})
eq(expected_exitcode, p.status)
end
-- Invalid appnames:
test_appname('a/../b', 1)