Skip to content

Commit

Permalink
test(parser): Verify conflicts with precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 11, 2024
1 parent e2b18f1 commit 69c0509
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/builder/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,48 @@ fn flag_conflicts_with_subcommand_short_flag() {
assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind());
}

#[test]
#[cfg(feature = "error-context")]
fn positional_conflicts_with_subcommand_precedent() {
static CONFLICT_ERR: &str = "\
error: unexpected argument 'sub' found
Usage: test <arg1>
test <COMMAND>
For more information, try '--help'.
";

let cmd = Command::new("test")
.args_conflicts_with_subcommands(true)
.subcommand_precedence_over_arg(true)
.arg(arg!(<arg1> "some arg"))
.subcommand(Command::new("sub"));

utils::assert_output(cmd, "test hello sub", CONFLICT_ERR, true);
}

#[test]
#[cfg(feature = "error-context")]
fn flag_conflicts_with_subcommand_precedent() {
static CONFLICT_ERR: &str = "\
error: unexpected argument 'sub' found
Usage: test [OPTIONS]
test <COMMAND>
For more information, try '--help'.
";

let cmd = Command::new("test")
.args_conflicts_with_subcommands(true)
.subcommand_precedence_over_arg(true)
.arg(arg!(--hello))
.subcommand(Command::new("sub"));

utils::assert_output(cmd, "test --hello sub", CONFLICT_ERR, true);
}

#[test]
fn subcommand_conflict_negates_required() {
let cmd = Command::new("test")
Expand Down

0 comments on commit 69c0509

Please sign in to comment.