Skip to content

Commit a0187c6

Browse files
committed
test(assert): Verify num_args/action compat
1 parent a8f9885 commit a0187c6

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

tests/builder/action.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ fn set_true_with_required_if_eq() {
219219
assert_eq!(matches.get_flag("mammal"), true);
220220
}
221221

222+
#[test]
223+
#[should_panic = "Argument `mammal`'s selected action SetTrue contradicts `takes_value`"]
224+
fn set_true_with_incompatible_num_args() {
225+
Command::new("test")
226+
.arg(
227+
Arg::new("mammal")
228+
.long("mammal")
229+
.action(ArgAction::SetTrue)
230+
.num_args(1..),
231+
)
232+
.build();
233+
}
234+
222235
#[test]
223236
fn set_false() {
224237
let cmd = Command::new("test").arg(
@@ -333,6 +346,19 @@ fn set_false_with_default_value_if_value() {
333346
assert_eq!(matches.get_flag("mammal"), false);
334347
}
335348

349+
#[test]
350+
#[should_panic = "Argument `mammal`'s selected action SetFalse contradicts `takes_value`"]
351+
fn set_false_with_incompatible_num_args() {
352+
Command::new("test")
353+
.arg(
354+
Arg::new("mammal")
355+
.long("mammal")
356+
.action(ArgAction::SetFalse)
357+
.num_args(1..),
358+
)
359+
.build();
360+
}
361+
336362
#[test]
337363
fn count() {
338364
let cmd = Command::new("test").arg(Arg::new("mammal").long("mammal").action(ArgAction::Count));
@@ -442,3 +468,69 @@ fn count_with_default_value_if_value() {
442468
assert_eq!(*matches.get_one::<u8>("dog").unwrap(), 0);
443469
assert_eq!(*matches.get_one::<u8>("mammal").unwrap(), 1);
444470
}
471+
472+
#[test]
473+
#[should_panic = "Argument `mammal`'s selected action Count contradicts `takes_value`"]
474+
fn count_with_incompatible_num_args() {
475+
Command::new("test")
476+
.arg(
477+
Arg::new("mammal")
478+
.long("mammal")
479+
.action(ArgAction::Count)
480+
.num_args(1..),
481+
)
482+
.build();
483+
}
484+
485+
#[test]
486+
#[should_panic = "Argument `mammal`'s selected action Help contradicts `takes_value`"]
487+
fn help_with_incompatible_num_args() {
488+
Command::new("test")
489+
.arg(
490+
Arg::new("mammal")
491+
.long("mammal")
492+
.action(ArgAction::Help)
493+
.num_args(1..),
494+
)
495+
.build();
496+
}
497+
498+
#[test]
499+
#[should_panic = "Argument `mammal`'s selected action HelpShort contradicts `takes_value`"]
500+
fn help_short_with_incompatible_num_args() {
501+
Command::new("test")
502+
.arg(
503+
Arg::new("mammal")
504+
.long("mammal")
505+
.action(ArgAction::HelpShort)
506+
.num_args(1..),
507+
)
508+
.build();
509+
}
510+
511+
#[test]
512+
#[should_panic = "Argument `mammal`'s selected action HelpLong contradicts `takes_value`"]
513+
fn help_long_with_incompatible_num_args() {
514+
Command::new("test")
515+
.arg(
516+
Arg::new("mammal")
517+
.long("mammal")
518+
.action(ArgAction::HelpLong)
519+
.num_args(1..),
520+
)
521+
.build();
522+
}
523+
524+
#[test]
525+
#[should_panic = "Argument `mammal`'s selected action Version contradicts `takes_value`"]
526+
fn version_with_incompatible_num_args() {
527+
Command::new("test")
528+
.version("1.0.0")
529+
.arg(
530+
Arg::new("mammal")
531+
.long("mammal")
532+
.action(ArgAction::Version)
533+
.num_args(1..),
534+
)
535+
.build();
536+
}

0 commit comments

Comments
 (0)