use crate::{Res, load_config};
use std::process::Command;
pub(crate) fn cmd_test() -> Res {
let config = load_config()?;
eprintln!("Running plugin tests...\n");
let mut all_passed = true;
for p in &config.plugin {
eprint!(" {} ... ", p.name);
let status = Command::new("cargo")
.args(["test", "-p", &p.crate_name, "--", "--quiet"])
.output()?;
let stderr = String::from_utf8_lossy(&status.stderr);
if status.status.success() {
let test_line = stderr.lines().find(|l| l.contains("test result"));
if let Some(line) = test_line {
eprintln!("{}", line.trim());
} else {
eprintln!("PASS");
}
} else {
eprintln!("FAIL");
eprint!("{}", stderr);
all_passed = false;
}
}
if all_passed {
eprintln!("All tests passed.");
Ok(())
} else {
Err("Some tests failed".into())
}
}