From cf5beb96337bc105c43b5beb5066b3551c7e3bf0 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Fri, 1 Jul 2022 10:48:12 +0200 Subject: [PATCH] feat(ChildProcessStream): capture exit code on exit --- nvim/child_process_stream.lua | 3 ++- test/session_spec.lua | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nvim/child_process_stream.lua b/nvim/child_process_stream.lua index ca2d38e..ae11e19 100644 --- a/nvim/child_process_stream.lua +++ b/nvim/child_process_stream.lua @@ -19,7 +19,8 @@ function ChildProcessStream.spawn(argv, env, io_extra) stdio = {self._child_stdin, self._child_stdout, 2, io_extra}, args = args, env = env, - }, function() + }, function(ecode) + self._exit_code = ecode self:close() end) diff --git a/test/session_spec.lua b/test/session_spec.lua index 4cea1cf..3343404 100644 --- a/test/session_spec.lua +++ b/test/session_spec.lua @@ -168,6 +168,18 @@ test_session("Session using ChidProcessStream", function () return Session.new(proc_stream) end) +describe("ChildProcessStream", function() + it("can capture exit code", function() + local proc_stream = ChildProcessStream.spawn({ + nvim_prog, '-u', 'NONE', '--embed', + }) + + proc_stream:close() + + assert.is_not_nil(proc_stream._exit_code) + end) +end) + -- Session using SocketStream test_session(string.format("Session using SocketStream [%s]", socket_file), function () child_session = Session.new(ChildProcessStream.spawn({