fix tests for WNOHANG commit

This commit is contained in:
Mitchell Hashimoto
2022-11-16 21:04:31 -08:00
parent d567a976b4
commit 465b4df6ea
2 changed files with 7 additions and 7 deletions

View File

@ -185,11 +185,11 @@ fn setupFd(src: File.Handle, target: i32) !void {
}
/// Wait for the command to exit and return information about how it exited.
pub fn wait(self: Command) !Exit {
pub fn wait(self: Command, block: bool) !Exit {
// We specify NOHANG because its not our fault if the process we launch
// for the tty doesn't properly waitpid its children. We don't want
// to hang the terminal over it.
const res = std.os.waitpid(self.pid.?, std.c.W.NOHANG);
const res = std.os.waitpid(self.pid.?, if (block) 0 else std.c.W.NOHANG);
return Exit.init(res.status);
}
@ -341,7 +341,7 @@ test "Command: pre exec" {
try cmd.start(testing.allocator);
try testing.expect(cmd.pid != null);
const exit = try cmd.wait();
const exit = try cmd.wait(true);
try testing.expect(exit == .Exited);
try testing.expect(exit.Exited == 42);
}
@ -360,7 +360,7 @@ test "Command: redirect stdout to file" {
try cmd.start(testing.allocator);
try testing.expect(cmd.pid != null);
const exit = try cmd.wait();
const exit = try cmd.wait(true);
try testing.expect(exit == .Exited);
try testing.expect(exit.Exited == 0);
@ -390,7 +390,7 @@ test "Command: custom env vars" {
try cmd.start(testing.allocator);
try testing.expect(cmd.pid != null);
const exit = try cmd.wait();
const exit = try cmd.wait(true);
try testing.expect(exit == .Exited);
try testing.expect(exit.Exited == 0);
@ -416,7 +416,7 @@ test "Command: custom working directory" {
try cmd.start(testing.allocator);
try testing.expect(cmd.pid != null);
const exit = try cmd.wait();
const exit = try cmd.wait(true);
try testing.expect(exit == .Exited);
try testing.expect(exit.Exited == 0);

View File

@ -129,7 +129,7 @@ pub fn deinit(self: *Exec) void {
// Kill our command
self.killCommand() catch |err|
log.err("error sending SIGHUP to command, may hang: {}", .{err});
_ = self.command.wait() catch |err|
_ = self.command.wait(false) catch |err|
log.err("error waiting for command to exit: {}", .{err});
// Clean up our other members