clap/tests/template_help.rs
Oleksii Filonenko 1e39967044
Fix some clippy lints
- Manually fix some problems
- Run 'cargo fix --clippy'

Commits taken from similar PRs open at that time:

- Replace indexmap remove with swap_remove
  Resolves #1562 and closes #1563
- Use cognitive_complexity for clippy lint
  Resolves #1564 and closes #1565
- Replace deprecated trim_left_matches with trim_start_matches
  Closes #1539

Co-authored-by: Antoine Martin <antoine97.martin@gmail.com>
Co-authored-by: Brian Foley <bpfoley@users.noreply.github.com>
2019-10-29 21:46:25 -04:00

144 lines
3.6 KiB
Rust

extern crate clap;
extern crate regex;
use clap::App;
include!("../clap-test.rs");
static EXAMPLE1_TMPL_S: &str = include_str!("example1_tmpl_simple.txt");
static EXAMPLE1_TMPS_F: &str = include_str!("example1_tmpl_full.txt");
static CUSTOM_TEMPL_HELP: &str = "MyApp 1.0
Kevin K. <kbknapp@gmail.com>
Does awesome things
USAGE:
MyApp [FLAGS] [OPTIONS] <output> [SUBCOMMAND]
FLAGS:
-d Turn debugging information on
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-c, --config <FILE> Sets a custom config file
ARGS:
<output> Sets an optional output file
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
test does testing things";
static SIMPLE_TEMPLATE: &str = "MyApp 1.0
Kevin K. <kbknapp@gmail.com>
Does awesome things
USAGE:
MyApp [FLAGS] [OPTIONS] <output> [SUBCOMMAND]
ARGS:
<output> Sets an optional output file
FLAGS:
-d Turn debugging information on
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-c, --config <FILE> Sets a custom config file
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
test does testing things";
#[test]
fn with_template() {
let app = app_example1().help_template(EXAMPLE1_TMPL_S);
assert!(test::compare_output(
app,
"MyApp --help",
SIMPLE_TEMPLATE,
false
));
}
#[test]
fn custom_template() {
let app = app_example1().help_template(EXAMPLE1_TMPS_F);
assert!(test::compare_output(
app,
"MyApp --help",
CUSTOM_TEMPL_HELP,
false
));
}
#[test]
fn template_empty() {
let app = App::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.help_template("");
assert!(test::compare_output(app, "MyApp --help", "", false));
}
#[test]
fn template_notag() {
let app = App::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.help_template("test no tag test");
assert!(test::compare_output(
app,
"MyApp --help",
"test no tag test",
false
));
}
#[test]
fn template_unknowntag() {
let app = App::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.help_template("test {unknown_tag} test");
assert!(test::compare_output(
app,
"MyApp --help",
"test {unknown_tag} test",
false
));
}
#[test]
fn template_author_version() {
let app = App::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.help_template("{author}\n{version}\n{about}\n{bin}");
assert!(test::compare_output(
app,
"MyApp --help",
"Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp",
false
));
}
// ----------
fn app_example1<'b, 'c>() -> App<'c> {
App::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.arg("-c, --config=[FILE] 'Sets a custom config file'")
.arg("<output> 'Sets an optional output file'")
.arg("-d... 'Turn debugging information on'")
.subcommand(
App::new("test")
.about("does testing things")
.arg("-l, --list 'lists test values'"),
)
}