From 465b4df6eab0aaaf7127b2e3bdf8445214d259b6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 Nov 2022 21:04:31 -0800 Subject: [PATCH] fix tests for WNOHANG commit --- src/Command.zig | 12 ++++++------ src/termio/Exec.zig | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Command.zig b/src/Command.zig index 1e63d9161..ba11090d5 100644 --- a/src/Command.zig +++ b/src/Command.zig @@ -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); diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 1909d2025..6d061450f 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -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