Skip to content

Commit

Permalink
tests: removes extra newline from version output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed May 31, 2016
1 parent 921f5f7 commit 65b1de6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions clap-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>());
Expand Down
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: Write>(&self, w: &mut W) -> ClapResult<()> {
Expand Down
10 changes: 10 additions & 0 deletions tests/version.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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);
}

0 comments on commit 65b1de6

Please sign in to comment.