Skip to content

Commit

Permalink
test(parser): Consolidate args_conflicts_with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 21, 2022
1 parent a72f962 commit f632424
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
46 changes: 0 additions & 46 deletions tests/builder/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,52 +654,6 @@ Options:
utils::assert_output(cmd, "clap-test --help", REQUIRE_EQUALS, false);
}

#[test]
fn args_negate_subcommands_one_level() {
let res = Command::new("disablehelp")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg1> "some arg"))
.arg(arg!(<arg2> "some arg"))
.subcommand(
Command::new("sub1").subcommand(Command::new("sub2").subcommand(Command::new("sub3"))),
)
.try_get_matches_from(vec!["", "pickles", "sub1"]);
assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind());
let m = res.unwrap();
assert_eq!(
m.get_one::<String>("arg2").map(|v| v.as_str()),
Some("sub1")
);
}

#[test]
fn args_negate_subcommands_two_levels() {
let res = Command::new("disablehelp")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg1> "some arg"))
.arg(arg!(<arg2> "some arg"))
.subcommand(
Command::new("sub1")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg> "some"))
.arg(arg!(<arg2> "some"))
.subcommand(Command::new("sub2").subcommand(Command::new("sub3"))),
)
.try_get_matches_from(vec!["", "sub1", "arg", "sub2"]);
assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind());
let m = res.unwrap();
assert_eq!(
m.subcommand_matches("sub1")
.unwrap()
.get_one::<String>("arg2")
.map(|v| v.as_str()),
Some("sub2")
);
}

#[test]
fn propagate_vals_down() {
let m = Command::new("myprog")
Expand Down
46 changes: 46 additions & 0 deletions tests/builder/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,52 @@ fn exclusive_with_required() {
cmd.clone().try_get_matches_from(["bug", "--test"]).unwrap();
}

#[test]
fn args_negate_subcommands_one_level() {
let res = Command::new("disablehelp")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg1> "some arg"))
.arg(arg!(<arg2> "some arg"))
.subcommand(
Command::new("sub1").subcommand(Command::new("sub2").subcommand(Command::new("sub3"))),
)
.try_get_matches_from(vec!["", "pickles", "sub1"]);
assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind());
let m = res.unwrap();
assert_eq!(
m.get_one::<String>("arg2").map(|v| v.as_str()),
Some("sub1")
);
}

#[test]
fn args_negate_subcommands_two_levels() {
let res = Command::new("disablehelp")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg1> "some arg"))
.arg(arg!(<arg2> "some arg"))
.subcommand(
Command::new("sub1")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg> "some"))
.arg(arg!(<arg2> "some"))
.subcommand(Command::new("sub2").subcommand(Command::new("sub3"))),
)
.try_get_matches_from(vec!["", "sub1", "arg", "sub2"]);
assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind());
let m = res.unwrap();
assert_eq!(
m.subcommand_matches("sub1")
.unwrap()
.get_one::<String>("arg2")
.map(|v| v.as_str()),
Some("sub2")
);
}

#[test]
fn subcommand_conflict_negates_required() {
let cmd = Command::new("test")
Expand Down

0 comments on commit f632424

Please sign in to comment.