3 use super::bench::BenchSamples;
5 use super::types::TestDesc;
6 use super::options::ShouldPanic;
8 pub use self::TestResult::*;
10 // Return codes for secondary process.
11 // Start somewhere other than 0 so we know the return code means what we think
13 pub const TR_OK: i32 = 50;
14 pub const TR_FAILED: i32 = 51;
16 #[derive(Debug, Clone, PartialEq)]
23 TrBench(BenchSamples),
27 unsafe impl Send for TestResult {}
29 /// Creates a `TestResult` depending on the raw result of test execution
30 /// and assotiated data.
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(
53 format!("panic did not include expected string '{}'", msg)
58 (&ShouldPanic::Yes, Ok(())) => {
59 TestResult::TrFailedMsg("test did not panic as expected".to_string())
61 _ if desc.allow_fail => TestResult::TrAllowedFail,
62 _ => TestResult::TrFailed,
65 // If test is already failed (or allowed to fail), do not change the result.
66 if result != TestResult::TrOk {
70 // Check if test is failed due to timeout.
71 if let (Some(opts), Some(time)) = (time_opts, exec_time) {
72 if opts.error_on_excess && opts.is_critical(desc, time) {
73 return TestResult::TrTimedFail;
80 /// Creates a `TestResult` depending on the exit code of test subprocess.
81 pub fn get_result_from_exit_code(
84 time_opts: &Option<time::TestTimeOptions>,
85 exec_time: &Option<time::TestExecTime>,
87 let result = match (desc.allow_fail, code) {
88 (_, TR_OK) => TestResult::TrOk,
89 (true, TR_FAILED) => TestResult::TrAllowedFail,
90 (false, TR_FAILED) => TestResult::TrFailed,
91 (_, _) => TestResult::TrFailedMsg(format!("got unexpected return code {}", code)),
94 // If test is already failed (or allowed to fail), do not change the result.
95 if result != TestResult::TrOk {
99 // Check if test is failed due to timeout.
100 if let (Some(opts), Some(time)) = (time_opts, exec_time) {
101 if opts.error_on_excess && opts.is_critical(desc, time) {
102 return TestResult::TrTimedFail;