You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of #60790, a #[should_panic]#[test] produces a helpful error message when it fails because there was no panic. However, a #[should_panic(expected = *)]#[test] still fails with no error message in this case.
When run with cargo test, no_panic() fails with the message "note: test did not panic as expected", but no_panic_with_expected() still fails with no message:
test tests::no_panic ... FAILED
test tests::no_panic_with_expected ... FAILED
failures:
---- tests::no_panic stdout ----
note: test did not panic as expected
failures:
tests::no_panic
tests::no_panic_with_expected
Suggested Fix
I'm not totally confident here (I've only just started learning Rust), but I think this is an oversight with this match arm. The relevant pattern is currently (&ShouldPanic::Yes, Ok(())), which doesn't catch the ShouldPanic::YesWithMessage variant. I believe it should instead be something like (&ShouldPanic::Yes, Ok(())) | (&ShouldPanic::YesWithMessage(_), Ok(())).
johanngan
changed the title
Tests with #[should_panic(expected = *)] should print a message on failure
Tests with #[should_panic(expected = *)] should print a failure message if no panic occurs
Jan 10, 2021
…ected, r=m-ou-se
Print failure message on all tests that should panic, but don't
Fixesrust-lang#80861. Tests with the `#[should_panic]` attribute should always print a failure message if no panic occurs, regardless of whether or not an `expected` panic message is specified.
…ected, r=m-ou-se
Print failure message on all tests that should panic, but don't
Fixesrust-lang#80861. Tests with the `#[should_panic]` attribute should always print a failure message if no panic occurs, regardless of whether or not an `expected` panic message is specified.
As of #60790, a
#[should_panic]
#[test]
produces a helpful error message when it fails because there was no panic. However, a#[should_panic(expected = *)]
#[test]
still fails with no error message in this case.For example, consider the following two tests:
When run with
cargo test
,no_panic()
fails with the message "note: test did not panic as expected", butno_panic_with_expected()
still fails with no message:Suggested Fix
I'm not totally confident here (I've only just started learning Rust), but I think this is an oversight with this
match
arm. The relevant pattern is currently(&ShouldPanic::Yes, Ok(()))
, which doesn't catch theShouldPanic::YesWithMessage
variant. I believe it should instead be something like(&ShouldPanic::Yes, Ok(())) | (&ShouldPanic::YesWithMessage(_), Ok(()))
.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: