Skip to content

Commit d8815cf

Browse files
Rollup merge of #52453 - srijs:fix-52436, r=TimNN
improve diagnostics for tests with custom return values This is an attempt at getting the ball rolling to improve the diagnostics for test functions that return custom `impl Termination` values (see #52436). An alternative could be to use `eprintln!`, but including this in the panic message felt nicely consistent with how failing test assertions would be reported. Let me know what you think!
2 parents 0f4b498 + 6411aef commit d8815cf

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libtest/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,14 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
324324
/// test is considered a failure. By default, invokes `report()`
325325
/// and checks for a `0` result.
326326
pub fn assert_test_result<T: Termination>(result: T) {
327-
assert_eq!(result.report(), 0);
327+
let code = result.report();
328+
assert_eq!(
329+
code,
330+
0,
331+
"the test returned a termination value with a non-zero status code ({}) \
332+
which indicates a failure",
333+
code
334+
);
328335
}
329336

330337
#[derive(Copy, Clone, Debug)]

0 commit comments

Comments
 (0)