From b4cc99168d7c5328cd8aaa61f39bdbab6710eb6e Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Tue, 31 May 2022 16:52:44 +0100 Subject: [PATCH] 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 ``` --- library/test/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 0c748da1a59cc..2b70bb4299ee6 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -182,8 +182,8 @@ fn make_owned_test(test: &&TestDescAndFn) -> TestDescAndFn { /// and checks for a `0` result. pub fn assert_test_result(result: T) { let code = result.report().to_i32(); - assert_eq!( - code, 0, + assert!( + code == 0, "the test returned a termination value with a non-zero status code ({}) \ which indicates a failure", code