1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! ATDD for man-page generation (#117).
//!
//! Renders the clap command tree through `clap_mangen` and asserts the
//! produced roff contains the binary name, a SYNOPSIS section, and one
//! page per declared subcommand. Pure in-memory check — no disk I/O —
//! so CI doesn't depend on `target/man/` layout. The
//! `examples/mangen.rs` binary uses the same `Cli::command()` entrypoint
//! to write the actual files.
use clap::CommandFactory;
use clap_mangen::Man;
use upskill::cli::Cli;
fn render(cmd: clap::Command) -> String {
let mut buffer = Vec::new();
Man::new(cmd).render(&mut buffer).unwrap();
String::from_utf8(buffer).unwrap()
}
#[test]
fn root_man_page_has_synopsis_and_name() {
let page = render(Cli::command());
assert!(page.contains("upskill"), "missing binary name: {page}");
assert!(page.contains("SYNOPSIS"), "missing SYNOPSIS section");
assert!(page.contains("DESCRIPTION"), "missing DESCRIPTION section");
}
#[test]
fn every_subcommand_renders_a_man_page() {
let root = Cli::command();
let names: Vec<String> = root
.get_subcommands()
.map(|s| s.get_name().to_string())
.collect();
// Sanity: the audit-driven CLI ships nine commands. If this drifts,
// update the assert and the docs.
assert_eq!(
names.len(),
9,
"expected 9 subcommands, got {}: {names:?}",
names.len()
);
for sub in root.get_subcommands() {
let page = render(sub.clone());
let name = sub.get_name();
assert!(
page.contains("SYNOPSIS"),
"{name} man page missing SYNOPSIS"
);
assert!(page.contains(name), "{name} man page missing its own name");
}
}
#[test]
fn root_man_page_documents_quiet_flag() {
// Smoke check that global flags surface in the rendered roff —
// `--quiet` was just added, so its presence proves the generator
// tracks the live `Cli` definition rather than a stale snapshot.
let page = render(Cli::command());
// roff escapes hyphens: `--quiet` is rendered as `\-\-quiet`.
assert!(
page.contains(r"\-\-quiet"),
"expected --quiet in root man page, got:\n{page}"
);
}