|
| 1 | +//! The following tests check whether the help text files are outdated. |
| 2 | +//! |
| 3 | +//! If the tests fail, run `./generate-completions.sh` on the root of the repo to update the help files. |
| 4 | +
|
| 5 | +// Since the CLI in Windows look a little different, and I am way too lazy to make two versions |
| 6 | +// of help files, the following tests would only run in UNIX-like environment. |
| 7 | +#![cfg(unix)] |
1 | 8 | #![cfg(feature = "cli")] |
2 | 9 |
|
3 | 10 | pub mod _utils; |
4 | 11 | pub use _utils::*; |
5 | 12 |
|
6 | 13 | use command_extra::CommandExtra; |
7 | 14 | use pipe_trait::Pipe; |
8 | | -use std::{ |
9 | | - fs, |
10 | | - path::PathBuf, |
11 | | - process::{Command, Stdio}, |
12 | | -}; |
13 | | - |
14 | | -fn exports_dir() -> PathBuf { |
15 | | - PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("exports") |
16 | | -} |
| 15 | +use std::process::{Command, Stdio}; |
17 | 16 |
|
18 | | -fn pdu_help(long: bool) -> String { |
19 | | - let flag = if long { "--help" } else { "-h" }; |
20 | | - Command::new(PDU) |
21 | | - .with_arg(flag) |
22 | | - .with_stdin(Stdio::null()) |
23 | | - .with_stdout(Stdio::piped()) |
24 | | - .with_stderr(Stdio::null()) |
25 | | - .output() |
26 | | - .unwrap_or_else(|error| panic!("failed to spawn pdu {flag}: {error}")) |
27 | | - .pipe(stdout_text) |
| 17 | +macro_rules! check { |
| 18 | + ($name:ident: $flag:literal => $path:literal) => { |
| 19 | + #[test] |
| 20 | + fn $name() { |
| 21 | + let actual = Command::new(PDU) |
| 22 | + .with_arg($flag) |
| 23 | + .with_stdin(Stdio::null()) |
| 24 | + .with_stdout(Stdio::piped()) |
| 25 | + .with_stderr(Stdio::null()) |
| 26 | + .output() |
| 27 | + .expect("get actual help text") |
| 28 | + .pipe(stdout_text); |
| 29 | + let expected = include_str!($path); |
| 30 | + assert!( |
| 31 | + actual == expected.trim_end(), |
| 32 | + "help text is outdated, run ./generate-completions.sh to update it", |
| 33 | + ); |
| 34 | + } |
| 35 | + }; |
28 | 36 | } |
29 | 37 |
|
30 | | -#[test] |
31 | | -fn long_help_is_up_to_date() { |
32 | | - let actual = pdu_help(true); |
33 | | - let expected = fs::read_to_string(exports_dir().join("long.help")) |
34 | | - .expect("read exports/long.help") |
35 | | - .trim_end() |
36 | | - .to_string(); |
37 | | - assert_eq!(actual, expected); |
38 | | -} |
39 | | - |
40 | | -#[test] |
41 | | -fn short_help_is_up_to_date() { |
42 | | - let actual = pdu_help(false); |
43 | | - let expected = fs::read_to_string(exports_dir().join("short.help")) |
44 | | - .expect("read exports/short.help") |
45 | | - .trim_end() |
46 | | - .to_string(); |
47 | | - assert_eq!(actual, expected); |
48 | | -} |
| 38 | +check!(long_help_is_up_to_date: "--help" => "../exports/long.help"); |
| 39 | +check!(short_help_is_up_to_date: "-h" => "../exports/short.help"); |
0 commit comments