Skip to content

Commit

Permalink
fix(assert): Clean up num_args/action assert
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2025
1 parent 2bc0f45 commit 80ea3e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions clap_builder/src/builder/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,10 @@ fn assert_arg(arg: &Arg) {
if arg.is_takes_value_set() {
assert!(
arg.get_action().takes_values(),
"Argument `{}`'s selected action {:?} contradicts `takes_value`",
"Argument `{}`'s action {:?} is incompatible with `num_args({:?})`",
arg.get_id(),
arg.get_action()
arg.get_action(),
arg.get_num_args().unwrap_or(1.into())
);
}
if let Some(action_type_id) = arg.get_action().value_type_id() {
Expand Down
14 changes: 7 additions & 7 deletions tests/builder/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn set_true_with_required_if_eq() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action SetTrue contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action SetTrue is incompatible with `num_args(1..)`"]
fn set_true_with_incompatible_num_args() {
Command::new("test")
.arg(
Expand Down Expand Up @@ -347,7 +347,7 @@ fn set_false_with_default_value_if_value() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action SetFalse contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action SetFalse is incompatible with `num_args(1..)`"]
fn set_false_with_incompatible_num_args() {
Command::new("test")
.arg(
Expand Down Expand Up @@ -470,7 +470,7 @@ fn count_with_default_value_if_value() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action Count contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action Count is incompatible with `num_args(1..)`"]
fn count_with_incompatible_num_args() {
Command::new("test")
.arg(
Expand All @@ -483,7 +483,7 @@ fn count_with_incompatible_num_args() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action Help contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action Help is incompatible with `num_args(1..)`"]
fn help_with_incompatible_num_args() {
Command::new("test")
.arg(
Expand All @@ -496,7 +496,7 @@ fn help_with_incompatible_num_args() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action HelpShort contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action HelpShort is incompatible with `num_args(1..)`"]
fn help_short_with_incompatible_num_args() {
Command::new("test")
.arg(
Expand All @@ -509,7 +509,7 @@ fn help_short_with_incompatible_num_args() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action HelpLong contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action HelpLong is incompatible with `num_args(1..)`"]
fn help_long_with_incompatible_num_args() {
Command::new("test")
.arg(
Expand All @@ -522,7 +522,7 @@ fn help_long_with_incompatible_num_args() {
}

#[test]
#[should_panic = "Argument `mammal`'s selected action Version contradicts `takes_value`"]
#[should_panic = "Argument `mammal`'s action Version is incompatible with `num_args(1..)`"]
fn version_with_incompatible_num_args() {
Command::new("test")
.version("1.0.0")
Expand Down

0 comments on commit 80ea3e7

Please sign in to comment.