Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

Commit e2a4b62

Browse files
LukasKalbertodtgnzlbg
authored andcommitted
Improve output when #[test] returns an Err(_) value
Output before: ---- foo stdout ---- Error: Os { code: 2, kind: NotFound, message: "No such file or directory" } thread 'foo' panicked at 'assertion failed: `(left == right)` left: `1`, right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', src/libtest/lib.rs:335:5 Output with this commit: ---- foo stdout ---- Error: Os { code: 2, kind: NotFound, message: "No such file or directory" } thread 'foo' panicked at 'the test returned a termination value with a non-zero status code (1) which indicates a failure (this most likely means your test returned an `Err(_)`)', src/libtest/lib.rs:336:9 It's still by no means perfect. But it's already way better since there is no strange left/right 0/1 output (I regularly got confused by that output and searched for a failing `assert_eq` in my code)
1 parent 03a45d7 commit e2a4b62

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libtest/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
305305
/// and checks for a `0` result.
306306
pub fn assert_test_result<T: Termination>(result: T) {
307307
let code = result.report();
308-
assert_eq!(
309-
code, 0,
310-
"the test returned a termination value with a non-zero status code ({}) \
311-
which indicates a failure",
312-
code
313-
);
308+
if code != 0 {
309+
panic!(
310+
"the test returned a termination value with a non-zero status code ({}) \
311+
which indicates a failure (this most likely means your test returned \
312+
an `Err(_)` value)",
313+
code,
314+
);
315+
}
314316
}
315317

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

0 commit comments

Comments
 (0)