1 use super::utils;
2
3 use clap::{arg, Command};
4
5 #[cfg(not(feature = "unstable-v5"))]
6 static EXAMPLE1_TMPL_S: &str = "{bin} {version}
7 {author}
8 {about}
9
10 Usage: {usage}
11
12 {all-args}";
13
14 #[cfg(feature = "unstable-v5")]
15 static EXAMPLE1_TMPL_S: &str = "{name} {version}
16 {author}
17 {about}
18
19 Usage: {usage}
20
21 {all-args}";
22
23 #[cfg(not(feature = "unstable-v5"))]
24 static EXAMPLE1_TMPS_F: &str = "{bin} {version}
25 {author}
26 {about}
27
28 Usage: {usage}
29
30 Options:
31 {options}
32 Arguments:
33 {positionals}
34 Commands:
35 {subcommands}";
36
37 #[cfg(feature = "unstable-v5")]
38 static EXAMPLE1_TMPS_F: &str = "{name} {version}
39 {author}
40 {about}
41
42 Usage: {usage}
43
44 Options:
45 {options}
46 Arguments:
47 {positionals}
48 Commands:
49 {subcommands}";
50
51 static CUSTOM_TEMPL_HELP: &str = "MyApp 1.0
52 Kevin K. <kbknapp@gmail.com>
53 Does awesome things
54
55 Usage: MyApp [OPTIONS] <output> [COMMAND]
56
57 Options:
58 -c, --config <FILE> Sets a custom config file
59 -d... Turn debugging information on
60 -h, --help Print help
61 -V, --version Print version
62 Arguments:
63 <output> Sets an optional output file
64 Commands:
65 test does testing things
66 help Print this message or the help of the given subcommand(s)
67 ";
68
69 static SIMPLE_TEMPLATE: &str = "MyApp 1.0
70 Kevin K. <kbknapp@gmail.com>
71 Does awesome things
72
73 Usage: MyApp [OPTIONS] <output> [COMMAND]
74
75 Commands:
76 test does testing things
77 help Print this message or the help of the given subcommand(s)
78
79 Arguments:
80 <output> Sets an optional output file
81
82 Options:
83 -c, --config <FILE> Sets a custom config file
84 -d... Turn debugging information on
85 -h, --help Print help
86 -V, --version Print version
87 ";
88
89 #[test]
with_template()90 fn with_template() {
91 let cmd = get_app().help_template(EXAMPLE1_TMPL_S);
92 utils::assert_output(cmd, "MyApp --help", SIMPLE_TEMPLATE, false);
93 }
94
95 #[test]
custom_template()96 fn custom_template() {
97 let cmd = get_app().help_template(EXAMPLE1_TMPS_F);
98 utils::assert_output(cmd, "MyApp --help", CUSTOM_TEMPL_HELP, false);
99 }
100
101 #[test]
template_empty()102 fn template_empty() {
103 let cmd = Command::new("MyApp")
104 .version("1.0")
105 .author("Kevin K. <kbknapp@gmail.com>")
106 .about("Does awesome things")
107 .help_template("");
108 utils::assert_output(cmd, "MyApp --help", "\n", false);
109 }
110
111 #[test]
template_notag()112 fn template_notag() {
113 let cmd = Command::new("MyApp")
114 .version("1.0")
115 .author("Kevin K. <kbknapp@gmail.com>")
116 .about("Does awesome things")
117 .help_template("test no tag test");
118 utils::assert_output(cmd, "MyApp --help", "test no tag test\n", false);
119 }
120
121 #[test]
template_unknowntag()122 fn template_unknowntag() {
123 let cmd = Command::new("MyApp")
124 .version("1.0")
125 .author("Kevin K. <kbknapp@gmail.com>")
126 .about("Does awesome things")
127 .help_template("test {unknown_tag} test");
128 utils::assert_output(cmd, "MyApp --help", "test {unknown_tag} test\n", false);
129 }
130
131 #[test]
template_author_version()132 fn template_author_version() {
133 #[cfg(not(feature = "unstable-v5"))]
134 let cmd = Command::new("MyApp")
135 .version("1.0")
136 .author("Kevin K. <kbknapp@gmail.com>")
137 .about("Does awesome things")
138 .help_template("{author}\n{version}\n{about}\n{bin}");
139
140 #[cfg(feature = "unstable-v5")]
141 let cmd = Command::new("MyApp")
142 .version("1.0")
143 .author("Kevin K. <kbknapp@gmail.com>")
144 .about("Does awesome things")
145 .help_template("{author}\n{version}\n{about}\n{name}");
146
147 utils::assert_output(
148 cmd,
149 "MyApp --help",
150 "Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp\n",
151 false,
152 );
153 }
154
155 // ----------
156
get_app() -> Command157 fn get_app() -> Command {
158 Command::new("MyApp")
159 .version("1.0")
160 .author("Kevin K. <kbknapp@gmail.com>")
161 .about("Does awesome things")
162 .arg(
163 arg!(
164 -c --config <FILE> "Sets a custom config file"
165 )
166 .required(false),
167 )
168 .arg(arg!(
169 <output> "Sets an optional output file"
170 ))
171 .arg(arg!(
172 d: -d ... "Turn debugging information on"
173 ))
174 .subcommand(
175 Command::new("test")
176 .about("does testing things")
177 .arg(arg!(-l --list "lists test values")),
178 )
179 }
180