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(...@@ -822,9 +822,19 @@ fn runCommand(
822 },822 },
823 },823 },
824 .zig_test => {824 .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 };
825 const expected_term: std.process.Child.Term = .{ .Exited = 0 };834 const expected_term: std.process.Child.Term = .{ .Exited = 0 };
826 if (!termMatches(expected_term, result.term)) {835 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,
828 fmtTerm(result.term),838 fmtTerm(result.term),
829 fmtTerm(expected_term),839 fmtTerm(expected_term),
830 try Step.allocPrintCmd(arena, self.cwd, final_argv),840 try Step.allocPrintCmd(arena, self.cwd, final_argv),
...@@ -832,8 +842,8 @@ fn runCommand(...@@ -832,8 +842,8 @@ fn runCommand(
832 }842 }
833 if (!result.stdio.test_results.isSuccess()) {843 if (!result.stdio.test_results.isSuccess()) {
834 return step.fail(844 return step.fail(
835 "the following test command failed:\n{s}",845 "{s}the following test command failed:\n{s}",
836 .{try Step.allocPrintCmd(arena, self.cwd, final_argv)},846 .{ prefix, try Step.allocPrintCmd(arena, self.cwd, final_argv) },
837 );847 );
838 }848 }
839 },849 },
...@@ -922,6 +932,7 @@ const StdIoResult = struct {...@@ -922,6 +932,7 @@ const StdIoResult = struct {
922 stdout_null: bool,932 stdout_null: bool,
923 stderr_null: bool,933 stderr_null: bool,
924 test_results: Step.TestResults,934 test_results: Step.TestResults,
935 test_metadata: ?TestMetadata,
925};936};
926937
927fn evalZigTest(938fn evalZigTest(
...@@ -1057,6 +1068,7 @@ fn evalZigTest(...@@ -1057,6 +1068,7 @@ fn evalZigTest(
1057 .skip_count = skip_count,1068 .skip_count = skip_count,
1058 .leak_count = leak_count,1069 .leak_count = leak_count,
1059 },1070 },
1071 .test_metadata = metadata,
1060 };1072 };
1061}1073}
10621074
...@@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {...@@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
1172 .stdout_null = stdout_null,1184 .stdout_null = stdout_null,
1173 .stderr_null = stderr_null,1185 .stderr_null = stderr_null,
1174 .test_results = .{},1186 .test_results = .{},
1187 .test_metadata = null,
1175 };1188 };
1176}1189}
11771190