Skip to content

Commit d17b9c1

Browse files
CopilotKSXGitHub
andcommitted
fix: restrict sync_help tests to unix only
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
1 parent b83af13 commit d17b9c1

1 file changed

Lines changed: 29 additions & 38 deletions

File tree

tests/sync_help.rs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
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)]
18
#![cfg(feature = "cli")]
29

310
pub mod _utils;
411
pub use _utils::*;
512

613
use command_extra::CommandExtra;
714
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};
1716

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+
};
2836
}
2937

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

Comments
 (0)