test: spawn_wait() starts a non-RPC Nvim process

Problem:
Can't use `n.clear()` to test non-RPC `nvim` invocations. So tests end
up creating ad-hoc wrappers around `system()` or `jobstart()`.

Solution:
- Introduce `n.spawn_wait()`
- TODO (followup PR): Rename `n.spawn()` and `n.spawn_wait()`.
  It's misleading that `n.spawn()` returns a RPC session...
This commit is contained in:
Justin M. Keyes
2024-09-12 03:04:33 +02:00
parent fe87656f29
commit a1ba655dee
8 changed files with 214 additions and 80 deletions

View File

@@ -154,8 +154,9 @@ describe('startup', function()
it('failure modes', function()
-- nvim -l <empty>
matches('nvim%.?e?x?e?: Argument missing after: "%-l"', fn.system({ nvim_prog, '-l' }))
eq(1, eval('v:shell_error'))
local proc = n.spawn_wait('-l')
matches('nvim%.?e?x?e?: Argument missing after: "%-l"', proc.stderr)
eq(1, proc.status)
end)
it('os.exit() sets Nvim exitcode', function()
@@ -182,12 +183,11 @@ describe('startup', function()
end)
it('Lua-error sets Nvim exitcode', function()
local proc = n.spawn_wait('-l', 'test/functional/fixtures/startup-fail.lua')
matches('E5113: .* my pearls!!', proc.output)
eq(1, proc.status)
eq(0, eval('v:shell_error'))
matches(
'E5113: .* my pearls!!',
fn.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })
)
eq(1, eval('v:shell_error'))
matches(
'E5113: .* %[string "error%("whoa"%)"%]:1: whoa',
fn.system({ nvim_prog, '-l', '-' }, 'error("whoa")')