use std::path::{Path, PathBuf};
use std::process::Command;
const MIN_EXAMPLES: usize = 8;
fn examples_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(Path::parent)
.expect("repo root from src/bao")
.join("examples")
}
#[test]
fn examples_compile_against_current_umbrella_api() {
let root = examples_root();
let mut dirs: Vec<PathBuf> = std::fs::read_dir(&root)
.unwrap_or_else(|e| panic!("read {}: {e}", root.display()))
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|p| p.is_dir() && p.join("Cargo.toml").is_file())
.collect();
dirs.sort();
assert!(
dirs.len() >= MIN_EXAMPLES,
"expected at least {MIN_EXAMPLES} examples, found {} — silently dropped?",
dirs.len()
);
for dir in &dirs {
let name = dir
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("<unnamed>");
let manifest = dir.join("Cargo.toml");
let out = Command::new("cargo")
.arg("check")
.arg("--manifest-path")
.arg(&manifest)
.output()
.unwrap_or_else(|e| panic!("spawn cargo for {name}: {e}"));
assert!(
out.status.success(),
"example {name} no longer compiles against the current API \
(documentation drift). Output:\n{}",
String::from_utf8_lossy(&out.stderr)
);
}
}