mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
test(parser): Verify conflicts with precedence
This commit is contained in:
parent
e2b18f199f
commit
69c0509198
1 changed files with 42 additions and 0 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue