aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2025-01-03 18:39:42 +0100
committerJustin M. Keyes <justinkz@gmail.com>2025-01-03 19:24:04 +0100
commit700a25e6218e016b5adb0ddee740be4618d717a2 (patch)
tree7d068e82e41e44e3325fef63a6a7342234dc900a
parenta1ba655dee0f89230ea09712e4df981cc3b15bea (diff)
downloadrneovim-700a25e6218e016b5adb0ddee740be4618d717a2.tar.gz
rneovim-700a25e6218e016b5adb0ddee740be4618d717a2.tar.bz2
rneovim-700a25e6218e016b5adb0ddee740be4618d717a2.zip
test: include stderr in EOF failure message
-rw-r--r--test/client/session.lua12
-rw-r--r--test/client/uv_stream.lua18
-rw-r--r--test/functional/testnvim.lua4
3 files changed, 20 insertions, 14 deletions
diff --git a/test/client/session.lua b/test/client/session.lua
index 5b7f1a7caa..a5839e012a 100644
--- a/test/client/session.lua
+++ b/test/client/session.lua
@@ -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()
diff --git a/test/client/uv_stream.lua b/test/client/uv_stream.lua
index ac84cbf9bc..a9ef2db115 100644
--- a/test/client/uv_stream.lua
+++ b/test/client/uv_stream.lua
@@ -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
diff --git a/test/functional/testnvim.lua b/test/functional/testnvim.lua
index d65cbf685e..c8f1c35555 100644
--- a/test/functional/testnvim.lua
+++ b/test/functional/testnvim.lua
@@ -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(...)