1 // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
2 // Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
3 // Ana Hobden (@hoverbear) <operator@hoverbear.org>
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 //
11 // This work was derived from Structopt (https://github.com/TeXitoi/structopt)
12 // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
13 // MIT/Apache 2.0 license.
14
15 use crate::utils;
16
17 use clap::Parser;
18
19 #[test]
no_author_version_about()20 fn no_author_version_about() {
21 #[derive(Parser, PartialEq, Debug)]
22 #[command(name = "foo")]
23 #[command(help_template = utils::FULL_TEMPLATE)]
24 struct Opt {}
25
26 let output = utils::get_long_help::<Opt>();
27 assert!(output.starts_with("foo \n\nUsage:"));
28 }
29
30 #[test]
use_env()31 fn use_env() {
32 #[derive(Parser, PartialEq, Debug)]
33 #[command(author, about, version)]
34 #[command(help_template = utils::FULL_TEMPLATE)]
35 struct Opt {}
36
37 let output = utils::get_long_help::<Opt>();
38 assert!(output.starts_with("clap"));
39 assert!(output
40 .contains("A simple to use, efficient, and full-featured Command Line Argument Parser"));
41 }
42
43 #[test]
explicit_version_not_str_lit()44 fn explicit_version_not_str_lit() {
45 const VERSION: &str = "custom version";
46
47 #[derive(Parser)]
48 #[command(version = VERSION)]
49 #[command(help_template = utils::FULL_TEMPLATE)]
50 pub struct Opt {}
51
52 let output = utils::get_long_help::<Opt>();
53 assert!(output.contains("custom version"));
54 }
55