]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu> |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
6 | // option. This file may not be copied, modified, or distributed | |
7 | // except according to those terms. | |
8 | ||
9 | mod utils; | |
10 | ||
11 | use structopt::StructOpt; | |
12 | use utils::*; | |
13 | ||
14 | #[test] | |
15 | fn no_author_version_about() { | |
16 | #[derive(StructOpt, PartialEq, Debug)] | |
17 | #[structopt(name = "foo", no_version)] | |
18 | struct Opt {} | |
19 | ||
20 | let output = get_long_help::<Opt>(); | |
21 | assert!(output.starts_with("foo \n\nUSAGE:")); | |
22 | } | |
23 | ||
24 | #[test] | |
25 | fn use_env() { | |
26 | #[derive(StructOpt, PartialEq, Debug)] | |
27 | #[structopt(author, about)] | |
28 | struct Opt {} | |
29 | ||
30 | let output = get_long_help::<Opt>(); | |
31 | assert!(output.starts_with("structopt 0.")); | |
32 | assert!(output.contains("Guillaume Pinot <texitoi@texitoi.eu>, others")); | |
33 | assert!(output.contains("Parse command line argument by defining a struct.")); | |
34 | } | |
35 | ||
36 | #[test] | |
37 | fn explicit_version_not_str() { | |
38 | const VERSION: &str = "custom version"; | |
39 | ||
40 | #[derive(StructOpt)] | |
41 | #[structopt(version = VERSION)] | |
42 | pub struct Opt {} | |
43 | ||
44 | let output = get_long_help::<Opt>(); | |
45 | assert!(output.contains("custom version")); | |
46 | } | |
47 | ||
48 | #[test] | |
49 | fn no_version_gets_propagated() { | |
50 | #[derive(StructOpt, PartialEq, Debug)] | |
51 | #[structopt(no_version)] | |
52 | enum Action { | |
53 | Move, | |
54 | } | |
55 | ||
56 | let output = get_subcommand_long_help::<Action>("move"); | |
57 | assert_eq!(output.lines().next(), Some("test-move ")); | |
58 | } |