use anyhow::{Context, Result};
use std::path::PathBuf;
use std::process::Command;
pub fn run(manifest_path: &Option<PathBuf>, filter: Option<String>) -> Result<()> {
let mut cmd = Command::new("cargo");
cmd.arg("test");
cmd.arg("--examples");
if let Some(ref path) = manifest_path {
cmd.arg("--manifest-path").arg(path);
}
if let Some(filter) = filter {
cmd.arg("--").arg(filter);
}
let status = cmd
.status()
.context("failed to run `cargo test --examples` — is Cargo installed?")?;
if !status.success() {
anyhow::bail!(
"tests failed with exit code: {}",
status.code().unwrap_or(-1)
);
}
Ok(())
}