From 1490e2434aaf4071dc0dc36fe0046238401a3679 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jul 2024 15:38:49 -0500 Subject: [PATCH 1/2] chore: Update snapbox --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d98c29b8..1ca8d4bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1432,7 +1432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -2971,9 +2971,9 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" [[package]] name = "snapbox" -version = "0.6.11" +version = "0.6.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "699c824ef8c2061c39efb3af4f334310b3acbfb2a50c6d1f867e4d95dcff94be" +checksum = "027c936207f85d10d015e21faf5c676c7e08c453ed371adf55c0874c443ca77a" dependencies = [ "anstream", "anstyle", @@ -2994,9 +2994,9 @@ dependencies = [ [[package]] name = "snapbox-macros" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f4c14672714436c09254801c934b203196a51182a5107fb76591c7cc56424d" +checksum = "16569f53ca23a41bb6f62e0a5084aa1661f4814a67fa33696a79073e03a664af" dependencies = [ "anstream", ] diff --git a/Cargo.toml b/Cargo.toml index 395ba070..b98d8b57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -183,7 +183,7 @@ rustversion = "1.0.15" # Cutting out `filesystem` feature trycmd = { version = "0.15.3", default-features = false, features = ["color-auto", "diff", "examples"] } humantime = "2.1.0" -snapbox = "0.6.0" +snapbox = "0.6.16" shlex = "1.3.0" automod = "1.0.14" From 7b5b61b0218d2c19ed424155e7ae55d21b0e2240 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jul 2024 15:58:24 -0500 Subject: [PATCH 2/2] test(help): Switch to snapbox --- tests/builder/help.rs | 2415 ++++++++++++++++++++++------------------- 1 file changed, 1298 insertions(+), 1117 deletions(-) diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 79afc396..0169bb28 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -90,23 +90,12 @@ Usage: ctest subcmd multi [OPTIONS] For more information, try '--help'. -"#]]); +"#]] + ); } #[test] fn req_last_arg_usage() { - static LAST_ARG_REQ_MULT: &str = "\ -Usage: example ... -- ... - -Arguments: - ... First - ... Second - -Options: - -h, --help Print help - -V, --version Print version -"; - let cmd = Command::new("example") .version("1.0") .arg(Arg::new("FIRST").help("First").num_args(1..).required(true)) @@ -117,26 +106,23 @@ Options: .required(true) .last(true), ); - utils::assert_output(cmd, "example --help", LAST_ARG_REQ_MULT, false); + let expected = str![[r#" +Usage: example ... -- ... + +Arguments: + ... First + ... Second + +Options: + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "example --help", expected, false); } #[test] fn args_with_last_usage() { - static LAST_ARG_USAGE: &str = "\ -Usage: flamegraph [OPTIONS] [BINFILE] [-- ...] - -Arguments: - [BINFILE] The path of the binary to be profiled. for a binary. - [ARGS]... Any arguments you wish to pass to the being profiled. - -Options: - -v, --verbose Prints out more stuff. - -t, --timeout Timeout in seconds. - -f, --frequency The sampling frequency. - -h, --help Print help - -V, --version Print version -"; - let cmd = Command::new("flamegraph") .version("0.1") .arg( @@ -173,7 +159,22 @@ Options: .last(true) .value_name("ARGS"), ); - utils::assert_output(cmd, "flamegraph --help", LAST_ARG_USAGE, false); + let expected = str![[r#" +Usage: flamegraph [OPTIONS] [BINFILE] [-- ...] + +Arguments: + [BINFILE] The path of the binary to be profiled. for a binary. + [ARGS]... Any arguments you wish to pass to the being profiled. + +Options: + -v, --verbose Prints out more stuff. + -t, --timeout Timeout in seconds. + -f, --frequency The sampling frequency. + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "flamegraph --help", expected, false); } #[test] @@ -202,7 +203,7 @@ fn subcommand_help_rev() { #[test] fn complex_help_output() { - static HELP: &str = "\ + let expected = str![[r#" clap-test v1.4.8 Kevin K. tests clap library @@ -232,14 +233,21 @@ Options: --optvalnoeq [] Tests optional value -h, --help Print help -V, --version Print version -"; - utils::assert_output(utils::complex_app(), "clap-test --help", HELP, false); +"#]]; + utils::assert_output(utils::complex_app(), "clap-test --help", expected, false); } #[test] fn after_and_before_help_output() { - static AFTER_HELP: &str = "some text that comes before the help + let cmd = Command::new("clap-test") + .version("v1.4.8") + .about("tests clap library") + .before_help("some text that comes before the help") + .after_help("some text that comes after the help"); + + let expected = str![[r#" +some text that comes before the help tests clap library @@ -250,33 +258,39 @@ Options: -V, --version Print version some text that comes after the help -"; - let cmd = Command::new("clap-test") - .version("v1.4.8") - .about("tests clap library") - .before_help("some text that comes before the help") - .after_help("some text that comes after the help"); - utils::assert_output(cmd.clone(), "clap-test -h", AFTER_HELP, false); - utils::assert_output(cmd, "clap-test --help", AFTER_HELP, false); -} +"#]]; + utils::assert_output(cmd.clone(), "clap-test -h", expected, false); -#[test] -fn after_and_before_long_help_output() { - static AFTER_HELP: &str = "some text that comes before the help + let expected = str![[r#" +some text that comes before the help tests clap library Usage: clap-test Options: - -h, --help Print help (see more with '--help') + -h, --help Print help -V, --version Print version some text that comes after the help -"; - static AFTER_LONG_HELP: &str = "some longer text that comes before the help +"#]]; + utils::assert_output(cmd, "clap-test --help", expected, false); +} + +#[test] +fn after_and_before_long_help_output() { + let cmd = Command::new("clap-test") + .version("v1.4.8") + .about("tests clap library") + .before_help("some text that comes before the help") + .after_help("some text that comes after the help") + .before_long_help("some longer text that comes before the help") + .after_long_help("some longer text that comes after the help"); + + let expected = str![[r#" +some longer text that comes before the help tests clap library @@ -290,30 +304,26 @@ Options: Print version some longer text that comes after the help -"; - let cmd = Command::new("clap-test") - .version("v1.4.8") - .about("tests clap library") - .before_help("some text that comes before the help") - .after_help("some text that comes after the help") - .before_long_help("some longer text that comes before the help") - .after_long_help("some longer text that comes after the help"); - utils::assert_output(cmd.clone(), "clap-test --help", AFTER_LONG_HELP, false); - utils::assert_output(cmd, "clap-test -h", AFTER_HELP, false); -} +"#]]; + utils::assert_output(cmd.clone(), "clap-test --help", expected, false); -static MULTI_SC_HELP: &str = "\ -tests subcommands + let expected = str![[r#" +some text that comes before the help -Usage: ctest subcmd multi [OPTIONS] +tests clap library + +Usage: clap-test Options: - -f, --flag tests flags - -o, --option ... tests options - -h, --help Print help - -V, --version Print version -"; + -h, --help Print help (see more with '--help') + -V, --version Print version + +some text that comes after the help + +"#]]; + utils::assert_output(cmd, "clap-test -h", expected, false); +} #[test] fn multi_level_sc_help() { @@ -336,47 +346,54 @@ fn multi_level_sc_help() { ), ), ); - utils::assert_output(cmd, "ctest help subcmd multi", MULTI_SC_HELP, false); + + let expected = str![[r#" +tests subcommands + +Usage: ctest subcmd multi [OPTIONS] + +Options: + -f, --flag tests flags + -o, --option ... tests options + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "ctest help subcmd multi", expected, false); } #[test] fn no_wrap_default_help() { - static DEFAULT_HELP: &str = "\ + let cmd = Command::new("ctest").version("1.0").term_width(0); + + let expected = str![[r#" Usage: ctest Options: -h, --help Print help -V, --version Print version -"; - let cmd = Command::new("ctest").version("1.0").term_width(0); - utils::assert_output(cmd, "ctest --help", DEFAULT_HELP, false); +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] fn try_help_default() { - static DEFAULT_HELP: &str = "\ + let cmd = Command::new("ctest").version("1.0").term_width(0); + + let expected = str![[r#" error: unexpected argument 'bar' found Usage: ctest For more information, try '--help'. -"; - let cmd = Command::new("ctest").version("1.0").term_width(0); - utils::assert_output(cmd, "ctest bar", DEFAULT_HELP, true); +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); } #[test] fn try_help_custom_flag() { - static EXPECTED_HELP: &str = "\ -error: unexpected argument 'bar' found - -Usage: ctest - -For more information, try '--help'. -"; - let cmd = Command::new("ctest") .version("1.0") .disable_help_flag(true) @@ -387,89 +404,94 @@ For more information, try '--help'. .action(ArgAction::Help), ) .term_width(0); - utils::assert_output(cmd, "ctest bar", EXPECTED_HELP, true); -} -#[test] -fn try_help_custom_flag_short() { - static EXPECTED_HELP: &str = "\ -error: unexpected argument 'bar' found - -Usage: ctest - -For more information, try '-h'. -"; - - let cmd = Command::new("ctest") - .version("1.0") - .disable_help_flag(true) - .arg(Arg::new("help").short('h').action(ArgAction::HelpShort)) - .term_width(0); - utils::assert_output(cmd, "ctest bar", EXPECTED_HELP, true); -} - -#[test] -fn try_help_custom_flag_long() { - static EXPECTED_HELP: &str = "\ + let expected = str![[r#" error: unexpected argument 'bar' found Usage: ctest For more information, try '--help'. -"; +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); +} + +#[test] +fn try_help_custom_flag_short() { + let cmd = Command::new("ctest") + .version("1.0") + .disable_help_flag(true) + .arg(Arg::new("help").short('h').action(ArgAction::HelpShort)) + .term_width(0); + + let expected = str![[r#" +error: unexpected argument 'bar' found + +Usage: ctest + +For more information, try '-h'. + +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); +} + +#[test] +fn try_help_custom_flag_long() { let cmd = Command::new("ctest") .version("1.0") .disable_help_flag(true) .arg(Arg::new("help").long("help").action(ArgAction::HelpShort)) .term_width(0); - utils::assert_output(cmd, "ctest bar", EXPECTED_HELP, true); + + let expected = str![[r#" +error: unexpected argument 'bar' found + +Usage: ctest + +For more information, try '--help'. + +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); } #[test] fn try_help_custom_flag_no_action() { - static EXPECTED_HELP: &str = "\ -error: unexpected argument 'bar' found - -Usage: ctest -"; - let cmd = Command::new("ctest") .version("1.0") .disable_help_flag(true) // Note `ArgAction::Help` is excluded .arg(Arg::new("help").long("help").global(true)) .term_width(0); - utils::assert_output(cmd, "ctest bar", EXPECTED_HELP, true); + + let expected = str![[r#" +error: unexpected argument 'bar' found + +Usage: ctest + +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); } #[test] fn try_help_subcommand_default() { - static DEFAULT_HELP: &str = "\ -error: unrecognized subcommand 'bar' - -Usage: ctest [COMMAND] - -For more information, try '--help'. -"; - let cmd = Command::new("ctest") .version("1.0") .subcommand(Command::new("foo")) .term_width(0); - utils::assert_output(cmd, "ctest bar", DEFAULT_HELP, true); -} -#[test] -fn try_help_subcommand_custom_flag() { - static EXPECTED_HELP: &str = "\ + let expected = str![[r#" error: unrecognized subcommand 'bar' Usage: ctest [COMMAND] For more information, try '--help'. -"; +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); +} + +#[test] +fn try_help_subcommand_custom_flag() { let cmd = Command::new("ctest") .version("1.0") .disable_help_flag(true) @@ -482,19 +504,20 @@ For more information, try '--help'. ) .subcommand(Command::new("foo")) .term_width(0); - utils::assert_output(cmd, "ctest bar", EXPECTED_HELP, true); -} -#[test] -fn try_help_subcommand_custom_flag_no_action() { - static EXPECTED_HELP: &str = "\ + let expected = str![[r#" error: unrecognized subcommand 'bar' Usage: ctest [COMMAND] -For more information, try 'help'. -"; +For more information, try '--help'. +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); +} + +#[test] +fn try_help_subcommand_custom_flag_no_action() { let cmd = Command::new("ctest") .version("1.0") .disable_help_flag(true) @@ -502,25 +525,21 @@ For more information, try 'help'. .arg(Arg::new("help").long("help").global(true)) .subcommand(Command::new("foo")) .term_width(0); - utils::assert_output(cmd, "ctest bar", EXPECTED_HELP, true); + + let expected = str![[r#" +error: unrecognized subcommand 'bar' + +Usage: ctest [COMMAND] + +For more information, try 'help'. + +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); } #[test] #[cfg(feature = "wrap_help")] fn wrapped_help() { - static WRAPPED_HELP: &str = "\ -Usage: test [OPTIONS] - -Options: - -a, --all Also do versioning for private crates (will - not be published) - --exact Specify inter dependency version numbers - exactly with `=` - --no-git-commit Do not commit version changes - --no-git-push Do not push generated commit and tags to git - remote - -h, --help Print help -"; let cmd = Command::new("test") .term_width(67) .arg( @@ -548,13 +567,8 @@ Options: .action(ArgAction::SetTrue) .help("Do not push generated commit and tags to git remote"), ); - utils::assert_output(cmd, "test --help", WRAPPED_HELP, false); -} -#[test] -#[cfg(feature = "wrap_help")] -fn unwrapped_help() { - static UNWRAPPED_HELP: &str = "\ + let expected = str![[r#" Usage: test [OPTIONS] Options: @@ -566,7 +580,14 @@ Options: --no-git-push Do not push generated commit and tags to git remote -h, --help Print help -"; + +"#]]; + utils::assert_output(cmd, "test --help", expected, false); +} + +#[test] +#[cfg(feature = "wrap_help")] +fn unwrapped_help() { let cmd = Command::new("test") .term_width(68) .arg( @@ -594,37 +615,27 @@ Options: .action(ArgAction::SetTrue) .help("Do not push generated commit and tags to git remote"), ); - utils::assert_output(cmd, "test --help", UNWRAPPED_HELP, false); + + let expected = str![[r#" +Usage: test [OPTIONS] + +Options: + -a, --all Also do versioning for private crates (will + not be published) + --exact Specify inter dependency version numbers + exactly with `=` + --no-git-commit Do not commit version changes + --no-git-push Do not push generated commit and tags to git + remote + -h, --help Print help + +"#]]; + utils::assert_output(cmd, "test --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn possible_value_wrapped_help() { - static WRAPPED_HELP: &str = "\ -Usage: test [OPTIONS] - -Options: - --possible-values - Possible values: - - short_name: Long enough help message, barely warrant - wrapping - - second: Short help gets handled the same - - --possible-values-with-new-line - Possible values: - - long enough name to trigger new line: Really long - enough help message to clearly warrant wrapping believe - me - - second - - --possible-values-without-new-line - Possible values: - - name: Short enough help message with no wrapping - - second: short help - - -h, --help - Print help (see a summary with '-h') -"; let cmd = Command::new("test") .term_width(67) .arg( @@ -657,12 +668,42 @@ Options: PossibleValue::new("second").help("short help"), ]), ); - utils::assert_output(cmd, "test --help", WRAPPED_HELP, false); + + let expected = str![[r#" +Usage: test [OPTIONS] + +Options: + --possible-values + Possible values: + - short_name: Long enough help message, barely warrant + wrapping + - second: Short help gets handled the same + + --possible-values-with-new-line + Possible values: + - long enough name to trigger new line: Really long + enough help message to clearly warrant wrapping believe + me + - second + + --possible-values-without-new-line + Possible values: + - name: Short enough help message with no wrapping + - second: short help + + -h, --help + Print help (see a summary with '-h') + +"#]]; + utils::assert_output(cmd, "test --help", expected, false); } #[test] fn complex_subcommand_help_output() { - static SC_HELP: &str = "clap-test-subcmd 0.1 + let a = utils::complex_app(); + + let expected = str![[r#" +clap-test-subcmd 0.1 Kevin K. tests subcommands @@ -677,31 +718,14 @@ Options: -s, --subcmdarg tests other args -h, --help Print help -V, --version Print version -"; - let a = utils::complex_app(); - utils::assert_output(a, "clap-test subcmd --help", SC_HELP, false); +"#]]; + utils::assert_output(a, "clap-test subcmd --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn issue_626_unicode_cutoff() { - static ISSUE_626_CUTOFF: &str = "\ -Usage: ctest [OPTIONS] - -Options: - -c, --cafe A coffeehouse, coffee shop, or café is an - establishment which primarily serves hot coffee, - related coffee beverages (e.g., café latte, - cappuccino, espresso), tea, and other hot - beverages. Some coffeehouses also serve cold - beverages such as iced coffee and iced tea. Many - cafés also serve some type of food, such as light - snacks, muffins, or pastries. - -h, --help Print help - -V, --version Print version -"; - let cmd = Command::new("ctest").version("0.1").term_width(70).arg( Arg::new("cafe") .short('c') @@ -717,18 +741,25 @@ Options: ) .action(ArgAction::Set), ); - utils::assert_output(cmd, "ctest --help", ISSUE_626_CUTOFF, false); -} -static HIDE_POS_VALS: &str = "\ + let expected = str![[r#" Usage: ctest [OPTIONS] Options: - -p, --pos Some vals [possible values: fast, slow] - -c, --cafe A coffeehouse, coffee shop, or café. + -c, --cafe A coffeehouse, coffee shop, or café is an + establishment which primarily serves hot coffee, + related coffee beverages (e.g., café latte, + cappuccino, espresso), tea, and other hot + beverages. Some coffeehouses also serve cold + beverages such as iced coffee and iced tea. Many + cafés also serve some type of food, such as light + snacks, muffins, or pastries. -h, --help Print help -V, --version Print version -"; + +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); +} #[test] fn hide_possible_vals() { @@ -753,7 +784,18 @@ fn hide_possible_vals() { .help("A coffeehouse, coffee shop, or café.") .action(ArgAction::Set), ); - utils::assert_output(cmd, "ctest --help", HIDE_POS_VALS, false); + + let expected = str![[r#" +Usage: ctest [OPTIONS] + +Options: + -p, --pos Some vals [possible values: fast, slow] + -c, --cafe A coffeehouse, coffee shop, or café. + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] @@ -781,31 +823,22 @@ fn hide_single_possible_val() { .help("A coffeehouse, coffee shop, or café.") .action(ArgAction::Set), ); - utils::assert_output(cmd, "ctest --help", HIDE_POS_VALS, false); + + let expected = str![[r#" +Usage: ctest [OPTIONS] + +Options: + -p, --pos Some vals [possible values: fast, slow] + -c, --cafe A coffeehouse, coffee shop, or café. + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] fn possible_vals_with_help() { - static POS_VALS_HELP: &str = "\ -Usage: ctest [OPTIONS] - -Options: - -p, --pos - Some vals - - Possible values: - - fast - - slow: not as fast - - -c, --cafe - A coffeehouse, coffee shop, or café. - - -h, --help - Print help (see a summary with '-h') - - -V, --version - Print version -"; let app = Command::new("ctest") .version("0.1") .arg( @@ -829,20 +862,33 @@ Options: .help("A coffeehouse, coffee shop, or café.") .action(ArgAction::Set), ); - utils::assert_output(app, "ctest --help", POS_VALS_HELP, false); + + let expected = str![[r#" +Usage: ctest [OPTIONS] + +Options: + -p, --pos + Some vals + + Possible values: + - fast + - slow: not as fast + + -c, --cafe + A coffeehouse, coffee shop, or café. + + -h, --help + Print help (see a summary with '-h') + + -V, --version + Print version + +"#]]; + utils::assert_output(app, "ctest --help", expected, false); } #[test] fn hidden_possible_vals() { - static POS_VALS_HELP: &str = "\ -Usage: ctest [pos] - -Arguments: - [pos] - -Options: - -h, --help Print help -"; let app = Command::new("ctest").arg( Arg::new("pos") .hide_possible_values(true) @@ -852,30 +898,23 @@ Options: ]) .action(ArgAction::Set), ); - utils::assert_output(app, "ctest --help", POS_VALS_HELP, false); + + let expected = str![[r#" +Usage: ctest [pos] + +Arguments: + [pos] + +Options: + -h, --help Print help + +"#]]; + utils::assert_output(app, "ctest --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn issue_626_panic() { - static ISSUE_626_PANIC: &str = "\ -Usage: ctest [OPTIONS] - -Options: - -c, --cafe - La culture du café est très développée - dans de nombreux pays à climat chaud - d\'Amérique, d\'Afrique et d\'Asie, dans des - plantations qui sont cultivées pour les - marchés d\'exportation. Le café est souvent - une contribution majeure aux exportations - des régions productrices. - -h, --help - Print help - -V, --version - Print version -"; - let cmd = Command::new("ctest") .version("0.1") .term_width(52) @@ -887,7 +926,26 @@ Options: d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \ Le café est souvent une contribution majeure aux exportations des régions productrices.") .action(ArgAction::Set)); - utils::assert_output(cmd, "ctest --help", ISSUE_626_PANIC, false); + + let expected = str![[r#" +Usage: ctest [OPTIONS] + +Options: + -c, --cafe + La culture du café est très développée + dans de nombreux pays à climat chaud + d'Amérique, d'Afrique et d'Asie, dans des + plantations qui sont cultivées pour les + marchés d'exportation. Le café est souvent + une contribution majeure aux exportations + des régions productrices. + -h, --help + Print help + -V, --version + Print version + +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] @@ -912,7 +970,9 @@ fn issue_626_variable_panic() { #[test] #[cfg(feature = "wrap_help")] fn final_word_wrapping() { - static FINAL_WORD_WRAPPING: &str = "\ + let cmd = Command::new("ctest").version("0.1").term_width(24); + + let expected = str![[r#" Usage: ctest Options: @@ -920,16 +980,24 @@ Options: Print help -V, --version Print version -"; - let cmd = Command::new("ctest").version("0.1").term_width(24); - utils::assert_output(cmd, "ctest --help", FINAL_WORD_WRAPPING, false); +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn wrapping_newline_chars() { - static WRAPPING_NEWLINE_CHARS: &str = "\ + let cmd = Command::new("ctest") + .version("0.1") + .term_width(60) + .arg(Arg::new("mode").help( + "x, max, maximum 20 characters, contains symbols.\n\ + l, long Copy-friendly, 14 characters, contains symbols.\n\ + m, med, medium Copy-friendly, 8 characters, contains symbols.\n", + )); + + let expected = str![[r#" Usage: ctest [mode] Arguments: @@ -942,23 +1010,24 @@ Arguments: Options: -h, --help Print help -V, --version Print version -"; - let cmd = Command::new("ctest") - .version("0.1") - .term_width(60) - .arg(Arg::new("mode").help( - "x, max, maximum 20 characters, contains symbols.\n\ - l, long Copy-friendly, 14 characters, contains symbols.\n\ - m, med, medium Copy-friendly, 8 characters, contains symbols.\n", - )); - utils::assert_output(cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false); +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn wrapped_indentation() { - static HELP: &str = "\ + let cmd = Command::new("ctest") + .version("0.1") + .term_width(60) + .arg(Arg::new("mode").help( + "Some values: + - l, long Copy-friendly, 14 characters, contains symbols. + - m, med, medium Copy-friendly, 8 characters, contains symbols.", + )); + + let expected = str![[r#" Usage: ctest [mode] Arguments: @@ -971,23 +1040,24 @@ Arguments: Options: -h, --help Print help -V, --version Print version -"; - let cmd = Command::new("ctest") - .version("0.1") - .term_width(60) - .arg(Arg::new("mode").help( - "Some values: - - l, long Copy-friendly, 14 characters, contains symbols. - - m, med, medium Copy-friendly, 8 characters, contains symbols.", - )); - utils::assert_output(cmd, "ctest --help", HELP, false); +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn wrapping_newline_variables() { - static WRAPPING_NEWLINE_CHARS: &str = "\ + let cmd = Command::new("ctest") + .version("0.1") + .term_width(60) + .arg(Arg::new("mode").help( + "x, max, maximum 20 characters, contains symbols.{n}\ + l, long Copy-friendly, 14 characters, contains symbols.{n}\ + m, med, medium Copy-friendly, 8 characters, contains symbols.{n}", + )); + + let expected = str![[r#" Usage: ctest [mode] Arguments: @@ -1000,17 +1070,9 @@ Arguments: Options: -h, --help Print help -V, --version Print version -"; - let cmd = Command::new("ctest") - .version("0.1") - .term_width(60) - .arg(Arg::new("mode").help( - "x, max, maximum 20 characters, contains symbols.{n}\ - l, long Copy-friendly, 14 characters, contains symbols.{n}\ - m, med, medium Copy-friendly, 8 characters, contains symbols.{n}", - )); - utils::assert_output(cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false); +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] @@ -1025,7 +1087,7 @@ fn dont_wrap_urls() { .action(ArgAction::SetTrue)) ); - const EXPECTED: &str = "\ + let expected = str![[r#" Usage: Example update [OPTIONS] Options: @@ -1036,20 +1098,11 @@ Options: https://github.com/rust-lang/rustup/wiki/Non-host-toolchains -h, --help Print help -"; - utils::assert_output(cmd, "Example update --help", EXPECTED, false); + +"#]]; + utils::assert_output(cmd, "Example update --help", expected, false); } -static OLD_NEWLINE_CHARS: &str = "\ -Usage: ctest [OPTIONS] - -Options: - -m Some help with some wrapping - (Defaults to something) - -h, --help Print help - -V, --version Print version -"; - #[test] fn old_newline_chars() { let cmd = Command::new("ctest").version("0.1").arg( @@ -1058,7 +1111,18 @@ fn old_newline_chars() { .action(ArgAction::SetTrue) .help("Some help with some wrapping\n(Defaults to something)"), ); - utils::assert_output(cmd, "ctest --help", OLD_NEWLINE_CHARS, false); + + let expected = str![[r#" +Usage: ctest [OPTIONS] + +Options: + -m Some help with some wrapping + (Defaults to something) + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] @@ -1069,14 +1133,25 @@ fn old_newline_variables() { .action(ArgAction::SetTrue) .help("Some help with some wrapping{n}(Defaults to something)"), ); - utils::assert_output(cmd, "ctest --help", OLD_NEWLINE_CHARS, false); + + let expected = str![[r#" +Usage: ctest [OPTIONS] + +Options: + -m Some help with some wrapping + (Defaults to something) + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); } #[test] #[cfg(feature = "wrap_help")] fn issue_688_hide_pos_vals() { #[cfg(not(feature = "unstable-v5"))] - static ISSUE_688: &str = "\ + let expected = str![[r#" Usage: ctest [OPTIONS] Options: @@ -1085,10 +1160,11 @@ Options: Lanczos3] -h, --help Print help -V, --version Print version -"; + +"#]]; #[cfg(feature = "unstable-v5")] - static ISSUE_688: &str = "\ + let expected = str![[r#" Usage: ctest [OPTIONS] Options: @@ -1097,7 +1173,8 @@ Options: Nearest, Linear, Cubic, Gaussian, Lanczos3] -h, --help Print help -V, --version Print version -"; + +"#]]; let filter_values = ["Nearest", "Linear", "Cubic", "Gaussian", "Lanczos3"]; @@ -1111,7 +1188,8 @@ Options: .long("filter") .value_parser(filter_values) .action(ArgAction::Set)); - utils::assert_output(app1, "ctest --help", ISSUE_688, false); + + utils::assert_output(app1, "ctest --help", expected.clone(), false); let app2 = Command::new("ctest") .version("0.1") @@ -1122,7 +1200,8 @@ Options: .long("filter") .value_parser(filter_values) .action(ArgAction::Set)); - utils::assert_output(app2, "ctest --help", ISSUE_688, false); + + utils::assert_output(app2, "ctest --help", expected.clone(), false); let app3 = Command::new("ctest") .version("0.1") @@ -1132,28 +1211,12 @@ Options: images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]") .long("filter") .action(ArgAction::Set)); - utils::assert_output(app3, "ctest --help", ISSUE_688, false); + + utils::assert_output(app3, "ctest --help", expected.clone(), false); } #[test] fn issue_702_multiple_values() { - static ISSUE_702: &str = "\ -bar - -Usage: myapp [OPTIONS] [arg1] [arg2]... - -Arguments: - [arg1] some option - [arg2]... some option - -Options: - -s, --some some option - -o, --other some other option - -l, --label