#![allow(clippy::manual_assert, clippy::panic)]
#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::fs;
use std::path::{Path, PathBuf};
fn workspace_root() -> PathBuf {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
loop {
let toml = p.join("Cargo.toml");
if toml.exists() {
let text = fs::read_to_string(&toml).unwrap_or_default();
if text.contains("[workspace]") {
return p;
}
}
if !p.pop() {
panic!("could not locate workspace root");
}
}
}
fn collect_rs_files(dir: &Path, out: &mut Vec<PathBuf>) {
let Ok(entries) = fs::read_dir(dir) else {
return;
};
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
collect_rs_files(&path, out);
} else if path.extension().and_then(|s| s.to_str()) == Some("rs") {
out.push(path);
}
}
}
#[test]
fn exactly_one_parse_auth_binding_user_input_in_cli_src() {
let root = workspace_root();
let cli_src = root.join("meerkat-cli/src");
assert!(
cli_src.is_dir(),
"expected meerkat-cli/src to exist at {}",
cli_src.display()
);
let mut files = Vec::new();
collect_rs_files(&cli_src, &mut files);
let needle = "fn parse_auth_binding_user_input";
let mut hits: Vec<(PathBuf, usize)> = Vec::new();
for path in &files {
let Ok(body) = fs::read_to_string(path) else {
continue;
};
for (lineno, line) in body.lines().enumerate() {
if line.contains(needle) {
hits.push((path.clone(), lineno + 1));
}
}
}
assert_eq!(
hits.len(),
1,
"expected exactly one `fn parse_auth_binding_user_input` in \
meerkat-cli/src, found {}. The CLI must have a single \
AuthBindingRef parser at the input boundary (C-12). Hits:\n{}",
hits.len(),
hits.iter()
.map(|(p, ln)| format!(" {}:{}", p.display(), ln))
.collect::<Vec<_>>()
.join("\n")
);
}