Skip to content

Commit

Permalink
test: Add failing test for issue clap-rs#4520
Browse files Browse the repository at this point in the history
This test is semantically equivalent to the situation described in that
issue's description:
a first option conflicts with a second option.
a third option requires the second option.
Clap lets us provide the first and the third options only, which
shouldn't be allowed.

The test fails here, but is fixed by the next commit in this PR.
  • Loading branch information
pierrechevalier83 committed Nov 29, 2022
1 parent ad47263 commit 2c51d8f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/builder/require.rs
Expand Up @@ -41,6 +41,18 @@ fn option_required() {
assert_eq!(err.kind(), ErrorKind::MissingRequiredArgument);
}

#[test]
fn option_required_and_conflicts_with_other_option() {
let result = Command::new("cli")
.arg(arg!(brick: -b "do something harmful"))
.arg(arg!(fix: -f "do something good").conflicts_with("brick"))
.arg(arg!(dry_run: -d "don't do it Louis").requires("fix"))
.try_get_matches_from(vec!["", "-b", "-d"]);
assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(err.kind(), ErrorKind::MissingRequiredArgument);
}

#[test]
fn option_required_2() {
let m = Command::new("option_required")
Expand Down

0 comments on commit 2c51d8f

Please sign in to comment.