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

feat(ChildProcessStream): capture exit code on exit #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nvim/child_process_stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
33 changes: 33 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,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 "kill"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is uv.run() needed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not pass for now, but it was needed in the exit code test.


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({
Expand Down