test(parser): Verify conflicts with precedence

This commit is contained in:
Ed Page 2024-01-11 09:14:37 -06:00
parent e2b18f199f
commit 69c0509198

View file

@ -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")