Skip to content

Commit

Permalink
tests(Requirements): adds tests for required but conflicting args
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Feb 5, 2018
1 parent 0d470af commit f258b43
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,51 @@ USAGE:
For more information try --help";

static ISSUE_1158: &'static str = "error: The following required arguments were not provided:
-x <X>
-y <Y>
-z <Z>
USAGE:
example [OPTIONS] <ID> -x <X> -y <Y> -z <Z>
For more information try --help";

#[test]
fn issue_1158_conflicting_requirements() {
let app = App::new("example")
.arg(Arg::from_usage("-c, --config [FILE] 'Custom config file.'")
.required_unless("ID")
.conflicts_with("ID"))
.arg(Arg::from_usage("[ID] 'ID'")
.required_unless("config")
.conflicts_with("config")
.requires_all(&["x", "y", "z"]))
.arg(Arg::from_usage("-x [X] 'X'"))
.arg(Arg::from_usage("-y [Y] 'Y'"))
.arg(Arg::from_usage("-z [Z] 'Z'"));

assert!(test::compare_output(app, "example id", ISSUE_1158, true));
}

#[test]
fn issue_1158_conflicting_requirements_rev() {
let res = App::new("example")
.arg(Arg::from_usage("-c, --config [FILE] 'Custom config file.'")
.required_unless("ID")
.conflicts_with("ID"))
.arg(Arg::from_usage("[ID] 'ID'")
.required_unless("config")
.conflicts_with("config")
.requires_all(&["x", "y", "z"]))
.arg(Arg::from_usage("-x [X] 'X'"))
.arg(Arg::from_usage("-y [Y] 'Y'"))
.arg(Arg::from_usage("-z [Z] 'Z'"))
.get_matches_from_safe(vec!["example", "--config", "some"]);

assert!(res.is_ok());
}

#[test]
fn flag_required() {
let result = App::new("flag_required")
Expand Down

0 comments on commit f258b43

Please sign in to comment.