| 1 | //! Various data structures used for carrying information about test success or failure |
| 2 | |
| 3 | use crate::{status_emitter::TestStatus, AbortCheck, Error}; |
| 4 | use bstr::ByteSlice; |
| 5 | use color_eyre::eyre::Result; |
| 6 | |
| 7 | /// The possible non-failure results a single test can have. |
| 8 | #[derive (Debug)] |
| 9 | pub enum TestOk { |
| 10 | /// The test passed |
| 11 | Ok, |
| 12 | /// The test was ignored due to a rule (`//@only-*` or `//@ignore-*`) |
| 13 | Ignored, |
| 14 | } |
| 15 | |
| 16 | /// The possible results a single test can have. |
| 17 | pub type TestResult = Result<TestOk, Errored>; |
| 18 | |
| 19 | /// Information about a test failure. |
| 20 | pub struct Errored { |
| 21 | /// Command that failed |
| 22 | pub(crate) command: String, |
| 23 | /// The errors that were encountered. |
| 24 | pub(crate) errors: Vec<Error>, |
| 25 | /// The full stderr of the test run. |
| 26 | pub(crate) stderr: Vec<u8>, |
| 27 | /// The full stdout of the test run. |
| 28 | pub(crate) stdout: Vec<u8>, |
| 29 | } |
| 30 | |
| 31 | impl std::fmt::Debug for Errored { |
| 32 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 33 | writeln!(f, "command: {}" , self.command)?; |
| 34 | writeln!(f, "errors: {:#?}" , self.errors)?; |
| 35 | writeln!(f, "stderr: {}" , self.stderr.to_str_lossy())?; |
| 36 | writeln!(f, "stdout: {}" , self.stdout.to_str_lossy())?; |
| 37 | Ok(()) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | impl Errored { |
| 42 | /// If no command was executed for this error, use a message instead. |
| 43 | pub fn new(errors: Vec<Error>, message: &str) -> Self { |
| 44 | Self { |
| 45 | errors, |
| 46 | stderr: vec![], |
| 47 | stdout: vec![], |
| 48 | command: message.into(), |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | pub(crate) fn aborted() -> Errored { |
| 53 | Self::new(errors:vec![], message:"aborted" ) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /// Result of an actual test or sub-test (revision, fixed, run, ...) including its status. |
| 58 | pub struct TestRun { |
| 59 | /// Actual test run output. |
| 60 | pub result: TestResult, |
| 61 | /// Usually created via `for_revsion` or `for_path` |
| 62 | pub status: Box<dyn TestStatus>, |
| 63 | /// Whether the run was aborted prematurely |
| 64 | pub abort_check: AbortCheck, |
| 65 | } |
| 66 | |