Skip to content

Commit

Permalink
Merge clap-rs#2962
Browse files Browse the repository at this point in the history
2962: Fix some test cases to print correct failure message r=epage a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
  • Loading branch information
bors[bot] and pksunkara committed Oct 29, 2021
2 parents b5e3900 + 2984748 commit 7ce5d79
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
24 changes: 20 additions & 4 deletions tests/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ fn conflicts_with_alongside_default() {
.arg(Arg::from("-f, --flag 'some flag'"))
.try_get_matches_from(vec!["myprog", "-f"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"conflicts_with should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -279,7 +283,11 @@ fn group_in_conflicts_with() {
.arg(Arg::new("flag").long("flag").conflicts_with("one"))
.try_get_matches_from(vec!["myprog", "--flag"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"conflicts_with on an arg group should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -298,7 +306,11 @@ fn group_conflicts_with_default_value() {
.arg(Arg::new("flag").long("flag").group("one"))
.try_get_matches_from(vec!["myprog", "--flag"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"arg group count should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -313,7 +325,11 @@ fn group_conflicts_with_default_arg() {
.group(ArgGroup::new("one").conflicts_with("opt"))
.try_get_matches_from(vec!["myprog", "--flag"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"arg group conflicts_with should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand Down
34 changes: 27 additions & 7 deletions tests/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,14 @@ fn required_unless_all_with_any() {

let result = app.clone().try_get_matches_from(vec!["myprog", "--foo"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(result.is_ok(), "{:?}", result.unwrap_err());
assert!(!result.unwrap().is_present("flag"));

let result = app
.clone()
.try_get_matches_from(vec!["myprog", "--bar", "--baz"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(result.is_ok(), "{:?}", result.unwrap_err());
assert!(!result.unwrap().is_present("flag"));

let result = app.try_get_matches_from(vec!["myprog", "--bar"]);
Expand Down Expand Up @@ -1154,7 +1154,11 @@ fn requires_with_default_value() {
.arg(Arg::new("flag").long("flag"))
.try_get_matches_from(vec!["myprog"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"requires should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -1173,7 +1177,11 @@ fn requires_if_with_default_value() {
.arg(Arg::new("flag").long("flag"))
.try_get_matches_from(vec!["myprog"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"requires_if should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -1188,7 +1196,11 @@ fn group_requires_with_default_value() {
.group(ArgGroup::new("one").arg("opt").requires("flag"))
.try_get_matches_from(vec!["myprog"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"arg group requires should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -1206,7 +1218,11 @@ fn required_if_eq_on_default_value() {
)
.try_get_matches_from(vec!["myprog"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"required_if_eq should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand All @@ -1224,7 +1240,11 @@ fn required_if_eq_all_on_default_value() {
)
.try_get_matches_from(vec!["myprog"]);

assert!(result.is_ok(), "{:?}", result.unwrap());
assert!(
result.is_ok(),
"required_if_eq_all should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();

assert_eq!(m.value_of("opt"), Some("default"));
Expand Down

0 comments on commit 7ce5d79

Please sign in to comment.