-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Less confusing message for failed test returning Result #97586
Conversation
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 ```
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) soon. Please see the contribution instructions for more information. |
This may close #69517. |
@@ -182,8 +182,8 @@ fn make_owned_test(test: &&TestDescAndFn) -> TestDescAndFn { | |||
/// and checks for a `0` result. | |||
pub fn assert_test_result<T: Termination>(result: T) { | |||
let code = result.report().to_i32(); | |||
assert_eq!( | |||
code, 0, | |||
assert!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_eq
also accepts an error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was assert_eq with error message. It results in confusing output, please see examples in initial comment or diff's comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bors r+ |
And without test and/or comment, this can be accidentally changed back. |
@bors r- Good call! We can add a test pretty easily along the lines of src/test/ui/test-attrs/test-panic-abort-nocapture.rs, which runs some tests and captures the stdout in src/test/ui/test-attrs/test-panic-abort-nocapture.run.stdout. (Obviously, we don't need the panic=abort-ness for this test). |
☔ The latest upstream changes (presumably #102586) made this pull request unmergeable. Please resolve the merge conflicts. |
It seems that this PR was unmergable (by the time it was accepted) and the issue was simply closed. Would a new PR allow the issue to be reopened? The original problem is that test functions cannot report meaningful errors if they return a Err(E) from a |
@printercu @Mark-Simulacrum Would you consider re-submitting this? |
@bobhy As I understand tests will try to print error into stderr if it is |
That is true and a slight improvement. But we've also lost the line number in the process.
|
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:
Before:
After:
Fixes #69517