From 642db9b042c29fdcb5e77b0529ad01e57cb54355 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Thu, 9 Mar 2017 08:52:37 -0500 Subject: [PATCH] tests: adds tests for new dual usage strings with certain subcommand settings --- tests/help.rs | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/help.rs b/tests/help.rs index 63266442..4e5a6489 100644 --- a/tests/help.rs +++ b/tests/help.rs @@ -36,6 +36,47 @@ SUBCOMMANDS: help Prints this message or the help of the given subcommand(s) subcmd tests subcommands"; +static SC_NEGATES_REQS: &'static str = "prog 1.0 + +USAGE: + prog --opt [PATH] + prog [PATH] + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -o, --opt tests options + +ARGS: + + +SUBCOMMANDS: + help Prints this message or the help of the given subcommand(s) + test"; + +static ARGS_NEGATE_SC: &'static str = "prog 1.0 + +USAGE: + prog [FLAGS] [OPTIONS] [PATH] + prog + +FLAGS: + -f, --flag testing flags + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -o, --opt tests options + +ARGS: + + +SUBCOMMANDS: + help Prints this message or the help of the given subcommand(s) + test"; + static AFTER_HELP: &'static str = "some text that comes before the help clap-test v1.4.8 @@ -50,6 +91,19 @@ FLAGS: some text that comes after the help"; +static HIDDEN_ARGS: &'static str = "prog 1.0 + +USAGE: + prog [FLAGS] [OPTIONS] + +FLAGS: + -f, --flag testing flags + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -o, --opt tests options"; + static SC_HELP: &'static str = "clap-test-subcmd 0.1 Kevin K. tests subcommands @@ -531,6 +585,40 @@ fn issue_760() { .takes_value(true)); assert!(test::compare_output(app, "ctest --help", ISSUE_760, false)); } + +#[test] +fn hidden_args() { + let app = App::new("prog") + .version("1.0") + .args_from_usage("-f, --flag 'testing flags' + -o, --opt [FILE] 'tests options'") + .arg(Arg::with_name("pos").hidden(true)); + assert!(test::compare_output(app, "prog --help", HIDDEN_ARGS, false)); +} + +#[test] +fn sc_negates_reqs() { + let app = App::new("prog") + .version("1.0") + .setting(AppSettings::SubcommandsNegateReqs) + .arg_from_usage("-o, --opt 'tests options'") + .arg(Arg::with_name("PATH")) + .subcommand(SubCommand::with_name("test")); + assert!(test::compare_output(app, "prog --help", SC_NEGATES_REQS, false)); +} + +#[test] +fn args_negate_sc() { + let app = App::new("prog") + .version("1.0") + .setting(AppSettings::ArgsNegateSubcommands) + .args_from_usage("-f, --flag 'testing flags' + -o, --opt [FILE] 'tests options'") + .arg(Arg::with_name("PATH")) + .subcommand(SubCommand::with_name("test")); + assert!(test::compare_output(app, "prog --help", ARGS_NEGATE_SC, false)); +} + #[test] fn issue_777_wrap_all_things() { let app = App::new("A app with a crazy very long long long name hahaha")