4 use super::bench::BenchSamples;
6 use super::types::TestDesc;
7 use super::options::ShouldPanic;
9 pub use self::TestResult::*;
11 // Return codes for secondary process.
12 // Start somewhere other than 0 so we know the return code means what we think
14 pub const TR_OK: i32 = 50;
15 pub const TR_FAILED: i32 = 51;
17 #[derive(Debug, Clone, PartialEq)]
24 TrBench(BenchSamples),
28 unsafe impl Send for TestResult {}
31 pub fn calc_result<'a>(
33 task_result: Result<(), &'a (dyn Any + 'static + Send)>,
34 time_opts: &Option<time::TestTimeOptions>,
35 exec_time: &Option<time::TestExecTime>
37 let result = match (&desc.should_panic, task_result) {
38 (&ShouldPanic::No, Ok(())) | (&ShouldPanic::Yes, Err(_)) => TestResult::TrOk,
39 (&ShouldPanic::YesWithMessage(msg), Err(ref err)) => {
41 .downcast_ref::<String>()
43 .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e))
44 .map(|e| e.contains(msg))
50 TestResult::TrAllowedFail
52 TestResult::TrFailedMsg(format!("panic did not include expected string '{}'", msg))
56 (&ShouldPanic::Yes, Ok(())) => TestResult::TrFailedMsg("test did not panic as expected".to_string()),
57 _ if desc.allow_fail => TestResult::TrAllowedFail,
58 _ => TestResult::TrFailed,
61 // If test is already failed (or allowed to fail), do not change the result.
62 if result != TestResult::TrOk {
66 // Check if test is failed due to timeout.
67 if let (Some(opts), Some(time)) = (time_opts, exec_time) {
68 if opts.error_on_excess && opts.is_critical(desc, time) {
69 return TestResult::TrTimedFail;
76 pub fn get_result_from_exit_code(
79 time_opts: &Option<time::TestTimeOptions>,
80 exec_time: &Option<time::TestExecTime>,
82 let result = match (desc.allow_fail, code) {
83 (_, TR_OK) => TestResult::TrOk,
84 (true, TR_FAILED) => TestResult::TrAllowedFail,
85 (false, TR_FAILED) => TestResult::TrFailed,
86 (_, _) => TestResult::TrFailedMsg(format!("got unexpected return code {}", code)),
89 // If test is already failed (or allowed to fail), do not change the result.
90 if result != TestResult::TrOk {
94 // Check if test is failed due to timeout.
95 if let (Some(opts), Some(time)) = (time_opts, exec_time) {
96 if opts.error_on_excess && opts.is_critical(desc, time) {
97 return TestResult::TrTimedFail;