litcheck_lit/test/
status.rs1use std::fmt;
2
3#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
4pub enum TestStatus {
5 #[default]
6 Unresolved,
7 Excluded,
8 Skipped,
9 Pass,
10 FlakyPass,
11 Fail,
12 Xfail,
13 Xpass,
14 Timeout,
15 Unsupported,
16}
17impl TestStatus {
18 pub fn tag(&self) -> &'static str {
19 match self {
20 Self::Excluded => "EXCLUDED",
21 Self::Skipped => "SKIPPED",
22 Self::Unsupported => "UNSUPPORTED",
23 Self::Pass => "PASS",
24 Self::FlakyPass => "FLAKYPASS",
25 Self::Xfail => "XFAIL",
26 Self::Unresolved => "UNRESOLVED",
27 Self::Timeout => "TIMEOUT",
28 Self::Fail => "FAIL",
29 Self::Xpass => "XPASS",
30 }
31 }
32
33 pub fn label(&self) -> &'static str {
34 match self {
35 Self::Excluded => "Excluded",
36 Self::Skipped => "Skipped",
37 Self::Unsupported => "Unsupported",
38 Self::Pass => "Passed",
39 Self::FlakyPass => "Passed With Retry",
40 Self::Xfail => "Failed As Expected",
41 Self::Unresolved => "Unresolved",
42 Self::Timeout => "Timed Out",
43 Self::Fail => "Failed",
44 Self::Xpass => "Unexpectedly Passed",
45 }
46 }
47
48 pub fn is_failure(&self) -> bool {
49 matches!(
50 self,
51 Self::Unresolved | Self::Timeout | Self::Fail | Self::Xpass
52 )
53 }
54}
55impl From<std::process::ExitStatus> for TestStatus {
56 fn from(status: std::process::ExitStatus) -> Self {
57 match status.code() {
58 None => TestStatus::Unresolved,
59 Some(0) => TestStatus::Pass,
60 Some(_) => TestStatus::Fail,
61 }
62 }
63}
64impl fmt::Display for TestStatus {
65 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66 f.write_str(self.label())
67 }
68}