mirror of
https://github.com/neovim/neovim.git
synced 2026-01-04 10:26:42 +10: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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user