Skip to content

Commit

Permalink
tests: adds require_unless_one test cases
Browse files Browse the repository at this point in the history
* test: `require_unless_one` with second argument

Add the `require_unless_one_2` test. This tests that when the second
argument in the array is used at the command line, that the required
argument is not present. This test was added because it appears the
`require_unless_one` function only works for the first argument in the
array.

* Fix: assertions for test

The assertions did not check for the `infile` to be present.
  • Loading branch information
volks73 authored and kbknapp committed Jul 23, 2016
1 parent af4bb4c commit 1b99091
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,30 @@ fn required_unless_one() {
assert!(!m.is_present("cfg"));
}

#[test]
fn required_unless_one_2() {
// This tests that the required_unless_one works when the second arg in the array is used
// instead of the first.
let res = App::new("unlessone")
.arg(Arg::with_name("cfg")
.required_unless_one(&["dbg", "infile"])
.takes_value(true)
.long("config"))
.arg(Arg::with_name("dbg")
.long("debug"))
.arg(Arg::with_name("infile")
.short("i")
.takes_value(true))
.get_matches_from_safe(vec![
"unlessone", "-i", "file"
]);

assert!(res.is_ok());
let m = res.unwrap();
assert!(m.is_present("infile"));
assert!(!m.is_present("cfg"));
}

#[test]
fn required_unless_one_err() {
let res = App::new("unlessone")
Expand Down

0 comments on commit 1b99091

Please sign in to comment.