From a80fc8d58544d1e73b96a0eff596e71c6da891d8 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 | 4 +++- test/session_spec.lua | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/nvim/child_process_stream.lua b/nvim/child_process_stream.lua index ca2d38e..3e65b40 100644 --- a/nvim/child_process_stream.lua +++ b/nvim/child_process_stream.lua @@ -19,7 +19,9 @@ function ChildProcessStream.spawn(argv, env, io_extra) stdio = {self._child_stdin, self._child_stdout, 2, io_extra}, args = args, env = env, - }, function() + }, function(ecode, signal) + self._exit_code = ecode + self._signal = signal self:close() end) diff --git a/test/session_spec.lua b/test/session_spec.lua index 4cea1cf..6e2b48c 100644 --- a/test/session_spec.lua +++ b/test/session_spec.lua @@ -4,6 +4,7 @@ local SocketStream = require('nvim.socket_stream') local Session = require('nvim.session') local coxpcall = require('coxpcall') local busted = require('busted') +local uv = require('luv') require('nvim._compat') local nvim_prog = os.getenv('NVIM_PROG') or 'nvim' @@ -168,6 +169,38 @@ test_session("Session using ChidProcessStream", function () return Session.new(proc_stream) end) +describe("ChildProcessStream", function() + local session, proc_stream + + before_each(function() + proc_stream = ChildProcessStream.spawn({ + nvim_prog, '--clean', '--embed', + }) + session = Session.new(proc_stream) + session:request "nvim_get_api_info" + end) + + after_each(function() + session:close() + proc_stream:close() + end) + + it("can capture exit code", function() + session:request("nvim_command", "qall!") + uv.run() + + assert.is.same(proc_stream._exit_code, 0) + assert.is.same(proc_stream._signal, 0) + end) + + it("can can capture signal", function() + session:close() + + assert.is.same(proc_stream._exit_code, 0) + assert.is.same(proc_stream._signal, 9) + end) +end) + -- Session using SocketStream test_session(string.format("Session using SocketStream [%s]", socket_file), function () child_session = Session.new(ChildProcessStream.spawn({