Skip to content

Commit

Permalink
Rollup merge of rust-lang#52453 - srijs:fix-52436, r=TimNN
Browse files Browse the repository at this point in the history
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 rust-lang#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!
  • Loading branch information
GuillaumeGomez authored Aug 15, 2018
2 parents 0f4b498 + 6411aef commit d8815cf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,14 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
/// test is considered a failure. By default, invokes `report()`
/// and checks for a `0` result.
pub fn assert_test_result<T: Termination>(result: T) {
assert_eq!(result.report(), 0);
let code = result.report();
assert_eq!(
code,
0,
"the test returned a termination value with a non-zero status code ({}) \
which indicates a failure",
code
);
}

#[derive(Copy, Clone, Debug)]
Expand Down

0 comments on commit d8815cf

Please sign in to comment.