Skip to content

Commit 6827841

Browse files
committed
test(parser): Show bad ignore_errors defaulting case
1 parent 76d0049 commit 6827841

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/builder/ignore_errors.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@ fn multiple_args_and_intermittent_arg_without_value() {
9595
assert_eq!(m.get_one::<bool>("unset-flag").copied(), Some(false));
9696
}
9797

98+
#[test]
99+
fn unexpected_argument() {
100+
let cmd = Command::new("cmd")
101+
.ignore_errors(true)
102+
.arg(arg!(
103+
-c --config [FILE] "Sets a custom config file"
104+
))
105+
.arg(arg!(--"unset-flag"));
106+
107+
let r = cmd.try_get_matches_from(vec!["cmd", "-c", "config file", "unexpected"]);
108+
109+
assert!(r.is_ok(), "unexpected error: {r:?}");
110+
let m = r.unwrap();
111+
assert!(m.contains_id("config"));
112+
assert_eq!(
113+
m.get_one::<String>("config").cloned(),
114+
Some("config file".to_owned())
115+
);
116+
assert_eq!(m.get_one::<bool>("unset-flag").copied(), None);
117+
}
118+
98119
#[test]
99120
fn subcommand() {
100121
let cmd = Command::new("test")

0 commit comments

Comments
 (0)