use std::fs;
use std::process;
use anyhow;
fn examples() -> anyhow::Result<Vec<String>> {
let mut paths: Vec<_> = fs::read_dir("./examples")?
.filter_map(|f| f.ok())
.filter(|e| {
e.path().is_file()
&& e.file_name().to_str()
.filter(|name| name.ends_with(".rs"))
.is_some()
})
.map(|e| {
e.file_name().to_str()
.map(|name| {
String::from(&name[..name.len()-3])
})
.unwrap()
})
.collect();
paths.sort();
Ok(paths)
}
#[cfg_attr(not(feature = "build-bin"), ignore)]
#[test]
fn cargo_what() -> anyhow::Result<()> {
for example in examples()? {
let status = process::Command::new("./target/debug/cargo-what")
.arg(format!("--example={}", example))
.status()?;
assert!(status.success());
}
Ok(())
}