Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit a80fc8d

Browse files
committed
feat(ChildProcessStream): capture exit code on exit
1 parent 12d070b commit a80fc8d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Diff for: nvim/child_process_stream.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function ChildProcessStream.spawn(argv, env, io_extra)
1919
stdio = {self._child_stdin, self._child_stdout, 2, io_extra},
2020
args = args,
2121
env = env,
22-
}, function()
22+
}, function(ecode, signal)
23+
self._exit_code = ecode
24+
self._signal = signal
2325
self:close()
2426
end)
2527

Diff for: test/session_spec.lua

+33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local SocketStream = require('nvim.socket_stream')
44
local Session = require('nvim.session')
55
local coxpcall = require('coxpcall')
66
local busted = require('busted')
7+
local uv = require('luv')
78
require('nvim._compat')
89

910
local nvim_prog = os.getenv('NVIM_PROG') or 'nvim'
@@ -168,6 +169,38 @@ test_session("Session using ChidProcessStream", function ()
168169
return Session.new(proc_stream)
169170
end)
170171

172+
describe("ChildProcessStream", function()
173+
local session, proc_stream
174+
175+
before_each(function()
176+
proc_stream = ChildProcessStream.spawn({
177+
nvim_prog, '--clean', '--embed',
178+
})
179+
session = Session.new(proc_stream)
180+
session:request "nvim_get_api_info"
181+
end)
182+
183+
after_each(function()
184+
session:close()
185+
proc_stream:close()
186+
end)
187+
188+
it("can capture exit code", function()
189+
session:request("nvim_command", "qall!")
190+
uv.run()
191+
192+
assert.is.same(proc_stream._exit_code, 0)
193+
assert.is.same(proc_stream._signal, 0)
194+
end)
195+
196+
it("can can capture signal", function()
197+
session:close()
198+
199+
assert.is.same(proc_stream._exit_code, 0)
200+
assert.is.same(proc_stream._signal, 9)
201+
end)
202+
end)
203+
171204
-- Session using SocketStream
172205
test_session(string.format("Session using SocketStream [%s]", socket_file), function ()
173206
child_session = Session.new(ChildProcessStream.spawn({

0 commit comments

Comments
 (0)