Merge pull request #5351 from epage/snap

chore: Update snapbox/trycmd
This commit is contained in:
Ed Page 2024-02-14 19:45:07 -06:00 committed by GitHub
commit b48c90fc64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 417 additions and 376 deletions

31
Cargo.lock generated
View file

@ -3022,9 +3022,9 @@ checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]] [[package]]
name = "snapbox" name = "snapbox"
version = "0.4.16" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73145a30df4935f50a7b13c1882bce7d194d7071ad0bcc36e7cacbf9ef16e3ec" checksum = "8269b717f21b142c0377f1e617e80999e3ef6b1c010959b44fd93320722d2cba"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -3045,9 +3045,9 @@ dependencies = [
[[package]] [[package]]
name = "snapbox-macros" name = "snapbox-macros"
version = "0.3.7" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ccde059aad940984ff696fe8c280900f7ea71a6fb45fce65071a3f2c40b667" checksum = "e1c4b838b05d15ab22754068cb73500b2f3b07bf09d310e15b27f88160f1de40"
dependencies = [ dependencies = [
"anstream", "anstream",
] ]
@ -3354,20 +3354,20 @@ dependencies = [
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"winnow", "winnow 0.5.17",
] ]
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.21.1" version = "0.22.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" checksum = "99e68c159e8f5ba8a28c4eb7b0c0c190d77bb479047ca713270048145a9ad28a"
dependencies = [ dependencies = [
"indexmap 2.1.0", "indexmap 2.1.0",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"winnow", "winnow 0.6.1",
] ]
[[package]] [[package]]
@ -3387,9 +3387,9 @@ dependencies = [
[[package]] [[package]]
name = "trycmd" name = "trycmd"
version = "0.14.20" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7ad3a033f38ca4d9eedf36ba792622027119c61b62b57970c5bed42cfd0c40d" checksum = "464edb3603a81a50b4c8f47b11dfade69ef48ffdc0af2f8b194ad87cbda75317"
dependencies = [ dependencies = [
"glob", "glob",
"humantime", "humantime",
@ -3398,7 +3398,7 @@ dependencies = [
"serde", "serde",
"shlex", "shlex",
"snapbox", "snapbox",
"toml_edit 0.21.1", "toml_edit 0.22.5",
] ]
[[package]] [[package]]
@ -4132,6 +4132,15 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winnow"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d90f4e0f530c4c69f62b80d839e9ef3855edc9cba471a160c4d692deed62b401"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.52.0" version = "0.52.0"

View file

@ -109,9 +109,9 @@ clap_derive = { path = "./clap_derive", version = "=4.5.0", optional = true }
trybuild = "1.0.89" trybuild = "1.0.89"
rustversion = "1.0.14" rustversion = "1.0.14"
# Cutting out `filesystem` feature # Cutting out `filesystem` feature
trycmd = { version = "0.14.20", default-features = false, features = ["color-auto", "diff", "examples"] } trycmd = { version = "0.15.0", default-features = false, features = ["color-auto", "diff", "examples"] }
humantime = "2.1.0" humantime = "2.1.0"
snapbox = "0.4.16" snapbox = "0.5.0"
shlex = "1.3.0" shlex = "1.3.0"
[[example]] [[example]]

View file

@ -42,9 +42,9 @@ shlex = { version = "1.1.0", optional = true }
unicode-xid = { version = "0.2.2", optional = true } unicode-xid = { version = "0.2.2", optional = true }
[dev-dependencies] [dev-dependencies]
snapbox = { version = "0.4.16", features = ["diff", "path", "examples"] } snapbox = { version = "0.5.0", features = ["diff", "path", "examples"] }
# Cutting out `filesystem` feature # Cutting out `filesystem` feature
trycmd = { version = "0.14.20", default-features = false, features = ["color-auto", "diff", "examples"] } trycmd = { version = "0.15.0", default-features = false, features = ["color-auto", "diff", "examples"] }
completest = "0.4.0" completest = "0.4.0"
completest-pty = "0.5.0" completest-pty = "0.5.0"
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "derive", "help"] } clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "derive", "help"] }

View file

