Skip to content

Commit b4cc991

Browse files
authored
Less confusing message for failed test returning Result
Failure message contained a part that is related to `assert_eq!` matcher. This is confusing in the cases when test fails because of Err result. Test: ```rust #[test] fn test() -> Result<(), &'static str> { Err("some failure")?; assert_eq!(1, 2); Ok(()) } ``` Before: ``` ---- tests::test stdout ---- Error: "some failure" thread 'tests::test' 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', /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/test/src/lib.rs:187:5 ``` After: ``` ---- tests::test stdout ---- Error: "some failure" thread 'tests::test' panicked at 'the test returned a termination value with a non-zero status code (1) which indicates a failure', /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/test/src/lib.rs:187:5 ```
1 parent 16a0d03 commit b4cc991

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/test/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ fn make_owned_test(test: &&TestDescAndFn) -> TestDescAndFn {
182182
/// and checks for a `0` result.
183183
pub fn assert_test_result<T: Termination>(result: T) {
184184
let code = result.report().to_i32();
185-
assert_eq!(
186-
code, 0,
185+
assert!(
186+
code == 0,
187187
"the test returned a termination value with a non-zero status code ({}) \
188188
which indicates a failure",
189189
code

0 commit comments

Comments
 (0)