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

Commit

Permalink
feat(ChildProcessStream): capture exit code on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoux committed Jul 1, 2022
1 parent 12d070b commit a77d906
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nvim/child_process_stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions test/session_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -168,6 +169,23 @@ 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',
})

local session = Session.new(proc_stream)
local ok = session:request "nvim_get_api_info"
session:request("nvim_command", "qall!")

assert.is_true(ok)
uv.run()

assert.is.same(proc_stream._exit_code, 0)
end)
end)

-- Session using SocketStream
test_session(string.format("Session using SocketStream [%s]", socket_file), function ()
child_session = Session.new(ChildProcessStream.spawn({
Expand Down

0 comments on commit a77d906

Please sign in to comment.