authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 13:08:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 13:29:39-07:00
loge3bb06a984ea934d6db811937186b0eee981e8e8
treef9e8326d0f01b14d7500375c961376a65e2639f2
parentfee318c44ddac8d8d247aac78a8cfa5305ef6e69

std.Build.RunStep: show test name on process termination

This is a small change to help when reading failure logs which makes the "exited with code 1" and similar message include the test name. Further enhancements could do the following: * even if one unit test crashes the process, the parent process continues running the other unit tests * ability to test for expected panics (#1356) * timeouts on individual tests

1 files changed, 16 insertions(+), 3 deletions(-)

lib/std/Build/RunStep.zig+16-3
......@@ -822,9 +822,19 @@ fn runCommand(
822822 },
823823 },
824824 .zig_test => {
825 const prefix: []const u8 = p: {
826 if (result.stdio.test_metadata) |tm| {
827 if (tm.next_index <= tm.names.len) {
828 const name = tm.testName(tm.next_index - 1);
829 break :p b.fmt("while executing test '{s}', ", .{name});
830 }
831 }
832 break :p "";
833 };
825834 const expected_term: std.process.Child.Term = .{ .Exited = 0 };
826835 if (!termMatches(expected_term, result.term)) {
827 return step.fail("the following command {} (expected {}):\n{s}", .{
836 return step.fail("{s}the following command {} (expected {}):\n{s}", .{
837 prefix,
828838 fmtTerm(result.term),
829839 fmtTerm(expected_term),
830840 try Step.allocPrintCmd(arena, self.cwd, final_argv),
......@@ -832,8 +842,8 @@ fn runCommand(
832842 }
833843 if (!result.stdio.test_results.isSuccess()) {
834844 return step.fail(
835 "the following test command failed:\n{s}",
836 .{try Step.allocPrintCmd(arena, self.cwd, final_argv)},
845 "{s}the following test command failed:\n{s}",
846 .{ prefix, try Step.allocPrintCmd(arena, self.cwd, final_argv) },
837847 );
838848 }
839849 },
......@@ -922,6 +932,7 @@ const StdIoResult = struct {
922932 stdout_null: bool,
923933 stderr_null: bool,
924934 test_results: Step.TestResults,
935 test_metadata: ?TestMetadata,
925936};
926937
927938fn evalZigTest(
......@@ -1057,6 +1068,7 @@ fn evalZigTest(
10571068 .skip_count = skip_count,
10581069 .leak_count = leak_count,
10591070 },
1071 .test_metadata = metadata,
10601072 };
10611073}
10621074
......@@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
11721184 .stdout_null = stdout_null,
11731185 .stderr_null = stderr_null,
11741186 .test_results = .{},
1187 .test_metadata = null,
11751188 };
11761189}
11771190