@ -4,8 +4,8 @@ use crate::common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.bash", snapbox::file!["../snapshots/basic.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.bash", snapbox::file!["../snapshots/feature_sample.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.bash", snapbox::file!["../snapshots/special_commands.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.bash", snapbox::file!["../snapshots/quoting.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.bash", snapbox::file!["../snapshots/aliases.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.bash", snapbox::file!["../snapshots/sub_subcommands.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -77,8 +77,8 @@ fn custom_bin_name() {
let name = "my-app"; let name = "my-app";
let bin_name = "bin-name"; let bin_name = "bin-name";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/custom_bin_name.bash", snapbox::file!["../snapshots/custom_bin_name.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
bin_name, bin_name,
@ -89,8 +89,8 @@ fn custom_bin_name() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.bash", snapbox::file!["../snapshots/value_hint.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -101,8 +101,8 @@ fn value_hint() {
fn value_terminator() { fn value_terminator() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_terminator_command(name); let cmd = common::value_terminator_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_terminator.bash", snapbox::file!["../snapshots/value_terminator.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -124,15 +124,15 @@ fn register_minimal() {
.unwrap(); .unwrap();
snapbox::Assert::new() snapbox::Assert::new()
.action_env("SNAPSHOTS") .action_env("SNAPSHOTS")
.matches_path("tests/snapshots/register_minimal.bash", buf); .matches(snapbox::file!["../snapshots/register_minimal.bash"], buf);
} }
#[test] #[test]
fn two_multi_valued_arguments() { fn two_multi_valued_arguments() {
let name = "my-app"; let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name); let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/two_multi_valued_arguments.bash", snapbox::file!["../snapshots/two_multi_valued_arguments.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -143,8 +143,8 @@ fn two_multi_valued_arguments() {
fn subcommand_last() { fn subcommand_last() {
let name = "my-app"; let name = "my-app";
let cmd = common::subcommand_last(name); let cmd = common::subcommand_last(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/subcommand_last.bash", snapbox::file!["../snapshots/subcommand_last.bash"],
clap_complete::shells::Bash, clap_complete::shells::Bash,
cmd, cmd,
name, name,
@ -241,7 +241,7 @@ fn complete() {
} }
let input = "exhaustive hint --other \t"; let input = "exhaustive hint --other \t";
let expected = "exhaustive hint --other % exhaustive hint --other "; let expected = snapbox::str!["exhaustive hint --other % exhaustive hint --other "];
let actual = runtime.complete(input, &term).unwrap(); let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual); snapbox::assert_eq(expected, actual);
} }

View file

@ -281,8 +281,8 @@ pub fn subcommand_last(name: &'static str) -> clap::Command {
.subcommands([clap::Command::new("foo"), clap::Command::new("bar")]) .subcommands([clap::Command::new("foo"), clap::Command::new("bar")])
} }
pub fn assert_matches_path( pub fn assert_matches(
expected_path: impl AsRef<std::path::Path>, expected: impl Into<snapbox::Data>,
gen: impl clap_complete::Generator, gen: impl clap_complete::Generator,
mut cmd: clap::Command, mut cmd: clap::Command,
name: &'static str, name: &'static str,
@ -291,9 +291,9 @@ pub fn assert_matches_path(
clap_complete::generate(gen, &mut cmd, name, &mut buf); clap_complete::generate(gen, &mut cmd, name, &mut buf);
snapbox::Assert::new() snapbox::Assert::new()
.action_env("SNAPSHOTS") .action_env(snapbox::DEFAULT_ACTION_ENV)
.normalize_paths(false) .normalize_paths(false)
.matches_path(expected_path, buf); .matches(expected, buf);
} }
pub fn register_example<R: completest::RuntimeBuilder>(context: &str, name: &str) { pub fn register_example<R: completest::RuntimeBuilder>(context: &str, name: &str) {

View file

@ -23,9 +23,11 @@ fn suggest_subcommand_subset() {
.subcommand(Command::new("goodbye-world")); .subcommand(Command::new("goodbye-world"));
snapbox::assert_eq( snapbox::assert_eq(
"hello-moon snapbox::str![
"hello-moon
hello-world hello-world
help\tPrint this message or the help of the given subcommand(s)", help\tPrint this message or the help of the given subcommand(s)"
],
complete!(cmd, "he"), complete!(cmd, "he"),
); );
} }
@ -50,9 +52,11 @@ fn suggest_long_flag_subset() {
); );
snapbox::assert_eq( snapbox::assert_eq(
"--hello-world snapbox::str![
"--hello-world
--hello-moon --hello-moon
--help\tPrint help", --help\tPrint help"
],
complete!(cmd, "--he"), complete!(cmd, "--he"),
); );
} }
@ -67,8 +71,10 @@ fn suggest_possible_value_subset() {
])); ]));
snapbox::assert_eq( snapbox::assert_eq(
"hello-world\tSay hello to the world snapbox::str![
hello-moon", "hello-world\tSay hello to the world
hello-moon"
],
complete!(cmd, "hello"), complete!(cmd, "hello"),
); );
} }
@ -93,10 +99,12 @@ fn suggest_additional_short_flags() {
); );
snapbox::assert_eq( snapbox::assert_eq(
"-aa snapbox::str![
"-aa
-ab -ab
-ac -ac
-ah\tPrint help", -ah\tPrint help"
],
complete!(cmd, "-a"), complete!(cmd, "-a"),
); );
} }
@ -112,11 +120,13 @@ fn suggest_subcommand_positional() {
)); ));
snapbox::assert_eq( snapbox::assert_eq(
"--help\tPrint help (see more with '--help') snapbox::str![
"--help\tPrint help (see more with '--help')
-h\tPrint help (see more with '--help') -h\tPrint help (see more with '--help')
hello-world\tSay hello to the world hello-world\tSay hello to the world
hello-moon hello-moon
goodbye-world", goodbye-world"
],
complete!(cmd, "hello-world [TAB]"), complete!(cmd, "hello-world [TAB]"),
); );
} }

View file

