//! **`.nornir/build-variants.toml` IS the code's emission — and this fails for any
//! reason it is not.**
//!
//! The same guard holger carries, for the same reason. The file is a PROJECTION of
//! `src/lib.rs`: it describes the build for readers and for the doors that discover
//! a repo by that path, and it is never read back as authority. If the emission does
//! not say what you wanted, the recipe is missing something and THAT is the bug —
//! editing the toml changes nothing.
use holger_egui_build_thing::{declared, emitted_toml, repo_root, BuildThingTrait, HolgerEguiBuildThing};
use nornir_build_thing::emit::first_difference;
use nornir_build_thing::variant::BuildVariantSet;
#[test]
fn the_committed_toml_is_the_codes_emission_byte_for_byte() {
let emitted = emitted_toml().expect("the recipe emits");
let path = BuildVariantSet::conventional_path(&repo_root());
let committed =
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
if let Some(diff) = first_difference(&committed, &emitted) {
panic!(
"{} is not the code's emission — the code is the source. Run \
`cargo run -p holger-egui-build-thing -- emit` and commit the result; never edit \
the toml by hand. {diff}",
path.display()
);
}
let back = BuildVariantSet::from_toml_str(&emitted).expect("the emission parses back");
assert_eq!(back, declared());
back.validate_all().expect("and every rung validates");
}
#[test]
fn an_edited_toml_has_zero_effect_on_what_the_code_declares() {
let before = declared();
let edited = emitted_toml()
.unwrap()
.replace("name = \"ui-mini\"", "name = \"ui-mini-edited\"");
let read = BuildVariantSet::from_toml_str(&edited).expect("still parses");
assert_ne!(read, before, "the edit must be visible to a reader, else this proves nothing");
assert_eq!(HolgerEguiBuildThing.variants(), before, "the code read the file — it must not");
}
/// The four rungs, and the ladder's load-bearing values: one source package, four
/// distinct bins, each with its own tier feature, every one THIN except the named
/// embedded exception.
#[test]
fn the_committed_file_carries_the_four_rungs() {
let set = BuildVariantSet::load_file(&BuildVariantSet::conventional_path(&repo_root())).unwrap();
assert_eq!(set.variants.len(), 4, "4 [[build.variant]] rows");
assert_eq!(
set.names(),
vec!["ui", "ui-embedded", "ui-mini", "ui-mikro"],
"the ladder, in ladder order"
);
assert!(set.containers.is_empty(), "holger-egui packages no container");
assert!(set.installers.is_empty(), "…and no installer medium");
// A perturbation must be VISIBLE, or the comparison above proves nothing.
let mut p = set.clone();
p.variants[0].features.clear();
assert_ne!(p, set, "a rung losing its features must compare unequal");
}