Skip to content

Commit

Permalink
std.Build.RunStep: show test name on process termination
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andrewrk committed Apr 28, 2023
1 parent fee318c commit e3bb06a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/std/Build/RunStep.zig
Original file line number Diff line number Diff line change
Expand Up @@ -822,18 +822,28 @@ fn runCommand(
},
},
.zig_test => {
const prefix: []const u8 = p: {
if (result.stdio.test_metadata) |tm| {
if (tm.next_index <= tm.names.len) {
const name = tm.testName(tm.next_index - 1);
break :p b.fmt("while executing test '{s}', ", .{name});
}
}
break :p "";
};
const expected_term: std.process.Child.Term = .{ .Exited = 0 };
if (!termMatches(expected_term, result.term)) {
return step.fail("the following command {} (expected {}):\n{s}", .{
return step.fail("{s}the following command {} (expected {}):\n{s}", .{
prefix,
fmtTerm(result.term),
fmtTerm(expected_term),
try Step.allocPrintCmd(arena, self.cwd, final_argv),
});
}
if (!result.stdio.test_results.isSuccess()) {
return step.fail(
"the following test command failed:\n{s}",
.{try Step.allocPrintCmd(arena, self.cwd, final_argv)},
"{s}the following test command failed:\n{s}",
.{ prefix, try Step.allocPrintCmd(arena, self.cwd, final_argv) },
);
}
},
Expand Down Expand Up @@ -922,6 +932,7 @@ const StdIoResult = struct {
stdout_null: bool,
stderr_null: bool,
test_results: Step.TestResults,
test_metadata: ?TestMetadata,
};

fn evalZigTest(
Expand Down Expand Up @@ -1057,6 +1068,7 @@ fn evalZigTest(
.skip_count = skip_count,
.leak_count = leak_count,
},
.test_metadata = metadata,
};
}

Expand Down Expand Up @@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
.stdout_null = stdout_null,
.stderr_null = stderr_null,
.test_results = .{},
.test_metadata = null,
};
}

Expand Down

0 comments on commit e3bb06a

Please sign in to comment.