Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert on leading and trailing whitespace #2786

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 21 additions & 10 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ USAGE:

FLAGS:
-h, --help Print help information
-V, --version Print version information";
-V, --version Print version information
";
epage marked this conversation as resolved.
Show resolved Hide resolved

static DONT_COLLAPSE_ARGS: &str = "clap-test v1.4.8

Expand All @@ -23,7 +24,8 @@ ARGS:

FLAGS:
-h, --help Print help information
-V, --version Print version information";
-V, --version Print version information
";

static REQUIRE_EQUALS: &str = "clap-test v1.4.8

Expand All @@ -35,7 +37,8 @@ FLAGS:
-V, --version Print version information

OPTIONS:
-o, --opt=<FILE> some";
-o, --opt=<FILE> some
";

static UNIFIED_HELP: &str = "test 1.3

Expand All @@ -53,7 +56,8 @@ OPTIONS:
-f, --flag some flag
-h, --help Print help information
--option <opt> some option
-V, --version Print version information";
-V, --version Print version information
";

static SKIP_POS_VALS: &str = "test 1.3

Expand All @@ -72,7 +76,8 @@ FLAGS:
-V, --version Print version information

OPTIONS:
-o, --opt <opt> some option";
-o, --opt <opt> some option
";

static ARG_REQUIRED_ELSE_HELP: &str = "test 1.0

Expand All @@ -82,7 +87,8 @@ USAGE:
FLAGS:
-h, --help Print help information
-i, --info Provides more info
-V, --version Print version information";
-V, --version Print version information
";

static SUBCOMMAND_REQUIRED_ELSE_HELP: &str = "test 1.0

Expand All @@ -95,7 +101,8 @@ FLAGS:

SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)
info";
info
";

static LONG_FORMAT_FOR_HELP_SUBCOMMAND: &str = "myprog-test

Expand All @@ -111,7 +118,8 @@ FLAGS:
Print help information

-V, --version
Print version information";
Print version information
";

static LONG_FORMAT_FOR_NESTED_HELP_SUBCOMMAND: &str = "myprog-test-nested

Expand All @@ -125,7 +133,8 @@ FLAGS:
Print help information

-V, --version
Print version information";
Print version information
";

static LONG_FORMAT_SINGLE_ARG_HELP_SUBCOMMAND: &str = "myprog

Expand All @@ -146,7 +155,9 @@ FLAGS:
SUBCOMMANDS:
help
Print this message or the help of the given subcommand(s)
test";
test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be incorrect, will open a ticket

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also expected, given the trailing spaces on short format help messages

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when there's a subcommand starting with z? Would appreciate you looking into it and then creating an issue with expected behaviour. In fact, there might one already for short format help messages.

";

