Skip to content

Commit

Permalink
test(Conditional Requirements): adds teste for conditional requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Dec 29, 2016
1 parent eb4010e commit eca6091
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,83 @@ USAGE:
For more information try --help", true)
}

// Conditional external requirements

#[test]
fn requires_if_present_val() {
let res = App::new("unlessone")
.arg(Arg::with_name("cfg")
.requires_if("my.cfg", "extra")
.takes_value(true)
.long("config"))
.arg(Arg::with_name("extra")
.long("extra"))
.get_matches_from_safe(vec![
"unlessone", "--config=my.cfg"
]);

assert!(res.is_err());
assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
}

#[test]
fn requires_if_present_mult() {
let res = App::new("unlessone")
.arg(Arg::with_name("cfg")
.requires_ifs(&[
("my.cfg", "extra"),
("other.cfg", "other"),
])
.takes_value(true)
.long("config"))
.arg(Arg::with_name("extra")
.long("extra"))
.arg(Arg::with_name("other")
.long("other"))
.get_matches_from_safe(vec![
"unlessone", "--config=other.cfg"
]);

assert!(res.is_err());
assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
}

#[test]
fn requires_if_present_mult_pass() {
let res = App::new("unlessone")
.arg(Arg::with_name("cfg")
.requires_ifs(&[
("my.cfg", "extra"),
("other.cfg", "other"),
])
.takes_value(true)
.long("config"))
.arg(Arg::with_name("extra")
.long("extra"))
.arg(Arg::with_name("other")
.long("other"))
.get_matches_from_safe(vec![
"unlessone", "--config=some.cfg"
]);

assert!(res.is_ok());
// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
}

#[test]
fn requires_if_present_val_no_present_pass() {
let res = App::new("unlessone")
.arg(Arg::with_name("cfg")
.requires_if("my.cfg", "extra")
.takes_value(true)
.long("config"))
.arg(Arg::with_name("extra")
.long("extra"))
.get_matches_from_safe(vec![
"unlessone",
]);

assert!(res.is_ok());
// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
}

0 comments on commit eca6091

Please sign in to comment.