tests: removes extra newline from version output tests

This commit is contained in:
Kevin K 2016-05-30 04:49:13 -04:00
parent a7401dc6a1
commit c5b24c0eb0
3 changed files with 21 additions and 1 deletions

View file

@ -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<_>>());

View file

@ -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<()> {

View file

@ -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);
}