use dev_report::{CheckResult, Producer, Report, Severity};
use crate::DepCheck;
pub struct DepProducer {
check: DepCheck,
}
impl DepProducer {
pub fn new(check: DepCheck) -> Self {
Self { check }
}
}
impl Producer for DepProducer {
fn produce(&self) -> Report {
match self.check.execute() {
Ok(result) => result.into_report(),
Err(e) => {
let mut report = Report::new(self.check.subject(), self.check.subject_version())
.with_producer("dev-deps");
let check = CheckResult::fail("deps::health", Severity::Critical)
.with_detail(e.to_string())
.with_tag("deps")
.with_tag("subprocess");
report.push(check);
report.finish();
report
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::DepScope;
#[test]
fn produce_returns_report_when_tool_missing() {
let producer = DepProducer::new(DepCheck::new("self", "0.0.0").scope(DepScope::Unused));
let report = producer.produce();
assert_eq!(report.subject, "self");
assert!(!report.checks.is_empty());
}
}