mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
tests: removes extra newline from version output tests
This commit is contained in:
parent
a7401dc6a1
commit
c5b24c0eb0
3 changed files with 21 additions and 1 deletions
10
clap-test.rs
10
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::<Vec<_>>());
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue