From 65b1de6d1f5557e80381595a3733d9a7a2e3b545 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 30 May 2016 04:49:13 -0400 Subject: [PATCH] tests: removes extra newline from version output tests --- clap-test.rs | 10 ++++++++++ src/app/mod.rs | 2 +- tests/version.rs | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clap-test.rs b/clap-test.rs index d2becbe376b..e3425d60842 100644 --- a/clap-test.rs +++ b/clap-test.rs @@ -60,6 +60,16 @@ mod test { assert_eq!(str::from_utf8(&help).unwrap(), out); } + pub fn check_version(mut a: App, out: &str) { + // We call a get_matches method to cause --help and --version to be built + let _ = a.get_matches_from_safe_borrow(vec![""]); + + // Now we check the output of print_version() + let mut ver = vec![]; + a.write_version(&mut ver).ok().expect("failed to print help"); + assert_eq!(str::from_utf8(&ver).unwrap(), out); + } + pub fn check_complex_output(args: &str, out: &str) { let mut w = vec![]; let matches = complex_app().get_matches_from(args.split(' ').collect::>()); diff --git a/src/app/mod.rs b/src/app/mod.rs index 0bc4102a62b..283c87915d9 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -805,7 +805,7 @@ impl<'a, 'b> App<'a, 'b> { /// use std::io; /// let mut app = App::new("myprog"); /// let mut out = io::stdout(); - /// app.write_vesrion(&mut out).ok().expect("failed to write to stdout"); + /// app.write_version(&mut out).ok().expect("failed to write to stdout"); /// ``` /// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html pub fn write_version(&self, w: &mut W) -> ClapResult<()> { diff --git a/tests/version.rs b/tests/version.rs index c5fc91545b0..c51a55ee484 100644 --- a/tests/version.rs +++ b/tests/version.rs @@ -1,7 +1,12 @@ extern crate clap; +extern crate regex; use clap::{App, ErrorKind}; +include!("../clap-test.rs"); + +static VERSION: &'static str = "clap-test v1.4.8"; + #[test] fn version_short() { let m = App::new("test") @@ -25,3 +30,8 @@ fn version_long() { assert!(m.is_err()); assert_eq!(m.unwrap_err().kind, ErrorKind::VersionDisplayed); } + +#[test] +fn complex_version_output() { + test::check_version(test::complex_app(), VERSION); +}