use std::path::PathBuf;
use crate::exit::ExitCode;
#[derive(Debug, Clone)]
pub enum Verdict {
Ok,
ExpectedFailButPassed,
ExpectedPassButFailed {
stderr: String,
},
SnapshotDiff {
diff: String,
},
SnapshotMissing {
actual: String,
},
Blessed {
snapshot_path: PathBuf,
},
Timeout,
MemoryExhausted,
WorkerCrashed {
cause: String,
},
SnapshotDiffTooLarge {
actual_lines: usize,
expected_lines: usize,
actual_head: String,
expected_head: String,
},
MalformedDiagnostic {
byte_offset: usize,
source: MalformedSource,
},
}
#[derive(Debug, Clone)]
pub enum MalformedSource {
RustcRendered,
Snapshot,
}
impl Verdict {
pub fn exit_code(&self) -> ExitCode {
match self {
Self::Ok | Self::Blessed { .. } => ExitCode::Ok,
Self::ExpectedFailButPassed
| Self::ExpectedPassButFailed { .. }
| Self::SnapshotDiff { .. } => ExitCode::SnapshotDiffOrUnexpected,
Self::SnapshotMissing { .. } => ExitCode::SnapshotMissing,
Self::Timeout => ExitCode::Timeout,
Self::MemoryExhausted => ExitCode::MemoryExhausted,
Self::WorkerCrashed { .. } => ExitCode::WorkerCrashed,
Self::SnapshotDiffTooLarge { .. } => ExitCode::SnapshotDiffTooLarge,
Self::MalformedDiagnostic { .. } => ExitCode::MalformedDiagnostic,
}
}
pub fn label(&self) -> &'static str {
match self {
Self::Ok => "OK",
Self::ExpectedFailButPassed => "EXPECTED_FAIL_BUT_PASSED",
Self::ExpectedPassButFailed { .. } => "EXPECTED_PASS_BUT_FAILED",
Self::SnapshotDiff { .. } => "SNAPSHOT_DIFF",
Self::SnapshotMissing { .. } => "SNAPSHOT_MISSING",
Self::Blessed { .. } => "BLESSED",
Self::Timeout => "TIMEOUT",
Self::MemoryExhausted => "MEMORY_EXHAUSTED",
Self::WorkerCrashed { .. } => "WORKER_CRASHED",
Self::SnapshotDiffTooLarge { .. } => "SNAPSHOT_DIFF_TOO_LARGE",
Self::MalformedDiagnostic { .. } => "MALFORMED_DIAGNOSTIC",
}
}
pub fn is_pass(&self) -> bool {
matches!(self, Self::Ok | Self::Blessed { .. })
}
}
#[derive(Debug, Clone)]
pub struct FixtureResult {
pub relative_path: String,
pub verdict: Verdict,
pub cleanup_failure: Option<CleanupFailure>,
pub wall_ms: u64,
pub warning: Option<FixtureWarning>,
}
#[derive(Debug, Clone)]
pub enum FixtureWarning {
LargeSnapshot {
expected_lines: usize,
actual_lines: usize,
},
}
#[derive(Debug, Clone)]
pub struct CleanupFailure {
pub path: PathBuf,
pub message: String,
}