@ -4,8 +4,8 @@ use crate::common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.elvish", snapbox::file!["../snapshots/basic.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.elvish", snapbox::file!["../snapshots/feature_sample.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.elvish", snapbox::file!["../snapshots/special_commands.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.elvish", snapbox::file!["../snapshots/quoting.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.elvish", snapbox::file!["../snapshots/aliases.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.elvish", snapbox::file!["../snapshots/sub_subcommands.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -77,8 +77,8 @@ fn custom_bin_name() {
let name = "my-app"; let name = "my-app";
let bin_name = "bin-name"; let bin_name = "bin-name";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/custom_bin_name.elvish", snapbox::file!["../snapshots/custom_bin_name.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
bin_name, bin_name,
@ -89,8 +89,8 @@ fn custom_bin_name() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.elvish", snapbox::file!["../snapshots/value_hint.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -101,8 +101,8 @@ fn value_hint() {
fn value_terminator() { fn value_terminator() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_terminator_command(name); let cmd = common::value_terminator_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_terminator.elvish", snapbox::file!["../snapshots/value_terminator.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -113,8 +113,8 @@ fn value_terminator() {
fn two_multi_valued_arguments() { fn two_multi_valued_arguments() {
let name = "my-app"; let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name); let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/two_multi_valued_arguments.elvish", snapbox::file!["../snapshots/two_multi_valued_arguments.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -125,8 +125,8 @@ fn two_multi_valued_arguments() {
fn subcommand_last() { fn subcommand_last() {
let name = "my-app"; let name = "my-app";
let cmd = common::subcommand_last(name); let cmd = common::subcommand_last(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/subcommand_last.elvish", snapbox::file!["../snapshots/subcommand_last.elvish"],
clap_complete::shells::Elvish, clap_complete::shells::Elvish,
cmd, cmd,
name, name,
@ -151,7 +151,8 @@ fn complete() {
common::load_runtime::<completest_pty::ElvishRuntimeBuilder>("static", "exhaustive"); common::load_runtime::<completest_pty::ElvishRuntimeBuilder>("static", "exhaustive");
let input = "exhaustive \t"; let input = "exhaustive \t";
let expected = r#"% exhaustive --generate let expected = snapbox::str![
r#"% exhaustive --generate
COMPLETING argument COMPLETING argument
--generate generate --generate generate
--global everywhere --global everywhere
@ -167,7 +168,8 @@ hint hint
last last last last
pacman pacman pacman pacman
quote quote quote quote
value value "#; value value "#
];
let actual = runtime.complete(input, &term).unwrap(); let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual); snapbox::assert_eq(expected, actual);
} }

View file

@ -4,8 +4,8 @@ use crate::common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.fish", snapbox::file!["../snapshots/basic.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.fish", snapbox::file!["../snapshots/feature_sample.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.fish", snapbox::file!["../snapshots/special_commands.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.fish", snapbox::file!["../snapshots/quoting.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.fish", snapbox::file!["../snapshots/aliases.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.fish", snapbox::file!["../snapshots/sub_subcommands.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -77,8 +77,8 @@ fn custom_bin_name() {
let name = "my-app"; let name = "my-app";
let bin_name = "bin-name"; let bin_name = "bin-name";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/custom_bin_name.fish", snapbox::file!["../snapshots/custom_bin_name.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
bin_name, bin_name,
@ -89,8 +89,8 @@ fn custom_bin_name() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.fish", snapbox::file!["../snapshots/value_hint.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -101,8 +101,8 @@ fn value_hint() {
fn value_terminator() { fn value_terminator() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_terminator_command(name); let cmd = common::value_terminator_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_terminator.fish", snapbox::file!["../snapshots/value_terminator.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -113,8 +113,8 @@ fn value_terminator() {
fn two_multi_valued_arguments() { fn two_multi_valued_arguments() {
let name = "my-app"; let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name); let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/two_multi_valued_arguments.fish", snapbox::file!["../snapshots/two_multi_valued_arguments.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -125,8 +125,8 @@ fn two_multi_valued_arguments() {
fn subcommand_last() { fn subcommand_last() {
let name = "my-app"; let name = "my-app";
let cmd = common::subcommand_last(name); let cmd = common::subcommand_last(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/subcommand_last.fish", snapbox::file!["../snapshots/subcommand_last.fish"],
clap_complete::shells::Fish, clap_complete::shells::Fish,
cmd, cmd,
name, name,
@ -182,17 +182,20 @@ fn complete_dynamic() {
common::load_runtime::<completest_pty::FishRuntimeBuilder>("dynamic", "exhaustive"); common::load_runtime::<completest_pty::FishRuntimeBuilder>("dynamic", "exhaustive");
let input = "exhaustive \t"; let input = "exhaustive \t";
let expected = r#"% exhaustive let expected = snapbox::str![
r#"% exhaustive
action last -V (Print version) action last -V (Print version)
alias pacman --generate (generate) alias pacman --generate (generate)
complete (Register shell completions for this program) quote --global (everywhere) complete (Register shell completions for this program) quote --global (everywhere)
help (Print this message or the help of the given subcommand(s)) value --help (Print help) help (Print this message or the help of the given subcommand(s)) value --help (Print help)
hint -h (Print help) --version (Print version)"#; hint -h (Print help) --version (Print version)"#
];
let actual = runtime.complete(input, &term).unwrap(); let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual); snapbox::assert_eq(expected, actual);
let input = "exhaustive quote \t"; let input = "exhaustive quote \t";
let expected = r#"% exhaustive quote let expected = snapbox::str![
r#"% exhaustive quote
cmd-backslash (Avoid '\n') cmd-backslash (Avoid '\n')
cmd-backticks (For more information see `echo test`) cmd-backticks (For more information see `echo test`)
cmd-brackets (List packages [filter]) cmd-brackets (List packages [filter])
@ -211,7 +214,8 @@ help (Print this message or the help of the given subcommand(s))
--global (everywhere) --global (everywhere)
--help (Print help) --help (Print help)
--single-quotes (Can be 'always', 'auto', or 'never') --single-quotes (Can be 'always', 'auto', or 'never')
--version (Print version)"#; --version (Print version)"#
];
let actual = runtime.complete(input, &term).unwrap(); let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual); snapbox::assert_eq(expected, actual);
} }

View file

@ -4,8 +4,8 @@ use crate::common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.ps1", snapbox::file!["../snapshots/basic.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.ps1", snapbox::file!["../snapshots/feature_sample.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.ps1", snapbox::file!["../snapshots/special_commands.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.ps1", snapbox::file!["../snapshots/quoting.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.ps1", snapbox::file!["../snapshots/aliases.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.ps1", snapbox::file!["../snapshots/sub_subcommands.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -77,8 +77,8 @@ fn custom_bin_name() {
let name = "my-app"; let name = "my-app";
let bin_name = "bin-name"; let bin_name = "bin-name";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/custom_bin_name.ps1", snapbox::file!["../snapshots/custom_bin_name.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
bin_name, bin_name,
@ -89,8 +89,8 @@ fn custom_bin_name() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.ps1", snapbox::file!["../snapshots/value_hint.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -101,8 +101,8 @@ fn value_hint() {
fn value_terminator() { fn value_terminator() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_terminator_command(name); let cmd = common::value_terminator_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_terminator.ps1", snapbox::file!["../snapshots/value_terminator.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -113,8 +113,8 @@ fn value_terminator() {
fn two_multi_valued_arguments() { fn two_multi_valued_arguments() {
let name = "my-app"; let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name); let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/two_multi_valued_arguments.ps1", snapbox::file!["../snapshots/two_multi_valued_arguments.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,
@ -125,8 +125,8 @@ fn two_multi_valued_arguments() {
fn subcommand_last() { fn subcommand_last() {
let name = "my-app"; let name = "my-app";
let cmd = common::subcommand_last(name); let cmd = common::subcommand_last(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/subcommand_last.ps1", snapbox::file!["../snapshots/subcommand_last.ps1"],
clap_complete::shells::PowerShell, clap_complete::shells::PowerShell,
cmd, cmd,
name, name,

View file

@ -4,8 +4,8 @@ use crate::common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.zsh", snapbox::file!["../snapshots/basic.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.zsh", snapbox::file!["../snapshots/feature_sample.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.zsh", snapbox::file!["../snapshots/special_commands.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.zsh", snapbox::file!["../snapshots/quoting.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.zsh", snapbox::file!["../snapshots/aliases.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.zsh", snapbox::file!["../snapshots/sub_subcommands.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -77,8 +77,8 @@ fn custom_bin_name() {
let name = "my-app"; let name = "my-app";
let bin_name = "bin-name"; let bin_name = "bin-name";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/custom_bin_name.zsh", snapbox::file!["../snapshots/custom_bin_name.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
bin_name, bin_name,
@ -89,8 +89,8 @@ fn custom_bin_name() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.zsh", snapbox::file!["../snapshots/value_hint.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -101,8 +101,8 @@ fn value_hint() {
fn value_terminator() { fn value_terminator() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_terminator_command(name); let cmd = common::value_terminator_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_terminator.zsh", snapbox::file!["../snapshots/value_terminator.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -113,8 +113,8 @@ fn value_terminator() {
fn two_multi_valued_arguments() { fn two_multi_valued_arguments() {
let name = "my-app"; let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name); let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/two_multi_valued_arguments.zsh", snapbox::file!["../snapshots/two_multi_valued_arguments.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -125,8 +125,8 @@ fn two_multi_valued_arguments() {
fn subcommand_last() { fn subcommand_last() {
let name = "my-app"; let name = "my-app";
let cmd = common::subcommand_last(name); let cmd = common::subcommand_last(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/subcommand_last.zsh", snapbox::file!["../snapshots/subcommand_last.zsh"],
clap_complete::shells::Zsh, clap_complete::shells::Zsh,
cmd, cmd,
name, name,
@ -151,10 +151,12 @@ fn complete() {
common::load_runtime::<completest_pty::ZshRuntimeBuilder>("static", "exhaustive"); common::load_runtime::<completest_pty::ZshRuntimeBuilder>("static", "exhaustive");
let input = "exhaustive \t"; let input = "exhaustive \t";
let expected = r#"% exhaustive let expected = snapbox::str![
r#"% exhaustive
complete -- Register shell completions for this program complete -- Register shell completions for this program
help -- Print this message or the help of the given subcommand(s) help -- Print this message or the help of the given subcommand(s)
pacman action alias value quote hint last -- "#; pacman action alias value quote hint last -- "#
];
let actual = runtime.complete(input, &term).unwrap(); let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual); snapbox::assert_eq(expected, actual);
} }

View file

@ -35,5 +35,5 @@ clap = { path = "../", version = "4.0.0", default-features = false, features = [
clap_complete = { path = "../clap_complete", version = "4.0.0" } clap_complete = { path = "../clap_complete", version = "4.0.0" }
[dev-dependencies] [dev-dependencies]
snapbox = { version = "0.4.16", features = ["diff"] } snapbox = { version = "0.5.0", features = ["diff"] }
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] } clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] }

View file

@ -247,8 +247,8 @@ pub fn value_hint_command(name: &'static str) -> clap::Command {
) )
} }
pub fn assert_matches_path( pub fn assert_matches(
expected_path: impl AsRef<std::path::Path>, expected: impl Into<snapbox::Data>,
gen: impl clap_complete::Generator, gen: impl clap_complete::Generator,
mut cmd: clap::Command, mut cmd: clap::Command,
name: &'static str, name: &'static str,
@ -257,6 +257,7 @@ pub fn assert_matches_path(
clap_complete::generate(gen, &mut cmd, name, &mut buf); clap_complete::generate(gen, &mut cmd, name, &mut buf);
snapbox::Assert::new() snapbox::Assert::new()
.action_env("SNAPSHOTS") .action_env(snapbox::DEFAULT_ACTION_ENV)
.matches_path(expected_path, buf); .normalize_paths(false)
.matches(expected, buf);
} }

View file

@ -4,8 +4,8 @@ mod common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.fig.js", snapbox::file!["snapshots/basic.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.fig.js", snapbox::file!["snapshots/feature_sample.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.fig.js", snapbox::file!["snapshots/special_commands.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.fig.js", snapbox::file!["snapshots/quoting.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.fig.js", snapbox::file!["snapshots/aliases.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.fig.js", snapbox::file!["snapshots/sub_subcommands.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,
@ -76,8 +76,8 @@ fn sub_subcommands() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.fig.js", snapbox::file!["snapshots/value_hint.fig.js"],
clap_complete_fig::Fig, clap_complete_fig::Fig,
cmd, cmd,
name, name,

View file

@ -14,7 +14,7 @@ const completion: Fig.Spec = {
}, },
{ {
name: "cmd-double-quotes", name: "cmd-double-quotes",
description: "Can be /"always/", /"auto/", or /"never/"", description: "Can be \"always\", \"auto\", or \"never\"",
options: [ options: [
{ {
name: ["-h", "--help"], name: ["-h", "--help"],
@ -34,7 +34,7 @@ const completion: Fig.Spec = {
}, },
{ {
name: "cmd-backslash", name: "cmd-backslash",
description: "Avoid '//n'", description: "Avoid '\\n'",
options: [ options: [
{ {
name: ["-h", "--help"], name: ["-h", "--help"],
@ -72,7 +72,7 @@ const completion: Fig.Spec = {
}, },
{ {
name: "cmd-double-quotes", name: "cmd-double-quotes",
description: "Can be /"always/", /"auto/", or /"never/"", description: "Can be \"always\", \"auto\", or \"never\"",
}, },
{ {
name: "cmd-backticks", name: "cmd-backticks",
@ -80,7 +80,7 @@ const completion: Fig.Spec = {
}, },
{ {
name: "cmd-backslash", name: "cmd-backslash",
description: "Avoid '//n'", description: "Avoid '\\n'",
}, },
{ {
name: "cmd-brackets", name: "cmd-brackets",
@ -104,7 +104,7 @@ const completion: Fig.Spec = {
}, },
{ {
name: "--double-quotes", name: "--double-quotes",
description: "Can be /"always/", /"auto/", or /"never/"", description: "Can be \"always\", \"auto\", or \"never\"",
}, },
{ {
name: "--backticks", name: "--backticks",
@ -112,7 +112,7 @@ const completion: Fig.Spec = {
}, },
{ {
name: "--backslash", name: "--backslash",
description: "Avoid '//n'", description: "Avoid '\\n'",
}, },
{ {
name: "--brackets", name: "--brackets",

View file

@ -35,7 +35,7 @@ clap = { path = "../", version = "4.0.0", default-features = false, features = [
clap_complete = { path = "../clap_complete", version = "4.0.0" } clap_complete = { path = "../clap_complete", version = "4.0.0" }
[dev-dependencies] [dev-dependencies]
snapbox = { version = "0.4.16", features = ["diff", "examples", "path"] } snapbox = { version = "0.5.0", features = ["diff", "examples", "path"] }
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] } clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] }
completest = "0.4.0" completest = "0.4.0"
completest-nu = "0.4.0" completest-nu = "0.4.0"

View file

@ -243,8 +243,8 @@ pub fn value_hint_command(name: &'static str) -> Command {
) )
} }
pub fn assert_matches_path( pub fn assert_matches(
expected_path: impl AsRef<std::path::Path>, expected: impl Into<snapbox::Data>,
gen: impl clap_complete::Generator, gen: impl clap_complete::Generator,
mut cmd: clap::Command, mut cmd: clap::Command,
name: &'static str, name: &'static str,
@ -253,9 +253,9 @@ pub fn assert_matches_path(
clap_complete::generate(gen, &mut cmd, name, &mut buf); clap_complete::generate(gen, &mut cmd, name, &mut buf);
snapbox::Assert::new() snapbox::Assert::new()
.action_env("SNAPSHOTS") .action_env(snapbox::DEFAULT_ACTION_ENV)
.normalize_paths(false) .normalize_paths(false)
.matches_path(expected_path, buf); .matches(expected, buf);
} }
pub fn register_example<R: completest::RuntimeBuilder>(context: &str, name: &str) { pub fn register_example<R: completest::RuntimeBuilder>(context: &str, name: &str) {

View file

@ -4,8 +4,8 @@ mod common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/basic.nu", snapbox::file!["snapshots/basic.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,
@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/feature_sample.nu", snapbox::file!["snapshots/feature_sample.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,
@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/special_commands.nu", snapbox::file!["snapshots/special_commands.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,
@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/quoting.nu", snapbox::file!["snapshots/quoting.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,
@ -52,8 +52,8 @@ fn quoting() {
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/aliases.nu", snapbox::file!["snapshots/aliases.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,
@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/sub_subcommands.nu", snapbox::file!["snapshots/sub_subcommands.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,
@ -76,8 +76,8 @@ fn sub_subcommands() {
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path( common::assert_matches(
"tests/snapshots/value_hint.nu", snapbox::file!["snapshots/value_hint.nu"],
clap_complete_nushell::Nushell, clap_complete_nushell::Nushell,
cmd, cmd,
name, name,

View file

@ -36,7 +36,7 @@ roff = "0.2.1"
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "env"] } clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "env"] }
[dev-dependencies] [dev-dependencies]
snapbox = { version = "0.4.16", features = ["diff"] } snapbox = { version = "0.5.0", features = ["diff"] }
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] } clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] }
[features] [features]

View file

@ -272,13 +272,14 @@ pub fn env_value_command(name: &'static str) -> clap::Command {
) )
} }
pub fn assert_matches_path(expected_path: impl AsRef<std::path::Path>, cmd: clap::Command) { pub fn assert_matches(expected: impl Into<snapbox::Data>, cmd: clap::Command) {
let mut buf = vec![]; let mut buf = vec![];
clap_mangen::Man::new(cmd).render(&mut buf).unwrap(); clap_mangen::Man::new(cmd).render(&mut buf).unwrap();
snapbox::Assert::new() snapbox::Assert::new()
.action_env("SNAPSHOTS") .action_env(snapbox::DEFAULT_ACTION_ENV)
.matches_path(expected_path, buf); .normalize_paths(false)
.matches(expected, buf);
} }
pub fn possible_values_command(name: &'static str) -> clap::Command { pub fn possible_values_command(name: &'static str) -> clap::Command {

View file

@ -4,70 +4,70 @@ mod common;
fn basic() { fn basic() {
let name = "my-app"; let name = "my-app";
let cmd = common::basic_command(name); let cmd = common::basic_command(name);
common::assert_matches_path("tests/snapshots/basic.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/basic.bash.roff"], cmd);
} }
#[test] #[test]
fn feature_sample() { fn feature_sample() {
let name = "my-app"; let name = "my-app";
let cmd = common::feature_sample_command(name); let cmd = common::feature_sample_command(name);
common::assert_matches_path("tests/snapshots/feature_sample.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/feature_sample.bash.roff"], cmd);
} }
#[test] #[test]
fn special_commands() { fn special_commands() {
let name = "my-app"; let name = "my-app";
let cmd = common::special_commands_command(name); let cmd = common::special_commands_command(name);
common::assert_matches_path("tests/snapshots/special_commands.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/special_commands.bash.roff"], cmd);
} }
#[test] #[test]
fn quoting() { fn quoting() {
let name = "my-app"; let name = "my-app";
let cmd = common::quoting_command(name); let cmd = common::quoting_command(name);
common::assert_matches_path("tests/snapshots/quoting.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/quoting.bash.roff"], cmd);
} }
#[test] #[test]
fn aliases() { fn aliases() {
let name = "my-app"; let name = "my-app";
let cmd = common::aliases_command(name); let cmd = common::aliases_command(name);
common::assert_matches_path("tests/snapshots/aliases.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/aliases.bash.roff"], cmd);
} }
#[test] #[test]
fn sub_subcommands() { fn sub_subcommands() {
let name = "my-app"; let name = "my-app";
let cmd = common::sub_subcommands_command(name); let cmd = common::sub_subcommands_command(name);
common::assert_matches_path("tests/snapshots/sub_subcommands.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/sub_subcommands.bash.roff"], cmd);
} }
#[test] #[test]
fn value_hint() { fn value_hint() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_hint_command(name); let cmd = common::value_hint_command(name);
common::assert_matches_path("tests/snapshots/value_hint.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/value_hint.bash.roff"], cmd);
} }
#[test] #[test]
fn hidden_options() { fn hidden_options() {
let name = "my-app"; let name = "my-app";
let cmd = common::hidden_option_command(name); let cmd = common::hidden_option_command(name);
common::assert_matches_path("tests/snapshots/hidden_option.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/hidden_option.bash.roff"], cmd);
} }
#[test] #[test]
fn value_env() { fn value_env() {
let name = "my-app"; let name = "my-app";
let cmd = common::env_value_command(name); let cmd = common::env_value_command(name);
common::assert_matches_path("tests/snapshots/value_env.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/value_env.bash.roff"], cmd);
} }
#[test] #[test]
fn possible_values() { fn possible_values() {
let name = "my-app"; let name = "my-app";
let cmd = common::possible_values_command(name); let cmd = common::possible_values_command(name);
common::assert_matches_path("tests/snapshots/possible_values.bash.roff", cmd); common::assert_matches(snapbox::file!["snapshots/possible_values.bash.roff"], cmd);
} }
#[test] #[test]
@ -80,7 +80,10 @@ fn sub_subcommands_help() {
.find(|cmd| cmd.get_display_name() == Some("my-app-help")); .find(|cmd| cmd.get_display_name() == Some("my-app-help"));
assert!(cmd.is_some(), "help subcommand not found in command"); assert!(cmd.is_some(), "help subcommand not found in command");
if let Some(cmd) = cmd { if let Some(cmd) = cmd {
common::assert_matches_path("tests/snapshots/sub_subcommand_help.roff", cmd.clone()); common::assert_matches(
snapbox::file!["snapshots/sub_subcommand_help.roff"],
cmd.clone(),
);
} }
} }
@ -88,5 +91,8 @@ fn sub_subcommands_help() {
fn value_name_without_arg() { fn value_name_without_arg() {
let name = "my-app"; let name = "my-app";
let cmd = common::value_name_without_arg(name); let cmd = common::value_name_without_arg(name);
common::assert_matches_path("tests/snapshots/value_name_without_arg.bash.roff", cmd); common::assert_matches(
snapbox::file!["snapshots/value_name_without_arg.bash.roff"],
cmd,
);
} }

View file

@ -1,27 +1,27 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app 3.0" .TH my-app 1 "my-app 3.0"
.SH NAME .SH NAME
my/-app /- testing bash completions my\-app \- testing bash completions
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-f/fR|/fB/-/-flag/fR] [/fB/-o/fR|/fB/-/-option/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIpositional/fR] \fBmy\-app\fR [\fB\-f\fR|\fB\-\-flag\fR] [\fB\-o\fR|\fB\-\-option\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIpositional\fR]
.SH DESCRIPTION .SH DESCRIPTION
testing bash completions testing bash completions
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-f/fR, /fB/-/-flag/fR \fB\-f\fR, \fB\-\-flag\fR
cmd flag cmd flag
.TP .TP
/fB/-o/fR, /fB/-/-option/fR \fB\-o\fR, \fB\-\-option\fR
cmd option cmd option
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.TP .TP
/fB/-V/fR, /fB/-/-version/fR \fB\-V\fR, \fB\-\-version\fR
Print version Print version
.TP .TP
[/fIpositional/fR] [\fIpositional\fR]
.SH VERSION .SH VERSION
v3.0 v3.0

View file

@ -1,25 +1,25 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app " .TH my-app 1 "my-app "
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-c /fR] [/fB/-v /fR] [/fB/-h/fR|/fB/-/-help/fR] [/fIsubcommands/fR] \fBmy\-app\fR [\fB\-c \fR] [\fB\-v \fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-c/fR \fB\-c\fR
.TP .TP
/fB/-v/fR \fB\-v\fR
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.SH SUBCOMMANDS .SH SUBCOMMANDS
.TP .TP
my/-app/-test(1) my\-app\-test(1)
Subcommand Subcommand
.TP .TP
my/-app/-help(1) my\-app\-help(1)
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)

View file

@ -1,36 +1,36 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app 3.0" .TH my-app 1 "my-app 3.0"
.SH NAME .SH NAME
my/-app /- Tests completions my\-app \- Tests completions
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR]... [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR] \fBmy\-app\fR [\fB\-c\fR|\fB\-\-config\fR]... [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIfile\fR] [\fIchoice\fR] [\fIsubcommands\fR]
.SH DESCRIPTION .SH DESCRIPTION
Tests completions Tests completions
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-c/fR, /fB/-/-config/fR \fB\-c\fR, \fB\-\-config\fR
some config file some config file
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.TP .TP
/fB/-V/fR, /fB/-/-version/fR \fB\-V\fR, \fB\-\-version\fR
Print version Print version
.TP .TP
[/fIfile/fR] [\fIfile\fR]
some input file some input file
.TP .TP
[/fIchoice/fR] [\fIchoice\fR]
.br .br
[/fIpossible values: /fRfirst, second] [\fIpossible values: \fRfirst, second]
.SH SUBCOMMANDS .SH SUBCOMMANDS
.TP .TP
my/-app/-test(1) my\-app\-test(1)
tests things tests things
.TP .TP
my/-app/-help(1) my\-app\-help(1)
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)
.SH VERSION .SH VERSION
v3.0 v3.0

View file

@ -1,15 +1,15 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app " .TH my-app 1 "my-app "
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-/-config/fR] [/fB/-h/fR|/fB/-/-help/fR] \fBmy\-app\fR [\fB\-\-config\fR] [\fB\-h\fR|\fB\-\-help\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-/-config/fR \fB\-\-config\fR
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help

View file

@ -1,41 +1,41 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app " .TH my-app 1 "my-app "
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-/-choice/fR] [/fB/-/-method/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fIpositional_choice/fR] \fBmy\-app\fR [\fB\-\-choice\fR] [\fB\-\-method\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIpositional_choice\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-/-choice/fR \fB\-\-choice\fR
.br .br
[/fIpossible values: /fRbash, fish, zsh] [\fIpossible values: \fRbash, fish, zsh]
.TP .TP
/fB/-/-method/fR \fB\-\-method\fR
.br .br
/fIPossible values:/fR \fIPossible values:\fR
.RS 14 .RS 14
.IP /(bu 2 .IP \(bu 2
fast: use the Fast method fast: use the Fast method
.IP /(bu 2 .IP \(bu 2
slow: use the slow method slow: use the slow method
.RE .RE
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help (see a summary with /*(Aq/-h/*(Aq) Print help (see a summary with \*(Aq\-h\*(Aq)
.TP .TP
[/fIpositional_choice/fR] [\fIpositional_choice\fR]
Pick the Position you want the command to run in Pick the Position you want the command to run in
.br .br
.br .br
/fIPossible values:/fR \fIPossible values:\fR
.RS 14 .RS 14
.IP /(bu 2 .IP \(bu 2
left: run left adjusted left: run left adjusted
.IP /(bu 2 .IP \(bu 2
right right
.RE .RE

View file

@ -1,57 +1,57 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app 3.0" .TH my-app 1 "my-app 3.0"
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-/-single/-quotes/fR] [/fB/-/-double/-quotes/fR] [/fB/-/-backticks/fR] [/fB/-/-backslash/fR] [/fB/-/-brackets/fR] [/fB/-/-expansions/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIsubcommands/fR] \fBmy\-app\fR [\fB\-\-single\-quotes\fR] [\fB\-\-double\-quotes\fR] [\fB\-\-backticks\fR] [\fB\-\-backslash\fR] [\fB\-\-brackets\fR] [\fB\-\-expansions\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIsubcommands\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-/-single/-quotes/fR \fB\-\-single\-quotes\fR
Can be /*(Aqalways/*(Aq, /*(Aqauto/*(Aq, or /*(Aqnever/*(Aq Can be \*(Aqalways\*(Aq, \*(Aqauto\*(Aq, or \*(Aqnever\*(Aq
.TP .TP
/fB/-/-double/-quotes/fR \fB\-\-double\-quotes\fR
Can be "always", "auto", or "never" Can be "always", "auto", or "never"
.TP .TP
/fB/-/-backticks/fR \fB\-\-backticks\fR
For more information see `echo test` For more information see `echo test`
.TP .TP
/fB/-/-backslash/fR \fB\-\-backslash\fR
Avoid /*(Aq//n/*(Aq Avoid \*(Aq\\n\*(Aq
.TP .TP
/fB/-/-brackets/fR \fB\-\-brackets\fR
List packages [filter] List packages [filter]
.TP .TP
/fB/-/-expansions/fR \fB\-\-expansions\fR
Execute the shell command with $SHELL Execute the shell command with $SHELL
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.TP .TP
/fB/-V/fR, /fB/-/-version/fR \fB\-V\fR, \fB\-\-version\fR
Print version Print version
.SH SUBCOMMANDS .SH SUBCOMMANDS
.TP .TP
my/-app/-cmd/-single/-quotes(1) my\-app\-cmd\-single\-quotes(1)
Can be /*(Aqalways/*(Aq, /*(Aqauto/*(Aq, or /*(Aqnever/*(Aq Can be \*(Aqalways\*(Aq, \*(Aqauto\*(Aq, or \*(Aqnever\*(Aq
.TP .TP
my/-app/-cmd/-double/-quotes(1) my\-app\-cmd\-double\-quotes(1)
Can be "always", "auto", or "never" Can be "always", "auto", or "never"
.TP .TP
my/-app/-cmd/-backticks(1) my\-app\-cmd\-backticks(1)
For more information see `echo test` For more information see `echo test`
.TP .TP
my/-app/-cmd/-backslash(1) my\-app\-cmd\-backslash(1)
Avoid /*(Aq//n/*(Aq Avoid \*(Aq\\n\*(Aq
.TP .TP
my/-app/-cmd/-brackets(1) my\-app\-cmd\-brackets(1)
List packages [filter] List packages [filter]
.TP .TP
my/-app/-cmd/-expansions(1) my\-app\-cmd\-expansions(1)
Execute the shell command with $SHELL Execute the shell command with $SHELL
.TP .TP
my/-app/-help(1) my\-app\-help(1)
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)
.SH VERSION .SH VERSION
v3.0 v3.0

View file

@ -1,41 +1,41 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app 3.0" .TH my-app 1 "my-app 3.0"
.SH NAME .SH NAME
my/-app /- Tests completions my\-app \- Tests completions
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR]... [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR] \fBmy\-app\fR [\fB\-c\fR|\fB\-\-config\fR]... [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIfile\fR] [\fIchoice\fR] [\fIsubcommands\fR]
.SH DESCRIPTION .SH DESCRIPTION
Tests completions Tests completions
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-c/fR, /fB/-/-config/fR \fB\-c\fR, \fB\-\-config\fR
some config file some config file
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.TP .TP
/fB/-V/fR, /fB/-/-version/fR \fB\-V\fR, \fB\-\-version\fR
Print version Print version
.TP .TP
[/fIfile/fR] [\fIfile\fR]
some input file some input file
.TP .TP
[/fIchoice/fR] [\fIchoice\fR]
.br .br
[/fIpossible values: /fRfirst, second] [\fIpossible values: \fRfirst, second]
.SH SUBCOMMANDS .SH SUBCOMMANDS
.TP .TP
my/-app/-test(1) my\-app\-test(1)
tests things tests things
.TP .TP
my/-app/-some_cmd(1) my\-app\-some_cmd(1)
tests other things tests other things
.TP .TP
my/-app/-some/-cmd/-with/-hyphens(1) my\-app\-some\-cmd\-with\-hyphens(1)
.TP .TP
my/-app/-help(1) my\-app\-help(1)
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)
.SH VERSION .SH VERSION
v3.0 v3.0

View file

@ -1,19 +1,19 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app-help 1 "help " .TH my-app-help 1 "help "
.SH NAME .SH NAME
my/-app/-help /- Print this message or the help of the given subcommand(s) my\-app\-help \- Print this message or the help of the given subcommand(s)
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app help/fR [/fIsubcommands/fR] \fBmy\-app help\fR [\fIsubcommands\fR]
.SH DESCRIPTION .SH DESCRIPTION
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)
.SH SUBCOMMANDS .SH SUBCOMMANDS
.TP .TP
my/-app/-help/-test(1) my\-app\-help\-test(1)
tests things tests things
.TP .TP
my/-app/-help/-some_cmd(1) my\-app\-help\-some_cmd(1)
top level subcommand top level subcommand
.TP .TP
my/-app/-help/-help(1) my\-app\-help\-help(1)
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)

View file

@ -1,39 +1,39 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app 3.0" .TH my-app 1 "my-app 3.0"
.SH NAME .SH NAME
my/-app /- Tests completions my\-app \- Tests completions
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR]... [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR] \fBmy\-app\fR [\fB\-c\fR|\fB\-\-config\fR]... [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIfile\fR] [\fIchoice\fR] [\fIsubcommands\fR]
.SH DESCRIPTION .SH DESCRIPTION
Tests completions Tests completions
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-c/fR, /fB/-/-config/fR \fB\-c\fR, \fB\-\-config\fR
some config file some config file
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.TP .TP
/fB/-V/fR, /fB/-/-version/fR \fB\-V\fR, \fB\-\-version\fR
Print version Print version
.TP .TP
[/fIfile/fR] [\fIfile\fR]
some input file some input file
.TP .TP
[/fIchoice/fR] [\fIchoice\fR]
.br .br
[/fIpossible values: /fRfirst, second] [\fIpossible values: \fRfirst, second]
.SH SUBCOMMANDS .SH SUBCOMMANDS
.TP .TP
my/-app/-test(1) my\-app\-test(1)
tests things tests things
.TP .TP
my/-app/-some_cmd(1) my\-app\-some_cmd(1)
top level subcommand top level subcommand
.TP .TP
my/-app/-help(1) my\-app\-help(1)
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)
.SH VERSION .SH VERSION
v3.0 v3.0

View file

@ -1,18 +1,18 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app " .TH my-app 1 "my-app "
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-c /fR] [/fB/-h/fR|/fB/-/-help/fR] \fBmy\-app\fR [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-c/fR [default: config.toml] \fB\-c\fR [default: config.toml]
Set configuration file path Set configuration file path
.RS .RS
May also be specified with the /fBCONFIG_FILE/fR environment variable. May also be specified with the \fBCONFIG_FILE\fR environment variable.
.RE .RE
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help (see a summary with /*(Aq/-h/*(Aq) Print help (see a summary with \*(Aq\-h\*(Aq)

View file

@ -1,56 +1,56 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app " .TH my-app 1 "my-app "
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-/-choice/fR] [/fB/-/-unknown/fR] [/fB/-/-other/fR] [/fB/-p/fR|/fB/-/-path/fR] [/fB/-f/fR|/fB/-/-file/fR] [/fB/-d/fR|/fB/-/-dir/fR] [/fB/-e/fR|/fB/-/-exe/fR] [/fB/-/-cmd/-name/fR] [/fB/-c/fR|/fB/-/-cmd/fR] [/fB/-u/fR|/fB/-/-user/fR] [/fB/-H/fR|/fB/-/-host/fR] [/fB/-/-url/fR] [/fB/-/-email/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fIcommand_with_args/fR] \fBmy\-app\fR [\fB\-\-choice\fR] [\fB\-\-unknown\fR] [\fB\-\-other\fR] [\fB\-p\fR|\fB\-\-path\fR] [\fB\-f\fR|\fB\-\-file\fR] [\fB\-d\fR|\fB\-\-dir\fR] [\fB\-e\fR|\fB\-\-exe\fR] [\fB\-\-cmd\-name\fR] [\fB\-c\fR|\fB\-\-cmd\fR] [\fB\-u\fR|\fB\-\-user\fR] [\fB\-H\fR|\fB\-\-host\fR] [\fB\-\-url\fR] [\fB\-\-email\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIcommand_with_args\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-/-choice/fR \fB\-\-choice\fR
.br .br
[/fIpossible values: /fRbash, fish, zsh] [\fIpossible values: \fRbash, fish, zsh]
.TP .TP
/fB/-/-unknown/fR \fB\-\-unknown\fR
.TP .TP
/fB/-/-other/fR \fB\-\-other\fR
.TP .TP
/fB/-p/fR, /fB/-/-path/fR \fB\-p\fR, \fB\-\-path\fR
.TP .TP
/fB/-f/fR, /fB/-/-file/fR \fB\-f\fR, \fB\-\-file\fR
.TP .TP
/fB/-d/fR, /fB/-/-dir/fR \fB\-d\fR, \fB\-\-dir\fR
.TP .TP
/fB/-e/fR, /fB/-/-exe/fR \fB\-e\fR, \fB\-\-exe\fR
.TP .TP
/fB/-/-cmd/-name/fR \fB\-\-cmd\-name\fR
.TP .TP
/fB/-c/fR, /fB/-/-cmd/fR \fB\-c\fR, \fB\-\-cmd\fR
.TP .TP
/fB/-u/fR, /fB/-/-user/fR \fB\-u\fR, \fB\-\-user\fR
.TP .TP
/fB/-H/fR, /fB/-/-host/fR \fB\-H\fR, \fB\-\-host\fR
.TP .TP
/fB/-/-url/fR \fB\-\-url\fR
.TP .TP
/fB/-/-email/fR \fB\-\-email\fR
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help
.TP .TP
[/fIcommand_with_args/fR] [\fIcommand_with_args\fR]

View file

@ -1,15 +1,15 @@
.ie /n(.g .ds Aq /(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH my-app 1 "my-app " .TH my-app 1 "my-app "
.SH NAME .SH NAME
my/-app my\-app
.SH SYNOPSIS .SH SYNOPSIS
/fBmy/-app/fR [/fB/-/-flag/fR] [/fB/-h/fR|/fB/-/-help/fR] \fBmy\-app\fR [\fB\-\-flag\fR] [\fB\-h\fR|\fB\-\-help\fR]
.SH DESCRIPTION .SH DESCRIPTION
.SH OPTIONS .SH OPTIONS
.TP .TP
/fB/-/-flag/fR \fB\-\-flag\fR
.TP .TP
/fB/-h/fR, /fB/-/-help/fR \fB\-h\fR, \fB\-\-help\fR
Print help Print help

View file

@ -427,14 +427,16 @@ fn optional_value() {
assert_eq!(m.get_one::<String>("port").unwrap(), "42"); assert_eq!(m.get_one::<String>("port").unwrap(), "42");
let help = cmd.render_help().to_string(); let help = cmd.render_help().to_string();
const HELP: &str = "\ snapbox::assert_eq(
Usage: test [OPTIONS] snapbox::str![[r#"
Usage: test [OPTIONS]
Options: Options:
-p [<NUM>] -p [<NUM>]
-h, --help Print help -h, --help Print help
"; "#]],
snapbox::assert_eq(HELP, help); help,
);
} }
#[test] #[test]

View file

@ -230,18 +230,6 @@ For more information, try '--help'.
#[test] #[test]
fn derive_order_next_order() { fn derive_order_next_order() {
static HELP: &str = "\
Usage: test [OPTIONS]
Options:
--flag-b first flag
--option-b <OPTION_B> first option
-h, --help Print help
-V, --version Print version
--flag-a second flag
--option-a <OPTION_A> second option
";
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(name = "test", version = "1.2")] #[command(name = "test", version = "1.2")]
struct Args { struct Args {
@ -277,23 +265,24 @@ Options:
let mut cmd = Args::command(); let mut cmd = Args::command();
let help = cmd.render_help().to_string(); let help = cmd.render_help().to_string();
snapbox::assert_eq(HELP, help); snapbox::assert_eq(
snapbox::str![[r#"
Usage: test [OPTIONS]
Options:
--flag-b first flag
--option-b <OPTION_B> first option
-h, --help Print help
-V, --version Print version
--flag-a second flag
--option-a <OPTION_A> second option
"#]],
help,
);
} }
#[test] #[test]
fn derive_order_next_order_flatten() { fn derive_order_next_order_flatten() {
static HELP: &str = "\
Usage: test [OPTIONS]
Options:
--flag-b first flag
--option-b <OPTION_B> first option
-h, --help Print help
-V, --version Print version
--flag-a second flag
--option-a <OPTION_A> second option
";
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(name = "test", version = "1.2")] #[command(name = "test", version = "1.2")]
struct Args { struct Args {
@ -329,7 +318,20 @@ Options:
let mut cmd = Args::command(); let mut cmd = Args::command();
let help = cmd.render_help().to_string(); let help = cmd.render_help().to_string();
snapbox::assert_eq(HELP, help); snapbox::assert_eq(
snapbox::str![[r#"
Usage: test [OPTIONS]
Options:
--flag-b first flag
--option-b <OPTION_B> first option
-h, --help Print help
-V, --version Print version
--flag-a second flag
--option-a <OPTION_A> second option
"#]],
help,
);
} }
#[test] #[test]

View file

@ -301,14 +301,16 @@ mod arg {
let mut help = Vec::new(); let mut help = Vec::new();
cmd.write_help(&mut help).unwrap(); cmd.write_help(&mut help).unwrap();
const HELP: &str = "\ snapbox::assert_eq(
snapbox::str![["\
Usage: test [OPTIONS] Usage: test [OPTIONS]
Options: Options:
-p [<NUM>] -p [<NUM>]
-h, --help Print help information -h, --help Print help information
"; "]],
snapbox::assert_eq(HELP, help); help,
);
} }
} }