use serde::Serialize;
use crate::{CaseMetadata, CommandReport, ConformanceProfile};
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct CaseResult {
pub case: CaseMetadata,
pub duration_ms: u64,
pub outcome: CaseOutcome,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case", tag = "kind")]
pub enum CaseOutcome {
Passed,
Failed {
details: String,
},
Skipped {
reason: String,
},
Error {
details: String,
},
TimedOut {
details: String,
},
}
impl CaseOutcome {
pub const fn is_passed(&self) -> bool {
matches!(self, Self::Passed)
}
pub const fn is_skipped(&self) -> bool {
matches!(self, Self::Skipped { .. })
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct SuiteReport {
pub crate_version: &'static str,
pub specification_version: &'static str,
pub host_platform: String,
pub candidate: CommandReport,
pub cases: Vec<CaseResult>,
#[serde(skip)]
pub profile: ConformanceProfile,
#[serde(skip)]
pub omitted_exact_case_count: usize,
}
impl SuiteReport {
pub const fn profile(&self) -> ConformanceProfile {
self.profile
}
pub const fn omitted_exact_case_count(&self) -> usize {
self.omitted_exact_case_count
}
pub fn passed(&self) -> bool {
!self.cases.is_empty()
&& self
.cases
.iter()
.all(|result| result.outcome.is_passed() || result.outcome.is_skipped())
}
pub fn passed_count(&self) -> usize {
self.cases
.iter()
.filter(|result| result.outcome.is_passed())
.count()
}
pub fn skipped_count(&self) -> usize {
self.cases
.iter()
.filter(|result| result.outcome.is_skipped())
.count()
}
}