tests: updates help tests to remove extra newline

This commit is contained in:
Kevin K 2016-05-30 05:39:54 -04:00
parent 054f8cb433
commit c8cc87ac10
4 changed files with 63 additions and 28 deletions

View file

@ -102,7 +102,7 @@ OPTIONS:
-V, --version Prints version information
ARGS:
<arg1> some pos arg\n"));
<arg1> some pos arg"));
}
#[test]
@ -135,5 +135,5 @@ OPTIONS:
-o, --opt <opt> some option
ARGS:
<arg1> some pos arg\n"));
<arg1> some pos arg"));
}

View file

@ -34,8 +34,7 @@ ARGS:
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
subcmd tests subcommands
";
subcmd tests subcommands";
static SC_HELP: &'static str = "subcmd 0.1
Kevin K. <kbknapp@gmail.com>
@ -51,8 +50,7 @@ OPTIONS:
-o, --option <scoption>... tests options
ARGS:
<scpositional> tests positionals
";
<scpositional> tests positionals";
#[test]
fn help_short() {

View file

@ -30,5 +30,5 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
--option <opt> some option\n"));
--option <opt> some option"));
}

View file

@ -7,6 +7,41 @@ use clap::{App, SubCommand};
static EXAMPLE1_TMPL_S : &'static str = include_str!("example1_tmpl_simple.txt");
static EXAMPLE1_TMPS_F : &'static str = include_str!("example1_tmpl_full.txt");
static CUSTOM_TEMPL_HELP: &'static str = "MyApp 1.0
Kevin K. <kbknapp@gmail.com>
Does awesome things
USAGE:
MyApp [FLAGS] [OPTIONS] <output> [SUBCOMMAND]
FLAGS:
-d Turn debugging information on
OPTIONS:
-c, --config <FILE> Sets a custom config file
ARGS:
<output> Sets an optional output file
SUBCOMMANDS:
test does testing things";
static SIMPLE_TEMPLATE: &'static str = "MyApp 1.0
Kevin K. <kbknapp@gmail.com>
Does awesome things
USAGE:
MyApp [FLAGS] [OPTIONS] <output> [SUBCOMMAND]
FLAGS:
-d Turn debugging information on
OPTIONS:
-c, --config <FILE> Sets a custom config file
ARGS:
<output> Sets an optional output file
SUBCOMMANDS:
test does testing things";
fn build_new_help(app: &App) -> String {
let mut buf = Cursor::new(Vec::with_capacity(50));
app.write_help(&mut buf).unwrap();
@ -14,27 +49,29 @@ fn build_new_help(app: &App) -> String {
String::from_utf8(content).unwrap()
}
fn compare2(app1: &App, app2: &App) -> bool {
let hlp1f = build_new_help(&app1);
let hlp1 = hlp1f.trim();
let hlp2f = build_new_help(&app2);
let hlp2 = hlp2f.trim();
let b = hlp1 == hlp2;
fn compare_app_str(l: &App, right: &str) -> bool {
let left = build_new_help(&l);
let b = left.trim() == right;
if !b {
println!("");
println!("--> hlp1");
println!("{}", hlp1);
println!("--> hlp2");
println!("{}", hlp2);
println!("--> left");
println!("{}", left);
println!("--> right");
println!("{}", right);
println!("--")
}
b
}
#[test]
fn comparison_with_template() {
assert!(compare2(&app_example1(), &app_example1().template(EXAMPLE1_TMPL_S)));
assert!(compare2(&app_example1(), &app_example1().template(EXAMPLE1_TMPS_F)));
fn with_template() {
assert!(compare_app_str(&app_example1().template(EXAMPLE1_TMPL_S), SIMPLE_TEMPLATE));
}
#[test]
fn custom_template() {
let app = app_example1().template(EXAMPLE1_TMPS_F);
assert!(compare_app_str(&app, CUSTOM_TEMPL_HELP));
}
#[test]
@ -44,7 +81,7 @@ fn template_empty() {
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.template("");
assert_eq!(build_new_help(&app), "");
assert!(compare_app_str(&app, ""));
}
#[test]
@ -53,8 +90,8 @@ fn template_notag() {
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.template(" no tag ");
assert_eq!(build_new_help(&app), " no tag ");
.template("test no tag test");
assert!(compare_app_str(&app, "test no tag test"));
}
#[test]
@ -63,8 +100,8 @@ fn template_unknowntag() {
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.template(" {unknown_tag} ");
assert_eq!(build_new_help(&app), " {unknown_tag} ");
.template("test {unknown_tag} test");
assert!(compare_app_str(&app, "test {unknown_tag} test"));
}
#[test]
@ -74,7 +111,7 @@ fn template_author_version() {
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.template("{author}\n{version}\n{about}\n{bin}");
assert_eq!(build_new_help(&app), "Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp");
assert!(compare_app_str(&app, "Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp"));
}
fn app_example1<'b, 'c>() -> App<'b, 'c> {
@ -83,8 +120,8 @@ fn app_example1<'b, 'c>() -> App<'b, 'c> {
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.args_from_usage("-c, --config=[FILE] 'Sets a custom config file'
<output> 'Sets an optional output file'
-d... 'Turn debugging information on'")
<output> 'Sets an optional output file'
-d... 'Turn debugging information on'")
.subcommand(SubCommand::with_name("test")
.about("does testing things")
.arg_from_usage("-l, --list 'lists test values'"))