From 4a6ad4e73a5599146e99fd3b91ef1f0fa8e3fb6b Mon Sep 17 00:00:00 2001 From: Kevin K Date: Tue, 8 Sep 2015 22:39:31 -0400 Subject: [PATCH] tests(App Help): tests writing of App help message --- tests/print_help.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/print_help.rs diff --git a/tests/print_help.rs b/tests/print_help.rs new file mode 100644 index 00000000000..367b4db694e --- /dev/null +++ b/tests/print_help.rs @@ -0,0 +1,33 @@ +extern crate clap; + +use clap::App; + +#[test] +fn print_app_help() { + let mut app = App::new("test") + .author("Kevin K.") + .about("tests stuff") + .version("1.3") + .args_from_usage("-f, --flag 'some flag' + --option [opt] 'some option'"); + // We call a get_matches method to cause --help and --version to be built + let _ = app.get_matches_from_safe_borrow(vec![""]); + + // Now we check the output of print_help() + let mut help = vec![]; + app.write_help(&mut help).ok().expect("failed to print help"); + assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\ +Kevin K. +tests stuff + +USAGE: +\ttest [FLAGS] [OPTIONS] + +FLAGS: + -f, --flag some flag + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + --option some option\n")); +}