test: include stderr in EOF failure message

This commit is contained in:
Justin M. Keyes
2025-01-03 18:39:42 +01:00
parent a1ba655dee
commit 700a25e621
3 changed files with 20 additions and 14 deletions

View File

@@ -12,10 +12,8 @@ local RpcStream = require('test.client.rpc_stream')
--- @field private _rpc_stream test.RpcStream
--- @field private _prepare uv.uv_prepare_t
--- @field private _timer uv.uv_timer_t
--- @field exec_lua_setup boolean
--- @field private _is_running boolean true during `Session:run()` scope.
--- @field private _stdout_buffer string[] Stores stdout chunks
--- @field public stdout string Full stdout after the process exits
--- @field exec_lua_setup boolean
local Session = {}
Session.__index = Session
if package.loaded['jit'] then
@@ -231,7 +229,13 @@ function Session:_run(request_cb, notification_cb, timeout)
end
self._rpc_stream:read_start(request_cb, notification_cb, function()
uv.stop()
self.eof_err = { 1, 'EOF was received from Nvim. Likely the Nvim process crashed.' }
--- @diagnostic disable-next-line: invisible
local stderr = self._rpc_stream._stream.stderr --[[@as string?]]
-- See if `ProcStream.stderr` has anything useful.
stderr = '' ~= ((stderr or ''):match('^%s*(.*%S)') or '') and ' stderr:\n' .. stderr or ''
self.eof_err = { 1, 'EOF was received from Nvim. Likely the Nvim process crashed.' .. stderr }
end)
uv.run()
self._prepare:stop()

View File

@@ -127,9 +127,11 @@ end
--- @field private _child_stdout uv.uv_pipe_t
--- @field private _child_stderr uv.uv_pipe_t
--- @field stdout string
--- stderr is always collected in this field, regardless of `collect_output`.
--- @field stderr string
--- @field stdout_eof boolean
--- @field stderr_eof boolean
--- Collects stdout in the `stdout` field, and stdout+stderr in `output` field.
--- @field private collect_output boolean
--- Exit code
--- @field status integer
@@ -149,8 +151,6 @@ function ProcStream.spawn(argv, env, io_extra)
output = '',
stdout = '',
stderr = '',
stdout_error = nil, -- TODO: not used, remove
stderr_error = nil, -- TODO: not used, remove
stdout_eof = false,
stderr_eof = false,
_child_stdin = assert(uv.new_pipe(false)),
@@ -189,14 +189,16 @@ end
function ProcStream:on_read(stream, cb, err, chunk)
if err then
-- stderr_error/stdout_error
self[stream .. '_error'] = err ---@type string
-- error(err)
error(err) -- stream read failed?
elseif chunk then
-- 'stderr' or 'stdout'
-- Always collect stderr, in case it gives useful info on failure.
if stream == 'stderr' then
self.stderr = self.stderr .. chunk ---@type string
end
-- Collect stdout if `collect_output` is enabled.
if self.collect_output then
self[stream] = self[stream] .. chunk ---@type string
--- Collects both stdout + stderr.
self.stdout = self.stdout .. chunk ---@type string
--- Collect both stdout + stderr in the `output` field.
self.output = self[stream] .. chunk ---@type string
end
else

View File

@@ -333,9 +333,9 @@ end
function M.expect_exit(fn_or_timeout, ...)
local eof_err_msg = 'EOF was received from Nvim. Likely the Nvim process crashed.'
if type(fn_or_timeout) == 'function' then
eq(eof_err_msg, t.pcall_err(fn_or_timeout, ...))
t.matches(eof_err_msg, t.pcall_err(fn_or_timeout, ...))
else
eq(
t.matches(
eof_err_msg,
t.pcall_err(function(timeout, fn, ...)
fn(...)