X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibtest%2Ftest_result.rs;h=bfa572c887a522005d649f93a47b4d80ba839529;hb=88429fb5e250d61e60578e3ed5de4ac2d56567a8;hp=80ca9dea18f5aff3ab26b4d57964850ddd7315bc;hpb=91fd6283e658e2c7aab2d3f5206fc1891f486af2;p=rust.git diff --git a/src/libtest/test_result.rs b/src/libtest/test_result.rs index 80ca9dea18f..bfa572c887a 100644 --- a/src/libtest/test_result.rs +++ b/src/libtest/test_result.rs @@ -1,9 +1,9 @@ use std::any::Any; use super::bench::BenchSamples; +use super::options::ShouldPanic; use super::time; use super::types::TestDesc; -use super::options::ShouldPanic; pub use self::TestResult::*; @@ -32,27 +32,35 @@ pub fn calc_result<'a>( desc: &TestDesc, task_result: Result<(), &'a (dyn Any + 'static + Send)>, time_opts: &Option, - exec_time: &Option + exec_time: &Option, ) -> TestResult { let result = match (&desc.should_panic, task_result) { (&ShouldPanic::No, Ok(())) | (&ShouldPanic::Yes, Err(_)) => TestResult::TrOk, (&ShouldPanic::YesWithMessage(msg), Err(ref err)) => { - if err + let maybe_panic_str = err .downcast_ref::() .map(|e| &**e) - .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)) - .map(|e| e.contains(msg)) - .unwrap_or(false) - { + .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)); + + if maybe_panic_str.map(|e| e.contains(msg)).unwrap_or(false) { TestResult::TrOk + } else if desc.allow_fail { + TestResult::TrAllowedFail + } else if let Some(panic_str) = maybe_panic_str { + TestResult::TrFailedMsg(format!( + r#"panic did not contain expected string + panic message: `{:?}`, + expected substring: `{:?}`"#, + panic_str, msg + )) } else { - if desc.allow_fail { - TestResult::TrAllowedFail - } else { - TestResult::TrFailedMsg( - format!("panic did not include expected string '{}'", msg) - ) - } + TestResult::TrFailedMsg(format!( + r#"expected panic with string value, + found non-string value: `{:?}` + expected substring: `{:?}`"#, + (**err).type_id(), + msg + )) } } (&ShouldPanic::Yes, Ok(())) => {