diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-01-28 15:09:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-28 15:09:04 +0900 |
| commit | 98226638fd014ec7786878a0b102448f3530bcdb (patch) | |
| tree | ef0823a99c280875e9f065888dd83b715bafe99b | |
| parent | 446edd1e1a4e024949a84533e027da9d384b79f7 (diff) | |
| parent | b43aa960d0a7d09f137cc6b7f26605f6183cd72f (diff) | |
| download | rust-98226638fd014ec7786878a0b102448f3530bcdb.tar.gz rust-98226638fd014ec7786878a0b102448f3530bcdb.zip | |
Rollup merge of #80868 - johanngan:should-panic-msg-with-expected, r=m-ou-se
Print failure message on all tests that should panic, but don't Fixes #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.
| -rw-r--r-- | library/test/src/test_result.rs | 2 | ||||
| -rw-r--r-- | library/test/src/tests.rs | 39 |
2 files changed, 25 insertions, 16 deletions
diff --git a/library/test/src/test_result.rs b/library/test/src/test_result.rs index 465f3f8f994..598fb670bb4 100644 --- a/library/test/src/test_result.rs +++ b/library/test/src/test_result.rs @@ -63,7 +63,7 @@ pub fn calc_result<'a>( )) } } - (&ShouldPanic::Yes, Ok(())) => { + (&ShouldPanic::Yes, Ok(())) | (&ShouldPanic::YesWithMessage(_), Ok(())) => { TestResult::TrFailedMsg("test did not panic as expected".to_string()) } _ if desc.allow_fail => TestResult::TrAllowedFail, diff --git a/library/test/src/tests.rs b/library/test/src/tests.rs index 74313cc4438..a629829b885 100644 --- a/library/test/src/tests.rs +++ b/library/test/src/tests.rs @@ -228,21 +228,30 @@ fn test_should_panic_non_string_message_type() { #[test] #[cfg(not(target_os = "emscripten"))] fn test_should_panic_but_succeeds() { - fn f() {} - let desc = TestDescAndFn { - desc: TestDesc { - name: StaticTestName("whatever"), - ignore: false, - should_panic: ShouldPanic::Yes, - allow_fail: false, - test_type: TestType::Unknown, - }, - testfn: DynTestFn(Box::new(f)), - }; - let (tx, rx) = channel(); - run_test(&TestOpts::new(), false, desc, RunStrategy::InProcess, tx, Concurrent::No); - let result = rx.recv().unwrap().result; - assert_eq!(result, TrFailedMsg("test did not panic as expected".to_string())); + let should_panic_variants = [ShouldPanic::Yes, ShouldPanic::YesWithMessage("error message")]; + + for &should_panic in should_panic_variants.iter() { + fn f() {} + let desc = TestDescAndFn { + desc: TestDesc { + name: StaticTestName("whatever"), + ignore: false, + should_panic, + allow_fail: false, + test_type: TestType::Unknown, + }, + testfn: DynTestFn(Box::new(f)), + }; + let (tx, rx) = channel(); + run_test(&TestOpts::new(), false, desc, RunStrategy::InProcess, tx, Concurrent::No); + let result = rx.recv().unwrap().result; + assert_eq!( + result, + TrFailedMsg("test did not panic as expected".to_string()), + "should_panic == {:?}", + should_panic + ); + } } fn report_time_test_template(report_time: bool) -> Option<TestExecTime> { |
