Skip to content

Commit 65b1de6

Browse files
committed
tests: removes extra newline from version output tests
1 parent 921f5f7 commit 65b1de6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

clap-test.rs

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ mod test {
6060
assert_eq!(str::from_utf8(&help).unwrap(), out);
6161
}
6262

63+
pub fn check_version(mut a: App, out: &str) {
64+
// We call a get_matches method to cause --help and --version to be built
65+
let _ = a.get_matches_from_safe_borrow(vec![""]);
66+
67+
// Now we check the output of print_version()
68+
let mut ver = vec![];
69+
a.write_version(&mut ver).ok().expect("failed to print help");
70+
assert_eq!(str::from_utf8(&ver).unwrap(), out);
71+
}
72+
6373
pub fn check_complex_output(args: &str, out: &str) {
6474
let mut w = vec![];
6575
let matches = complex_app().get_matches_from(args.split(' ').collect::<Vec<_>>());

src/app/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl<'a, 'b> App<'a, 'b> {
805805
/// use std::io;
806806
/// let mut app = App::new("myprog");
807807
/// let mut out = io::stdout();
808-
/// app.write_vesrion(&mut out).ok().expect("failed to write to stdout");
808+
/// app.write_version(&mut out).ok().expect("failed to write to stdout");
809809
/// ```
810810
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
811811
pub fn write_version<W: Write>(&self, w: &mut W) -> ClapResult<()> {

tests/version.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
extern crate clap;
2+
extern crate regex;
23

34
use clap::{App, ErrorKind};
45

6+
include!("../clap-test.rs");
7+
8+
static VERSION: &'static str = "clap-test v1.4.8";
9+
510
#[test]
611
fn version_short() {
712
let m = App::new("test")
@@ -25,3 +30,8 @@ fn version_long() {
2530
assert!(m.is_err());
2631
assert_eq!(m.unwrap_err().kind, ErrorKind::VersionDisplayed);
2732
}
33+
34+
#[test]
35+
fn complex_version_output() {
36+
test::check_version(test::complex_app(), VERSION);
37+
}

0 commit comments

Comments
 (0)