use super::*;
use crate::testrepo::TestRepo;
fn labels(root: &Path, nodes: &[PathBuf]) -> Vec<String> {
nodes.iter().map(|n| node_label(root, n)).collect()
}
fn tree(tag: &str, ignore: &str, files: &[&str]) -> Result<TestRepo, String> {
let r = TestRepo::new(tag)?;
r.write(".gitignore", ignore)?;
r.write("docs/README.md", "x\n")?;
r.commit("fixture")?;
for f in files {
r.write(f, "# SPEC\n")?;
}
Ok(r)
}
#[test]
fn a_gitignored_scratch_checkout_is_not_a_node() -> Result<(), String> {
let r = tree("fed-ignored", "scratch/\n", &["scratch/other/SPEC.md"])?;
let root = r.path();
assert_eq!(labels(root, &discover(root)), vec!["."]);
r.write(".gitignore", "")?;
assert_eq!(labels(root, &discover(root)), vec![".", "scratch/other"]);
Ok(())
}
#[test]
fn an_ignored_spec_file_does_not_make_its_dir_a_node() -> Result<(), String> {
let r = tree("fed-ignored-file", "docs/SPEC.md\n", &["docs/SPEC.md"])?;
let root = r.path();
assert_eq!(labels(root, &discover(root)), vec!["."]);
r.write(".gitignore", "")?;
assert_eq!(labels(root, &discover(root)), vec![".", "docs"]);
Ok(())
}
#[test]
fn the_fixed_list_holds_for_tracked_dirs() -> Result<(), String> {
let r = tree("fed-floor", "", &["vendor/dep/SPEC.md", "src/SPEC.md"])?;
r.commit("tracked")?;
let root = r.path();
assert_eq!(labels(root, &discover(root)), vec![".", "src"]);
Ok(())
}
#[test]
fn outside_a_work_tree_the_walk_is_unchanged() -> Result<(), String> {
let r = tree(
"fed-nogit",
"scratch/\n",
&["scratch/SPEC.md", "target/SPEC.md"],
)?;
std::fs::remove_dir_all(r.path().join(".git"))
.map_err(|e| e.to_string())?;
let root = r.path();
assert_eq!(labels(root, &discover(root)), vec![".", "scratch"]);
Ok(())
}
#[test]
fn an_ignored_dir_is_not_a_missing_federation_row() -> Result<(), String> {
let r = tree("fed-exhaustive", "scratch/\n", &["scratch/x"])?;
let root = r.path();
let (_, missing) = find_exhaustive_violations(&[], root);
assert_eq!(missing, vec![root.join("docs")]);
r.write(".gitignore", "")?;
let (_, mut missing) = find_exhaustive_violations(&[], root);
missing.sort();
assert_eq!(missing, vec![root.join("docs"), root.join("scratch")]);
Ok(())
}
#[test]
fn an_ignored_rust_file_is_not_measured() -> Result<(), String> {
let r = tree("fed-rust", "scratch/\n", &["scratch/big.rs", "src/lib.rs"])?;
let root = r.path();
assert_eq!(rust_files(root), vec![root.join("src/lib.rs")]);
r.write(".gitignore", "")?;
let all = vec![root.join("scratch/big.rs"), root.join("src/lib.rs")];
assert_eq!(rust_files(root), all);
Ok(())
}
#[test]
fn an_ignored_script_is_not_read() -> Result<(), String> {
let r = tree("fed-sh", "scratch/\n", &["scratch/x.sh", "bin/y.sh"])?;
let root = r.path();
assert_eq!(script_files(root), vec![root.join("bin/y.sh")]);
r.write(".gitignore", "")?;
let all = vec![root.join("bin/y.sh"), root.join("scratch/x.sh")];
assert_eq!(script_files(root), all);
Ok(())
}