Skip to content

Commit

Permalink
test(parser): Show bad ignore_errors defaulting case
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 12, 2024
1 parent 76d0049 commit 6827841
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/builder/ignore_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ fn multiple_args_and_intermittent_arg_without_value() {
assert_eq!(m.get_one::<bool>("unset-flag").copied(), Some(false));
}

#[test]
fn unexpected_argument() {
let cmd = Command::new("cmd")
.ignore_errors(true)
.arg(arg!(
-c --config [FILE] "Sets a custom config file"
))
.arg(arg!(--"unset-flag"));

let r = cmd.try_get_matches_from(vec!["cmd", "-c", "config file", "unexpected"]);

assert!(r.is_ok(), "unexpected error: {r:?}");
let m = r.unwrap();
assert!(m.contains_id("config"));
assert_eq!(
m.get_one::<String>("config").cloned(),
Some("config file".to_owned())
);
assert_eq!(m.get_one::<bool>("unset-flag").copied(), None);
}

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

0 comments on commit 6827841

Please sign in to comment.