-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and fixed display of conflicted flags
- Loading branch information
1 parent
444bce2
commit c34a0fd
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use clap::{App, Arg}; | ||
|
||
#[test] | ||
fn two_conflicting_arguments() { | ||
let a = App::new("two_conflicting_arguments") | ||
.arg( | ||
Arg::with_name("develop") | ||
.long("develop") | ||
.conflicts_with("production"), | ||
) | ||
.arg( | ||
Arg::with_name("production") | ||
.long("production") | ||
.conflicts_with("develop"), | ||
) | ||
.try_get_matches_from(vec!["", "--develop", "--production"]); | ||
|
||
assert!(a.is_err()); | ||
let a = a.unwrap_err(); | ||
assert_eq!( | ||
a.cause, | ||
"The argument \'--develop\' cannot be used with \'--production\'" | ||
); | ||
} | ||
|
||
#[test] | ||
fn three_conflicting_arguments() { | ||
let a = App::new("two_conflicting_arguments") | ||
.arg( | ||
Arg::with_name("one") | ||
.long("one") | ||
.conflicts_with_all(&["two", "three"]), | ||
) | ||
.arg( | ||
Arg::with_name("two") | ||
.long("two") | ||
.conflicts_with_all(&["one", "three"]), | ||
) | ||
.arg( | ||
Arg::with_name("three") | ||
.long("three") | ||
.conflicts_with_all(&["one", "two"]), | ||
) | ||
.try_get_matches_from(vec!["", "--one", "--two", "--three"]); | ||
|
||
assert!(a.is_err()); | ||
let a = a.unwrap_err(); | ||
assert_eq!( | ||
a.cause, | ||
"The argument \'--one\' cannot be used with \'--two\'" | ||
); | ||
} |