xtask/tests/docs_name_our_home.rs
//! **The docs name our repositories' real home** (A28 L17 / A29-23).
//!
//! The constellation left the old forge: a `README.md` or a `.nornir/*.md` that still sends a
//! reader to one of our organisations there (or to its pages host) sends them to a dead or stale
//! place. This test reads the top-level docs and fails on the first such URL. The old forge as a
//! forge (a mirror source, a driver) is not our home and is not matched.
use std::path::{Path, PathBuf};
/// Our organisations on the old forge, and its pages host, spelled so a search finds only real uses.
fn stale() -> Vec<String> {
let forge = concat!("code", "berg", ".org/");
let mut s: Vec<String> = ["nordisk/", "mikronova/", "vetra/"].iter().map(|o| format!("{forge}{o}")).collect();
s.push(concat!("code", "berg", ".page").to_string());
s
}
fn repo_root() -> PathBuf {
let start = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
start.ancestors().find(|d| d.join(".git").exists()).map(Path::to_path_buf).unwrap_or_else(|| start.parent().unwrap().to_path_buf())
}
#[test]
fn the_docs_name_no_old_home_of_ours() {
let root = repo_root();
let mut docs = vec![root.join("README.md")];
if let Ok(entries) = std::fs::read_dir(root.join(".nornir")) {
docs.extend(entries.flatten().map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "md")));
}
let stale = stale();
let mut found = Vec::new();
for doc in docs {
let Ok(text) = std::fs::read_to_string(&doc) else { continue };
for (i, line) in text.lines().enumerate() {
if let Some(s) = stale.iter().find(|s| line.contains(s.as_str())) {
found.push(format!("{}:{}: names {s}", doc.strip_prefix(&root).unwrap_or(&doc).display(), i + 1));
}
}
}
assert!(found.is_empty(), "our repositories live on git.gunnar.rs:\n{}", found.join("\n"));
}