blob: 8bbd47454ac7ad9f5328ae10390441d1fa3a80c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
extern crate clap;
extern crate regex;
use std::str;
use clap::{App, Arg, ErrorKind};
include!("../clap-test.rs");
static VERSION: &'static str = "clap-test v1.4.8";
#[test]
fn version_short() {
let m = App::new("test")
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.get_matches_from_safe(vec!["myprog", "-V"]);
assert!(m.is_err());
assert_eq!(m.unwrap_err().kind, ErrorKind::VersionDisplayed);
}
#[test]
fn version_long() {
let m = App::new("test")
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.get_matches_from_safe(vec!["myprog", "--version"]);
assert!(m.is_err());
assert_eq!(m.unwrap_err().kind, ErrorKind::VersionDisplayed);
}
#[test]
fn complex_version_output() {
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);
}
#[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"));
}
|