OXYGENHUB
◆ main oxygen / tests / cli_docs.rs
1.9 KiB · Rust · last changed Shell completions, man pages, and help for every argument 1 month ago source blame history raw
1
//! Shell completions and man pages come from the command definitions.
2
3
use std::process::Command;
4
5
fn oxy(args: &[&str]) -> (bool, String) {
6
    let out = Command::new(env!("CARGO_BIN_EXE_oxy"))
7
        .args(args)
8
        .env("NO_COLOR", "1")
9
        .output()
10
        .unwrap();
11
    (
12
        out.status.success(),
13
        String::from_utf8_lossy(&out.stdout).into_owned(),
14
    )
15
}
16
17
#[test]
18
fn completions_for_each_shell() {
19
    for (shell, marker) in [
20
        ("bash", "_oxy()"),
21
        ("zsh", "#compdef oxy"),
22
        ("fish", "complete -c oxy"),
23
        ("powershell", "Register-ArgumentCompleter"),
24
    ] {
25
        let (ok, text) = oxy(&["completions", shell]);
26
        assert!(ok, "{shell}");
27
        assert!(
28
            text.contains(marker),
29
            "{shell}: {}",
30
            &text[..text.len().min(200)]
31
        );
32
        assert!(
33
            text.contains("commit") && text.contains("doctor"),
34
            "{shell} knows the commands"
35
        );
36
    }
37
    assert!(
38
        !oxy(&["completions", "tcsh"]).0,
39
        "an unknown shell is refused"
40
    );
41
}
42
43
#[test]
44
fn man_pages_for_every_command() {
45
    let dir = tempfile::tempdir().unwrap();
46
    let (ok, _) = oxy(&["man", "--dir", &dir.path().to_string_lossy()]);
47
    assert!(ok);
48
    for page in [
49
        "oxy.1",
50
        "oxy-commit.1",
51
        "oxy-remote-add.1",
52
        "oxy-identity-delegate-add.1",
53
        "oxy-doctor.1",
54
    ] {
55
        let text = std::fs::read_to_string(dir.path().join(page))
56
            .unwrap_or_else(|_| panic!("{page} missing"));
57
        assert!(
58
            text.starts_with(".ie") || text.contains(".TH"),
59
            "{page} is roff"
60
        );
61
    }
62
    let commit = std::fs::read_to_string(dir.path().join("oxy-commit.1")).unwrap();
63
    assert!(
64
        commit.contains("subject line"),
65
        "argument help reaches the page"
66
    );
67
    let (ok, top) = oxy(&["man"]);
68
    assert!(ok && top.contains(".TH oxy"), "oxy man prints the top page");
69
}