From 7b5b61b0218d2c19ed424155e7ae55d21b0e2240 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jul 2024 15:58:24 -0500 Subject: [PATCH] test(help): Switch to snapbox --- tests/builder/help.rs | 2223 ++++++++++++++++++++++------------------- 1 file changed, 1202 insertions(+), 1021 deletions(-) diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 79afc396ef2..0169bb28538 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); -} - -#[test] -fn args_with_last_usage() { - static LAST_ARG_USAGE: &str = "\ -Usage: flamegraph [OPTIONS] [BINFILE] [-- ...] + let expected = str![[r#" +Usage: example ... -- ... Arguments: - [BINFILE] The path of the binary to be profiled. for a binary. - [ARGS]... Any arguments you wish to pass to the being profiled. + ... First + ... Second 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 -"; + -h, --help Print help + -V, --version Print version + +"#]]; + utils::assert_output(cmd, "example --help", expected, false); +} +#[test] +fn args_with_last_usage() { 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 = "\ + let expected = str![[r#" error: unexpected argument 'bar' found Usage: ctest -For more information, try '-h'. -"; +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); - 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'. -"; +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); -} -#[test] -fn try_help_custom_flag_no_action() { - 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_no_action() { 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); -} -#[test] -fn try_help_subcommand_default() { - static DEFAULT_HELP: &str = "\ -error: unrecognized subcommand 'bar' + let expected = str![[r#" +error: unexpected argument 'bar' found -Usage: ctest [COMMAND] +Usage: ctest -For more information, try '--help'. -"; +"#]]; + utils::assert_output(cmd, "ctest bar", expected, true); +} +#[test] +fn try_help_subcommand_default() { 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); -} -#[test] -#[cfg(feature = "wrap_help")] -fn possible_value_wrapped_help() { - static WRAPPED_HELP: &str = "\ + 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 + -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 - --possible-values-without-new-line - Possible values: - - name: Short enough help message with no wrapping - - second: short help +"#]]; + utils::assert_output(cmd, "test --help", expected, false); +} - -h, --help - Print help (see a summary with '-h') -"; +#[test] +#[cfg(feature = "wrap_help")] +fn possible_value_wrapped_help() { 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); -} -#[test] + 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); -} -#[test] -fn possible_vals_with_help() { - static POS_VALS_HELP: &str = "\ + 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é. + -p, --pos Some vals [possible values: fast, slow] + -c, --cafe A coffeehouse, coffee shop, or café. + -h, --help Print help + -V, --version Print version - -h, --help - Print help (see a summary with '-h') +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); +} - -V, --version - Print version -"; +#[test] +fn possible_vals_with_help() { 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,42 +898,54 @@ 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 = "\ + let cmd = Command::new("ctest") + .version("0.1") + .term_width(52) + .arg(Arg::new("cafe") + .short('c') + .long("cafe") + .value_name("FILE") + .help("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.") + .action(ArgAction::Set)); + + 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 + 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 + 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) - .arg(Arg::new("cafe") - .short('c') - .long("cafe") - .value_name("FILE") - .help("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.") - .action(ArgAction::Set)); - utils::assert_output(cmd, "ctest --help", ISSUE_626_PANIC, false); +"#]]; + 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 -"; +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); +} + +#[test] +#[cfg(feature = "wrap_help")] +fn wrapped_indentation() { 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", + "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", WRAPPING_NEWLINE_CHARS, false); -} -#[test] -#[cfg(feature = "wrap_help")] -fn wrapped_indentation() { - static HELP: &str = "\ + let expected = str![[r#" Usage: ctest [mode] Arguments: @@ -971,23 +1040,24 @@ Arguments: Options: -h, --help Print help -V, --version Print version -"; +"#]]; + utils::assert_output(cmd, "ctest --help", expected, false); +} + +#[test] +#[cfg(feature = "wrap_help")] +fn wrapping_newline_variables() { 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.", + "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", HELP, false); -} -#[test] -#[cfg(feature = "wrap_help")] -fn wrapping_newline_variables() { - static WRAPPING_NEWLINE_CHARS: &str = "\ + 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,19 +1098,10 @@ Options: https://github.com/rust-lang/rustup/wiki/Non-host-toolchains -h, --help Print help -"; - 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 -"; +"#]]; + utils::assert_output(cmd, "Example update --help", expected, false); +} #[test] fn old_newline_chars() { @@ -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