From d9881466382093f3c29ebe3f36a7d09d72407837 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 17 May 2026 20:59:36 -0700 Subject: [PATCH] std.process.Child: add format and success methods --- lib/std/process.zig | 7 +++++++ lib/std/process/Child.zig | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/std/process.zig b/lib/std/process.zig index 9869bb2593ff21c864f599f95e9c2ae709ab4bab..bcee558a65eef07afab17b484cc012326bb5004c 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1113,3 +1113,10 @@ test protectMemory { protectMemory(&test_page, .{}) catch return error.SkipZigTest; protectMemory(&test_page, .{ .read = true, .write = true }) catch return error.SkipZigTest; } + +test { + _ = Child; + _ = Args; + _ = Environ; + _ = Preopens; +} diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig index 65f6429e59f399fcb34137587d3f73ac9a35c24b..a3cba3e7ece8ff9e34c9998bb47ff816e2586e5e 100644 --- a/lib/std/process/Child.zig +++ b/lib/std/process/Child.zig @@ -96,6 +96,22 @@ pub const Term = union(enum) { signal: std.posix.SIG, stopped: std.posix.SIG, unknown: u32, + + pub fn success(t: Term) bool { + return switch (t) { + .exited => |code| code == 0, + else => false, + }; + } + + pub fn format(t: Term, w: *Io.Writer) Io.Writer.Error!void { + switch (t) { + .exited => |code| return w.print("exited with code {d}", .{code}), + .signal => |sig| return w.print("terminated with signal {t}", .{sig}), + .stopped => |sig| return w.print("stopped with signal {t}", .{sig}), + .unknown => return w.writeAll("terminated unexpectedly"), + } + } }; pub const Cwd = union(enum) { @@ -135,3 +151,7 @@ pub fn wait(child: *Child, io: Io) WaitError!Term { assert(child.id != null); return io.vtable.childWait(io.userdata, child); } + +test { + _ = Term; +} -- 2.54.0