Skip to content

Commit

Permalink
feat: add tests and default exit code for kill() on ChildProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
CompeyDev committed Jun 25, 2024
1 parent e07d37e commit e134120
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions crates/lune-std-process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,9 @@ fn process_create(
.with_async_function("status", move |lua, ()| {
let code_rx_rc_clone = Rc::clone(&code_rx_rc);
async move {
let code = code_rx_rc_clone
.borrow_mut()
.recv()
.await
.expect("Code sender unexpectedly dropped");
// Exit code of 9 corresponds to SIGKILL, which should be the only case where
// the receiver gets suddenly dropped
let code = code_rx_rc_clone.borrow_mut().recv().await.unwrap_or(9);

TableBuilder::new(lua)?
.with_value("code", code)?
Expand Down
21 changes: 21 additions & 0 deletions tests/process/create/kill.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local process = require("@lune/process")

-- Killing a child process should work as expected

local message = "Hello, world!"
local child = process.create("cat")

child.stdin:write(message)
child.kill()

assert(child.status().code == 9, "Child process should have an exit code of 9 (SIGKILL)")

assert(
child.stdout:readToEnd() == message,
"Reading from stdout of child process should work even after kill"
)

local stdinWriteOk = pcall(function()
child.stdin:write(message)
end)
assert(not stdinWriteOk, "Writing to stdin of child process should not work after kill")

0 comments on commit e134120

Please sign in to comment.