Skip to content

Commit 7fbe8d5

Browse files
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 070cebd commit 7fbe8d5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/libtest/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,14 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
332332
/// and checks for a `0` result.
333333
pub fn assert_test_result<T: Termination>(result: T) {
334334
let code = result.report();
335-
assert_eq!(
336-
code, 0,
337-
"the test returned a termination value with a non-zero status code ({}) \
338-
which indicates a failure",
339-
code
340-
);
335+
if code != 0 {
336+
panic!(
337+
"the test returned a termination value with a non-zero status code ({}) \
338+
which indicates a failure (this most likely means your test returned \
339+
an `Err(_)` value)",
340+
code,
341+
);
342+
}
341343
}
342344

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

0 commit comments

Comments
 (0)