Skip to content

Commit

Permalink
Merge pull request #5351 from epage/snap
Browse files Browse the repository at this point in the history
chore: Update snapbox/trycmd
  • Loading branch information
epage authored Feb 15, 2024
2 parents f45a32e + 5f9cecb commit b48c90f
Show file tree
Hide file tree
Showing 35 changed files with 418 additions and 377 deletions.
31 changes: 20 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ clap_derive = { path = "./clap_derive", version = "=4.5.0", optional = true }
trybuild = "1.0.89"
rustversion = "1.0.14"
# 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"
snapbox = "0.4.16"
snapbox = "0.5.0"
shlex = "1.3.0"

[[example]]
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ shlex = { version = "1.1.0", optional = true }
unicode-xid = { version = "0.2.2", optional = true }

[dev-dependencies]
snapbox = { version = "0.4.16", features = ["diff", "path", "examples"] }
snapbox = { version = "0.5.0", features = ["diff", "path", "examples"] }
# 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-pty = "0.5.0"
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "derive", "help"] }
Expand Down
48 changes: 24 additions & 24 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::common;
fn basic() {
let name = "my-app";
let cmd = common::basic_command(name);
common::assert_matches_path(
"tests/snapshots/basic.bash",
common::assert_matches(
snapbox::file!["../snapshots/basic.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -16,8 +16,8 @@ fn basic() {
fn feature_sample() {
let name = "my-app";
let cmd = common::feature_sample_command(name);
common::assert_matches_path(
"tests/snapshots/feature_sample.bash",
common::assert_matches(
snapbox::file!["../snapshots/feature_sample.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -28,8 +28,8 @@ fn feature_sample() {
fn special_commands() {
let name = "my-app";
let cmd = common::special_commands_command(name);
common::assert_matches_path(
"tests/snapshots/special_commands.bash",
common::assert_matches(
snapbox::file!["../snapshots/special_commands.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -40,8 +40,8 @@ fn special_commands() {
fn quoting() {
let name = "my-app";
let cmd = common::quoting_command(name);
common::assert_matches_path(
"tests/snapshots/quoting.bash",
common::assert_matches(
snapbox::file!["../snapshots/quoting.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -52,8 +52,8 @@ fn quoting() {
fn aliases() {
let name = "my-app";
let cmd = common::aliases_command(name);
common::assert_matches_path(
"tests/snapshots/aliases.bash",
common::assert_matches(
snapbox::file!["../snapshots/aliases.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -64,8 +64,8 @@ fn aliases() {
fn sub_subcommands() {
let name = "my-app";
let cmd = common::sub_subcommands_command(name);
common::assert_matches_path(
"tests/snapshots/sub_subcommands.bash",
common::assert_matches(
snapbox::file!["../snapshots/sub_subcommands.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -77,8 +77,8 @@ fn custom_bin_name() {
let name = "my-app";
let bin_name = "bin-name";
let cmd = common::basic_command(name);
common::assert_matches_path(
"tests/snapshots/custom_bin_name.bash",
common::assert_matches(
snapbox::file!["../snapshots/custom_bin_name.bash"],
clap_complete::shells::Bash,
cmd,
bin_name,
Expand All @@ -89,8 +89,8 @@ fn custom_bin_name() {
fn value_hint() {
let name = "my-app";
let cmd = common::value_hint_command(name);
common::assert_matches_path(
"tests/snapshots/value_hint.bash",
common::assert_matches(
snapbox::file!["../snapshots/value_hint.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -101,8 +101,8 @@ fn value_hint() {
fn value_terminator() {
let name = "my-app";
let cmd = common::value_terminator_command(name);
common::assert_matches_path(
"tests/snapshots/value_terminator.bash",
common::assert_matches(
snapbox::file!["../snapshots/value_terminator.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -124,15 +124,15 @@ fn register_minimal() {
.unwrap();
snapbox::Assert::new()
.action_env("SNAPSHOTS")
.matches_path("tests/snapshots/register_minimal.bash", buf);
.matches(snapbox::file!["../snapshots/register_minimal.bash"], buf);
}

#[test]
fn two_multi_valued_arguments() {
let name = "my-app";
let cmd = common::two_multi_valued_arguments_command(name);
common::assert_matches_path(
"tests/snapshots/two_multi_valued_arguments.bash",
common::assert_matches(
snapbox::file!["../snapshots/two_multi_valued_arguments.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand All @@ -143,8 +143,8 @@ fn two_multi_valued_arguments() {
fn subcommand_last() {
let name = "my-app";
let cmd = common::subcommand_last(name);
common::assert_matches_path(
"tests/snapshots/subcommand_last.bash",
common::assert_matches(
snapbox::file!["../snapshots/subcommand_last.bash"],
clap_complete::shells::Bash,
cmd,
name,
Expand Down Expand Up @@ -241,7 +241,7 @@ fn complete() {
}

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();
snapbox::assert_eq(expected, actual);
}
Expand Down
8 changes: 4 additions & 4 deletions clap_complete/tests/testsuite/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ pub fn subcommand_last(name: &'static str) -> clap::Command {
.subcommands([clap::Command::new("foo"), clap::Command::new("bar")])
}

pub fn assert_matches_path(
expected_path: impl AsRef<std::path::Path>,
pub fn assert_matches(
expected: impl Into<snapbox::Data>,
gen: impl clap_complete::Generator,
mut cmd: clap::Command,
name: &'static str,
Expand All @@ -291,9 +291,9 @@ pub fn assert_matches_path(
clap_complete::generate(gen, &mut cmd, name, &mut buf);

snapbox::Assert::new()
.action_env("SNAPSHOTS")
.action_env(snapbox::DEFAULT_ACTION_ENV)
.normalize_paths(false)
.matches_path(expected_path, buf);
.matches(expected, buf);
}

pub fn register_example<R: completest::RuntimeBuilder>(context: &str, name: &str) {
Expand Down
30 changes: 20 additions & 10 deletions clap_complete/tests/testsuite/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ fn suggest_subcommand_subset() {
.subcommand(Command::new("goodbye-world"));

snapbox::assert_eq(
"hello-moon
snapbox::str![
"hello-moon
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"),
);
}
Expand All @@ -50,9 +52,11 @@ fn suggest_long_flag_subset() {
);

snapbox::assert_eq(
"--hello-world
snapbox::str![
"--hello-world
--hello-moon
--help\tPrint help",
--help\tPrint help"
],
complete!(cmd, "--he"),
);
}
Expand All @@ -67,8 +71,10 @@ fn suggest_possible_value_subset() {
]));

snapbox::assert_eq(
"hello-world\tSay hello to the world
hello-moon",
snapbox::str![
"hello-world\tSay hello to the world
hello-moon"
],
complete!(cmd, "hello"),
);
}
Expand All @@ -93,10 +99,12 @@ fn suggest_additional_short_flags() {
);

snapbox::assert_eq(
"-aa
snapbox::str![
"-aa
-ab
-ac
-ah\tPrint help",
-ah\tPrint help"
],
complete!(cmd, "-a"),
);
}
Expand All @@ -112,11 +120,13 @@ fn suggest_subcommand_positional() {
));

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')
hello-world\tSay hello to the world
hello-moon
goodbye-world",
goodbye-world"
],
complete!(cmd, "hello-world [TAB]"),
);
}
Expand Down
Loading

0 comments on commit b48c90f

Please sign in to comment.