-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` library
Description
Consider this test:
#[cfg(test)]
mod tests {
#[test]
fn it_works() -> Result<(), String> {
if 2 + 2 != 4 {
Ok(())
} else {
Err(String::from("two plus two does not equal four"))
}
}
}
(note the !
) when this fails, you get
> cargo test
Compiling termination v0.1.0 (file:///C:/Users/steve/tmp/termination)
Finished dev [unoptimized + debuginfo] target(s) in 1.44s
Running target\debug\deps\termination-4b340b40460d3098.exe
running 1 test
test tests::it_works ... FAILED
failures:
---- tests::it_works stdout ----
Error: "two plus two does not equal four"
thread 'tests::it_works' panicked at 'assertion failed: `(left == right)`
left: `1`,
right: `0`', libtest\lib.rs:326:5
This is because it triggers this assert.
can we make this better somehow? 1 != 0
is not super helpful at learning why this test failed.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` library
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
scottmcm commentedon Jul 17, 2018
Hmm, the trait is super-unstable, so maybe it's be worth adding a purpose-built method for this? Like
But then the
Result
impl could override it to show something better...srijs commentedon Jul 17, 2018
What if it printed something like this?
Or simply
EDIT: Nevermind the first suggestion, that seems like it couldn't work because
Termination::report
sort of couples printing the message with returning a code.improve diagnostics for tests with custom return values
Rollup merge of rust-lang#52453 - srijs:fix-52436, r=TimNN