From fb545cf7a4f984409a8b018aa71cb8d7b93db8c7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 22:55:52 -0700 Subject: [PATCH] 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 '), 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. --- crates/komorebic-core/tests/docs_cli.rs | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 crates/komorebic-core/tests/docs_cli.rs diff --git a/crates/komorebic-core/tests/docs_cli.rs b/crates/komorebic-core/tests/docs_cli.rs new file mode 100644 index 00000000..afa06f06 --- /dev/null +++ b/crates/komorebic-core/tests/docs_cli.rs @@ -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::(&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()); +}