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 {}
30 /// Creates a `TestResult` depending on the raw result of test execution
31 /// and assotiated data.
32 pub fn calc_result<'a>(
34 task_result: Result<(), &'a (dyn Any + 'static + Send)>,
35 time_opts: &Option<time::TestTimeOptions>,
36 exec_time: &Option<time::TestExecTime>
38 let result = match (&desc.should_panic, task_result) {
39 (&ShouldPanic::No, Ok(())) | (&ShouldPanic::Yes, Err(_)) => TestResult::TrOk,
40 (&ShouldPanic::YesWithMessage(msg), Err(ref err)) => {
42 .downcast_ref::<String>()
44 .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e))
45 .map(|e| e.contains(msg))
51 TestResult::TrAllowedFail
53 TestResult::TrFailedMsg(format!("panic did not include expected string '{}'", msg))
57 (&ShouldPanic::Yes, Ok(())) => TestResult::TrFailedMsg("test did not panic as expected".to_string()),
58 _ if desc.allow_fail => TestResult::TrAllowedFail,
59 _ => TestResult::TrFailed,
62 // If test is already failed (or allowed to fail), do not change the result.
63 if result != TestResult::TrOk {
67 // Check if test is failed due to timeout.
68 if let (Some(opts), Some(time)) = (time_opts, exec_time) {
69 if opts.error_on_excess && opts.is_critical(desc, time) {
70 return TestResult::TrTimedFail;
77 /// Creates a `TestResult` depending on the exit code of test subprocess.
78 pub fn get_result_from_exit_code(
81 time_opts: &Option<time::TestTimeOptions>,
82 exec_time: &Option<time::TestExecTime>,
84 let result = match (desc.allow_fail, code) {
85 (_, TR_OK) => TestResult::TrOk,
86 (true, TR_FAILED) => TestResult::TrAllowedFail,
87 (false, TR_FAILED) => TestResult::TrFailed,
88 (_, _) => TestResult::TrFailedMsg(format!("got unexpected return code {}", code)),
91 // If test is already failed (or allowed to fail), do not change the result.
92 if result != TestResult::TrOk {
96 // Check if test is failed due to timeout.
97 if let (Some(opts), Some(time)) = (time_opts, exec_time) {
98 if opts.error_on_excess && opts.is_critical(desc, time) {
99 return TestResult::TrTimedFail;