WIP red: four ways of shipping a document the .gitignore walk misses (improvise-c0aj)

This commit is contained in:
Edward Langley
2026-09-23 08:54:15 -07:00
parent 5932ad749f
commit 4e52d06838
+79
View File
@@ -30,6 +30,14 @@ fn documents_in(dir: &Path) -> Vec<PathBuf> {
found
}
/// Every shipped document under `root`: the walk the test below loads.
fn shipped_documents(root: &Path) -> Vec<PathBuf> {
shipped_directories(root)
.iter()
.flat_map(|dir| documents_in(dir))
.collect()
}
#[test]
fn every_shipped_document_loads() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
@@ -60,3 +68,74 @@ fn every_shipped_document_loads() {
}
}
}
/// A scratch repository, so each way of shipping a document is set up for real.
fn scratch_repo() -> tempfile::TempDir {
let dir = tempfile::tempdir().expect("a temp dir");
run_git(dir.path(), &["init", "-q"]);
dir
}
fn run_git(root: &Path, args: &[&str]) {
let status = std::process::Command::new("git")
.arg("-C")
.arg(root)
.args(args)
.status()
.expect("git runs");
assert!(status.success(), "git {args:?} failed");
}
fn write(root: &Path, rel: &str, text: &str) {
let path = root.join(rel);
std::fs::create_dir_all(path.parent().expect("a parent")).expect("dirs");
std::fs::write(path, text).expect("writes");
}
fn walked(root: &Path, rel: &str) -> bool {
shipped_documents(root).contains(&root.join(rel))
}
/// improvise-c0aj: one test per way of shipping a document that reading the
/// root `.gitignore` missed. Evidence: `context/test-evidence/tui.md`.
#[test]
fn a_single_file_un_ignore_is_walked() {
let repo = scratch_repo();
let root = repo.path();
write(root, ".gitignore", "*.improv\n!web/demo.improv\n");
write(root, "web/demo.improv", "x");
run_git(root, &["add", ".gitignore", "web/demo.improv"]);
assert!(walked(root, "web/demo.improv"));
}
#[test]
fn a_gzipped_document_is_walked() {
let repo = scratch_repo();
let root = repo.path();
write(root, ".gitignore", "*.improv\n");
write(root, "docs/model.improv.gz", "x");
run_git(root, &["add", ".gitignore", "docs/model.improv.gz"]);
assert!(walked(root, "docs/model.improv.gz"));
}
#[test]
fn a_document_un_ignored_by_a_nested_gitignore_is_walked() {
let repo = scratch_repo();
let root = repo.path();
write(root, ".gitignore", "*.improv\n");
write(root, "harness/.gitignore", "!keep.improv\n");
write(root, "harness/keep.improv", "x");
run_git(root, &["add", ".gitignore", "harness/.gitignore", "harness/keep.improv"]);
assert!(walked(root, "harness/keep.improv"));
}
#[test]
fn a_force_added_document_is_walked() {
let repo = scratch_repo();
let root = repo.path();
write(root, ".gitignore", "*.improv\n");
write(root, "secret/forced.improv", "x");
run_git(root, &["add", ".gitignore"]);
run_git(root, &["add", "-f", "secret/forced.improv"]);
assert!(walked(root, "secret/forced.improv"));
}