#[test]
fn sub_command_negate_required() {
Expand Down
6 changes: 4 additions & 2 deletions tests/arg_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ FLAGS:
-V, --version Print version information

OPTIONS:
-o, --opt <opt> [aliases: visible]";
-o, --opt <opt> [aliases: visible]
";
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if all of these tests need to care about whitspace, rather than having the full help-specific tests focus it.

My concern is with the cost of a change and ensuring that cost is not unnecessarily burdensome. For example, an arg alias test is only about a fraction of the overall output. If someone makes a change within a different part of clap, it shouldn't break arg aliases tests but only tests related to what was changed.

(Personally, I'd prefer we find a way to make these tests only care about the part of the help that is relevant.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this change would affect tests-breaking-at-a-distance. My main change was in tests/utils.rs, to stop us from stripping the trailing whitespace from assertions. Given that that file is used by all these tests, having to update all of them is expected.

Going forward with other changes in a particular area, such a wide sweep should not be necessary


static SC_INVISIBLE_ALIAS_HELP: &str = "ct-test 1.2

Expand All @@ -30,7 +31,8 @@ FLAGS:
-V, --version Print version information

OPTIONS:
-o, --opt <opt> ";
-o, --opt <opt>
";

#[test]
fn single_alias_of_option() {
Expand Down
6 changes: 4 additions & 2 deletions tests/arg_aliases_short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ FLAGS:
-V, --version Print version information

OPTIONS:
-o, --opt <opt> [short aliases: v]";
-o, --opt <opt> [short aliases: v]
";

static SC_INVISIBLE_ALIAS_HELP: &str = "ct-test 1.2

Expand All @@ -30,7 +31,8 @@ FLAGS:
-V, --version Print version information

OPTIONS:
-o, --opt <opt> ";
-o, --opt <opt>
";

#[test]
fn single_short_alias_of_option() {
Expand Down
9 changes: 6 additions & 3 deletions tests/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ static CONFLICT_ERR: &str = "error: The argument '-F' cannot be used with '--fla
USAGE:
clap-test --flag --long-option-2 <option2> <positional> <positional2>

For more information try --help";
For more information try --help
";

static CONFLICT_ERR_REV: &str = "error: The argument '--flag' cannot be used with '-F'

USAGE:
clap-test -F --long-option-2 <option2> <positional> <positional2>

For more information try --help";
For more information try --help
";

static CONFLICT_ERR_THREE: &str = "error: The argument '--two' cannot be used with '--one'

USAGE:
three_conflicting_arguments --one

For more information try --help";
For more information try --help
";

#[test]
fn flag_conflict() {
Expand Down
3 changes: 2 additions & 1 deletion tests/default_vals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ fn default_vals_donnot_show_in_smart_usage() {
USAGE:
bug [OPTIONS] <input>

For more information try --help",
For more information try --help
",
true,
));
}
Expand Down
30 changes: 20 additions & 10 deletions tests/derive_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ FLAGS:

OPTIONS:
--option_a <option_a> second option
--option_b <option_b> first option";
--option_b <option_b> first option
";

static DERIVE_ORDER: &str = "test 1.2

Expand All @@ -32,7 +33,8 @@ FLAGS:

OPTIONS:
--option_b <option_b> first option
--option_a <option_a> second option";
--option_a <option_a> second option
";

static UNIFIED_HELP: &str = "test 1.2

Expand All @@ -45,7 +47,8 @@ OPTIONS:
-h, --help Print help information
--option_a <option_a> second option
--option_b <option_b> first option
-V, --version Print version information";
-V, --version Print version information
";

static UNIFIED_HELP_AND_DERIVE: &str = "test 1.2

Expand All @@ -58,7 +61,8 @@ OPTIONS:
--flag_b first flag
--option_b <option_b> first option
--flag_a second flag
--option_a <option_a> second option";
--option_a <option_a> second option
";

static DERIVE_ORDER_SC_PROP: &str = "test-sub 1.2

Expand All @@ -73,7 +77,8 @@ FLAGS:

OPTIONS:
--option_b <option_b> first option
--option_a <option_a> second option";
--option_a <option_a> second option
";

static UNIFIED_SC_PROP: &str = "test-sub 1.2

Expand All @@ -86,7 +91,8 @@ OPTIONS:
-h, --help Print help information
--option_a <option_a> second option
--option_b <option_b> first option
-V, --version Print version information";
-V, --version Print version information
";

static UNIFIED_DERIVE_SC_PROP: &str = "test-sub 1.2

Expand All @@ -99,7 +105,8 @@ OPTIONS:
--flag_a second flag
--option_a <option_a> second option
-h, --help Print help information
-V, --version Print version information";
-V, --version Print version information
";

static UNIFIED_DERIVE_SC_PROP_EXPLICIT_ORDER: &str = "test-sub 1.2

Expand All @@ -112,7 +119,8 @@ OPTIONS:
--option_b <option_b> first option
--option_a <option_a> second option
-h, --help Print help information
-V, --version Print version information";
-V, --version Print version information
";

static PREFER_USER_HELP_DERIVE_ORDER: &str = "test 1.2

Expand All @@ -123,7 +131,8 @@ FLAGS:
-V, --version Print version information
-h, --help Print help message
--flag_b first flag
--flag_a second flag";
--flag_a second flag
";

static PREFER_USER_HELP_SUBCMD_DERIVE_ORDER: &str = "test-sub 1.2

Expand All @@ -134,7 +143,8 @@ FLAGS:
-h, --help Print help message
--flag_b first flag
--flag_a second flag
-V, --version Print version information";
-V, --version Print version information
";

#[test]
fn no_derive_order() {
Expand Down
3 changes: 2 additions & 1 deletion tests/display_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ FLAGS:

SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)
sub",
sub
",
false
));
}
3 changes: 2 additions & 1 deletion tests/empty_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ fn no_empty_values_without_equals_but_requires_equals() {
USAGE:
config [OPTIONS]

For more information try --help";
For more information try --help
";

assert!(utils::compare_output(
app,
Expand Down
9 changes: 6 additions & 3 deletions tests/flag_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ FLAGS:

OPTIONS:
-i, --info <info>... view package information
-s, --search <search>... search locally installed packages for matching strings";
-s, --search <search>... search locally installed packages for matching strings
";

#[test]
fn flag_subcommand_long_short_normal_usage_string() {
Expand Down Expand Up @@ -493,7 +494,8 @@ FLAGS:

OPTIONS:
-i, --info <info>... view package information
-s, --search <search>... search locally installed packages for matching strings";
-s, --search <search>... search locally installed packages for matching strings
";

#[test]
fn flag_subcommand_long_normal_usage_string() {
Expand Down Expand Up @@ -549,7 +551,8 @@ FLAGS:

OPTIONS:
-i, --info <info>... view package information
-s, --search <search>... search locally installed packages for matching strings";
-s, --search <search>... search locally installed packages for matching strings
";

#[test]
fn flag_subcommand_short_normal_usage_string() {
Expand Down
6 changes: 4 additions & 2 deletions tests/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const USE_FLAG_AS_ARGUMENT: &str =
USAGE:
mycat [FLAGS] [filename]

For more information try --help";
For more information try --help
";

#[test]
fn flag_using_short() {
Expand Down Expand Up @@ -168,7 +169,8 @@ fn issue_2308_multiple_dashes() {
USAGE:
test <arg>

For more information try --help";
For more information try --help
";
let app = App::new("test").arg(Arg::new("arg").takes_value(true).required(true));

assert!(utils::compare_output(
Expand Down
12 changes: 8 additions & 4 deletions tests/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ static REQ_GROUP_USAGE: &str = "error: The following required arguments were not
USAGE:
clap-test <base|--delete>

For more information try --help";
For more information try --help
";

static REQ_GROUP_CONFLICT_USAGE: &str =
"error: The argument '--delete' cannot be used with '<base>'

USAGE:
clap-test <base|--delete>

For more information try --help";
For more information try --help
";

static REQ_GROUP_CONFLICT_ONLY_OPTIONS: &str =
"error: The argument '--delete' cannot be used with '--all'

USAGE:
clap-test <--all|--delete>

For more information try --help";
For more information try --help
";

#[test]
fn required_group_missing_arg() {
Expand Down Expand Up @@ -264,7 +267,8 @@ ARGS:

FLAGS:
-h, --help Print help information
-V, --version Print version information";
-V, --version Print version information
";
let app = App::new("prog")
.arg(Arg::new("a").value_name("A"))
.group(ArgGroup::new("group").arg("a").required(true));
Expand Down