Skip to content

Commit

Permalink
test(derive): Highlight current behavior for version/help
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 5, 2022
1 parent 95207a1 commit 69ad5cf
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/derive/flags.rs
Expand Up @@ -12,6 +12,7 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.

use clap::CommandFactory;
use clap::Parser;

#[test]
Expand Down Expand Up @@ -42,6 +43,43 @@ fn bool_type_is_flag() {
assert!(Opt::try_parse_from(&["test", "-a", "foo"]).is_err());
}

#[test]
#[ignore] // Not a good path for supporting this atm
fn inferred_help() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
/// Foo
#[clap(short, long)]
help: bool,
}

let mut cmd = Opt::command();
cmd.build();
let arg = cmd.get_arguments().find(|a| a.get_id() == "help").unwrap();
assert_eq!(arg.get_help(), Some("Foo"), "Incorrect help");
assert!(matches!(arg.get_action(), clap::ArgAction::Help));
}

#[test]
#[ignore] // Not a good path for supporting this atm
fn inferred_version() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
/// Foo
#[clap(short, long)]
version: bool,
}

let mut cmd = Opt::command();
cmd.build();
let arg = cmd
.get_arguments()
.find(|a| a.get_id() == "version")
.unwrap();
assert_eq!(arg.get_help(), Some("Foo"), "Incorrect help");
assert!(matches!(arg.get_action(), clap::ArgAction::Version));
}

#[test]
fn count() {
#[derive(Parser, PartialEq, Debug)]
Expand Down

0 comments on commit 69ad5cf

Please sign in to comment.