use dev_report::{CheckResult, Producer, Report, Severity};
use crate::FlakyRun;
pub struct FlakyProducer {
run: FlakyRun,
}
impl FlakyProducer {
pub fn new(run: FlakyRun) -> Self {
Self { run }
}
}
impl Producer for FlakyProducer {
fn produce(&self) -> Report {
match self.run.execute() {
Ok(result) => result.into_report(),
Err(e) => {
let mut report = Report::new(self.run.subject(), self.run.subject_version())
.with_producer("dev-flaky");
let check = CheckResult::fail("flaky::scan", Severity::Critical)
.with_detail(e.to_string())
.with_tag("flaky")
.with_tag("subprocess");
report.push(check);
report.finish();
report
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[ignore = "spawns inner `cargo test` which deadlocks on the workspace target-dir lock when run from `cargo test`; run with CARGO_TARGET_DIR outside the workspace via `cargo test -- --ignored`"]
fn produce_returns_report_when_subprocess_fails() {
let producer = FlakyProducer::new(FlakyRun::new("self", "0.0.0").iterations(2));
let report = producer.produce();
assert_eq!(report.subject, "self");
assert!(!report.checks.is_empty());
}
}