diff --git a/tests/builder/conflicts.rs b/tests/builder/conflicts.rs index 799dcd3d0dd..72d9a986250 100644 --- a/tests/builder/conflicts.rs +++ b/tests/builder/conflicts.rs @@ -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 + test + +For more information, try '--help'. +"; + + let cmd = Command::new("test") + .args_conflicts_with_subcommands(true) + .subcommand_precedence_over_arg(true) + .arg(arg!( "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 + +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")