use dev_report::{CheckResult, Producer, Report, Severity};
use crate::{MutateRun, MutateThreshold};
pub struct MutateProducer {
run: MutateRun,
threshold: MutateThreshold,
}
impl MutateProducer {
pub fn new(run: MutateRun, threshold: MutateThreshold) -> Self {
Self { run, threshold }
}
}
impl Producer for MutateProducer {
fn produce(&self) -> Report {
let subject = self.run.subject().to_string();
let version = self.run.subject_version().to_string();
let mut report = Report::new(&subject, &version).with_producer("dev-mutate");
match self.run.execute() {
Ok(result) => {
report.push(result.into_check_result(self.threshold));
}
Err(e) => {
let check = CheckResult::fail(format!("mutate::{subject}"), Severity::Critical)
.with_detail(e.to_string())
.with_tag("mutate")
.with_tag("subprocess");
report.push(check);
}
}
report.finish();
report
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[ignore = "spawns inner `cargo mutants` 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_regardless_of_subprocess() {
let producer = MutateProducer::new(
MutateRun::new("self", "0.0.0"),
MutateThreshold::min_kill_pct(70.0),
);
let report = producer.produce();
assert_eq!(report.subject, "self");
assert!(!report.checks.is_empty());
}
}