From c1c7db5bf82e24c5cacbb5718de4dfb27eca7565 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 5 Aug 2022 14:22:09 -0500 Subject: [PATCH] test(derive): Highlight current behavior for version/help --- tests/derive/flags.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/derive/flags.rs b/tests/derive/flags.rs index 77383f92df34..31343206231d 100644 --- a/tests/derive/flags.rs +++ b/tests/derive/flags.rs @@ -12,6 +12,7 @@ // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the // MIT/Apache 2.0 license. +use clap::CommandFactory; use clap::Parser; #[test] @@ -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)]