pub fn diagnose(root: &Path) -> Vec<Diagnostic>Expand description
Everything wrong with where the version is stated: the projection against the authority, and every version written down by hand where the tool’s own files live.
A stale projection is a Severity::Warning — it is the state every bump leaves until
scripts/derive runs, generate --check is what refuses it, and a writer that refused
its own un-derived state could not correct a bump it had just made. A projection nothing
could have derived, and a version written by hand, are Severity::Errors. Asked only
where the product lives: a repository without the crate has its own scripts/ and its
own versions, and they are none of this module’s business.
use majordomus_cli::release::compat::Severity;
use majordomus_cli::release::version::{diagnose, MANIFEST, PROJECTION};
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
std::fs::create_dir_all(root.join("apps/majordomus-cli")).unwrap();
std::fs::create_dir_all(root.join("share")).unwrap();
std::fs::create_dir_all(root.join("lib")).unwrap();
std::fs::write(root.join(MANIFEST), "[package]\nversion = \"0.9.0\"\n").unwrap();
std::fs::write(root.join(PROJECTION), "version=0.9.0\n").unwrap();
assert!(diagnose(root).is_empty(), "authored once, projected once");
std::fs::write(root.join("lib/x.sh"), "FOO_VERSION=\"1.2.3\"\n").unwrap();
let found = diagnose(root);
assert_eq!(found.len(), 1);
assert_eq!(found[0].id, "version-stated-by-hand");
assert_eq!(found[0].severity, Severity::Error);