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!
This commit is contained in:
Guillaume Gomez 2018-08-15 19:20:19 +02:00 committed by GitHub
commit d8815cfe7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)]