test(komorebic-core): the macOS pages in docs/cli are what the command line renders

Renders the macOS command line through komorebic-core (it needs no macOS to do it) and compares every page with komorebi-for-mac/docs/cli after the page transform macOS uses (a heading, 'Usage: komorebic <name>'), and the number of pages. It found the four macOS pages that step 2 left stale (the previous revision regenerates them) and keeps all 158 in step from now on. The test returns early when the macOS tree is not in the source (the nix build of the Windows workspace).

Verified: native cargo test -p komorebic-core --test docs_cli: 1 passed.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent f84a941795
commit fb545cf7a4
1 file changed
+49
+49
View File
@@ -0,0 +1,49 @@
//! The pages of `docs/cli` that are checked in are what the command line renders today.
use komorebic_core::cli::Meta;
use komorebic_core::cli::command;
use komorebic_core::docgen::DocFormat;
use komorebic_core::docgen::pages;
use komorebic_core::platform::macos::MacosCommands;
use std::path::Path;
const META: Meta = Meta {
name: "komorebic",
about: "",
author: "",
version: "",
};
/// The pages of komorebic for macOS have a heading, and the usage line has the name of the binary.
fn macos_page(name: &str, page: &str) -> String {
let command = name.trim_end_matches(".md");
let page = page.replacen(
&format!("Usage: {command}"),
&format!("Usage: komorebic {command}"),
1,
);
format!("# {command}\n\n{page}")
}
#[test]
fn every_macos_page_is_as_checked_in() {
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../komorebi-for-mac/docs/cli");
if !dir.is_dir() {
// a source tree without the macOS tree (the nix build of the Windows workspace)
return;
}
let rendered = pages(command::<MacosCommands>(&META), &DocFormat::PLAIN);
let mut stale = Vec::new();
for (name, page) in &rendered {
let checked_in = std::fs::read_to_string(dir.join(name)).unwrap_or_default();
if checked_in != macos_page(name, page) {
stale.push(name.as_str());
}
}
assert!(
stale.is_empty(),
"stale pages in komorebi-for-mac/docs/cli: {stale:?}"
);
assert_eq!(rendered.len(), std::fs::read_dir(&dir).unwrap().count());
}