2016-01-13 17:03:27 +00:00
|
|
|
extern crate clap;
|
2016-05-30 08:49:13 +00:00
|
|
|
extern crate regex;
|
2016-01-13 17:03:27 +00:00
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
use std::str;
|
|
|
|
|
2017-04-04 23:54:20 +00:00
|
|
|
use clap::{App, Arg, ErrorKind};
|
2016-01-13 17:03:27 +00:00
|
|
|
|
2016-05-30 08:49:13 +00:00
|
|
|
include!("../clap-test.rs");
|
|
|
|
|
|
|
|
static VERSION: &'static str = "clap-test v1.4.8";
|
|
|
|
|
2016-01-13 17:03:27 +00:00
|
|
|
#[test]
|
|
|
|
fn version_short() {
|
|
|
|
let m = App::new("test")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
|
|
|
.version("1.3")
|
2016-01-21 05:18:53 +00:00
|
|
|
.get_matches_from_safe(vec!["myprog", "-V"]);
|
2016-01-13 17:03:27 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2016-01-21 05:18:53 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind, ErrorKind::VersionDisplayed);
|
2016-01-13 17:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn version_long() {
|
|
|
|
let m = App::new("test")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
|
|
|
.version("1.3")
|
2016-01-21 05:18:53 +00:00
|
|
|
.get_matches_from_safe(vec!["myprog", "--version"]);
|
2016-01-13 17:03:27 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2016-01-21 05:18:53 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind, ErrorKind::VersionDisplayed);
|
2016-01-13 17:03:27 +00:00
|
|
|
}
|
2016-05-30 08:49:13 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn complex_version_output() {
|
2017-01-03 04:05:23 +00:00
|
|
|
let mut a = App::new("clap-test").version("v1.4.8");
|
|
|
|
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).unwrap();
|
|
|
|
assert_eq!(str::from_utf8(&ver).unwrap(), VERSION);
|
2016-05-30 08:49:13 +00:00
|
|
|
}
|
2017-04-04 23:54:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_ver() {
|
|
|
|
let m = App::new("test")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
|
|
|
.version("1.3")
|
|
|
|
.arg(Arg::from_usage("-v, --version 'some version'"))
|
|
|
|
.get_matches_from_safe(vec!["test", "--version"]);
|
|
|
|
|
|
|
|
assert!(m.is_ok());
|
|
|
|
assert!(m.unwrap().is_present("version"));
|
|
|
|
}
|