Line data Source code
1 : // Copyright (c) 2006-2021 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/advgetopt
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 :
20 : // self
21 : //
22 : #include "main.h"
23 :
24 : // advgetopt lib
25 : //
26 : #include <advgetopt/flags.h>
27 : #include <advgetopt/exception.h>
28 :
29 : // snapdev lib
30 : //
31 : #include <snapdev/safe_setenv.h>
32 :
33 : // C++ lib
34 : //
35 : #include <fstream>
36 :
37 :
38 :
39 :
40 :
41 :
42 :
43 6 : CATCH_TEST_CASE("usage_function", "[getopt][usage]")
44 : {
45 8 : std::string tmpdir(SNAP_CATCH2_NAMESPACE::g_tmp_dir);
46 4 : tmpdir += "/.config/home";
47 8 : snap::safe_setenv env("HOME", tmpdir);
48 :
49 8 : CATCH_START_SECTION("usage() using \"--filename\" for the default option accepting multiple entries")
50 : {
51 1 : advgetopt::option const options_list[] =
52 : {
53 : advgetopt::define_option(
54 : advgetopt::Name("validate")
55 : , advgetopt::Flags(advgetopt::standalone_command_flags<advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
56 : , advgetopt::Help("this is used to validate different things.")
57 : ),
58 : advgetopt::define_option(
59 : advgetopt::Name("long")
60 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
61 : , advgetopt::GETOPT_FLAG_REQUIRED>())
62 : , advgetopt::Help("used to validate that invalid numbers generate an error.")
63 : ),
64 : advgetopt::define_option(
65 : advgetopt::Name("out-of-bounds")
66 : , advgetopt::ShortName('o')
67 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
68 : , advgetopt::GETOPT_FLAG_GROUP_OPTIONS
69 : , advgetopt::GETOPT_FLAG_REQUIRED>())
70 : , advgetopt::Help("valid values from 1 to 9.")
71 : ),
72 : advgetopt::define_option(
73 : advgetopt::Name("not-specified-and-no-default")
74 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
75 : , advgetopt::GETOPT_FLAG_REQUIRED
76 : , advgetopt::GETOPT_FLAG_GROUP_OPTIONS
77 : , advgetopt::GETOPT_FLAG_SHOW_GROUP1>())
78 : , advgetopt::Help("test long without having used the option and no default.")
79 : ),
80 : advgetopt::define_option(
81 : advgetopt::Name("not-specified-with-invalid-default")
82 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
83 : , advgetopt::GETOPT_FLAG_REQUIRED
84 : , advgetopt::GETOPT_FLAG_MULTIPLE
85 : , advgetopt::GETOPT_FLAG_SHOW_GROUP2>())
86 : , advgetopt::Help("test that an invalid default value can be returned as is.")
87 : , advgetopt::DefaultValue("123abc")
88 : ),
89 : advgetopt::define_option(
90 : advgetopt::Name("not-specified-string-without-default")
91 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
92 : , advgetopt::GETOPT_FLAG_REQUIRED>())
93 : , advgetopt::Alias("string")
94 : ),
95 : advgetopt::define_option(
96 : advgetopt::Name("string")
97 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
98 : , advgetopt::GETOPT_FLAG_REQUIRED>())
99 : , advgetopt::Help("string parameter.")
100 : ),
101 : advgetopt::define_option(
102 : advgetopt::Name("unique")
103 : , advgetopt::ShortName('u')
104 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
105 : , advgetopt::Help("make sure everything is unique.")
106 : ),
107 : advgetopt::define_option(
108 : advgetopt::Name("noisy")
109 : , advgetopt::ShortName('n')
110 : , advgetopt::Flags(advgetopt::standalone_command_flags<advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR
111 : , advgetopt::GETOPT_FLAG_GROUP_COMMANDS>())
112 : //, advgetopt::Help("make sure everything is unique.") -- do not show in --help
113 : ),
114 : advgetopt::define_option(
115 : advgetopt::Name("quiet")
116 : , advgetopt::ShortName('q')
117 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
118 : , advgetopt::GETOPT_FLAG_MULTIPLE
119 : , advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR
120 : , advgetopt::GETOPT_FLAG_GROUP_COMMANDS>())
121 : , advgetopt::Help("make it quiet (opposite of verbose).")
122 : ),
123 : advgetopt::define_option(
124 : advgetopt::Name("filename")
125 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
126 : , advgetopt::GETOPT_FLAG_MULTIPLE
127 : , advgetopt::GETOPT_FLAG_DEFAULT_OPTION>())
128 : , advgetopt::Help("other parameters are viewed as filenames.")
129 : ),
130 : advgetopt::end_options()
131 : };
132 1 : char const * cargv2[] =
133 : {
134 : "tests/unittests/unittest_advgetopt",
135 : "--validate",
136 : "--long",
137 : "123abc",
138 : "--out-of-bounds",
139 : "123",
140 : "--string",
141 : "string value",
142 : nullptr
143 : };
144 1 : int const argc2 = sizeof(cargv2) / sizeof(cargv2[0]) - 1;
145 1 : char ** argv2 = const_cast<char **>(cargv2);
146 :
147 1 : const char * const configuration_files[] =
148 : {
149 : "advgetopt.conf",
150 : "advgetopt.ini",
151 : "advgetopt.xml",
152 : "advgetopt.yaml",
153 : nullptr
154 : };
155 :
156 1 : const char * const configuration_directories[] =
157 : {
158 : "/etc/sys/advgetopt",
159 : "/etc/advgetopt",
160 : "/etc/advgetopt/advgetopt.d",
161 : "~/.config/advgetopt",
162 : nullptr
163 : };
164 :
165 1 : advgetopt::group_description const groups[] =
166 : {
167 : advgetopt::define_group(
168 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_COMMANDS)
169 : , advgetopt::GroupName("verbosity")
170 : , advgetopt::GroupDescription("Verbosity options:")
171 : ),
172 : advgetopt::define_group(
173 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_OPTIONS)
174 : , advgetopt::GroupName("option")
175 : , advgetopt::GroupDescription("Special options:")
176 : ),
177 : advgetopt::end_groups()
178 : };
179 :
180 1 : advgetopt::options_environment options;
181 1 : options.f_project_name = "unittest";
182 1 : options.f_group_name = "grouptest";
183 1 : options.f_options = options_list;
184 1 : options.f_options_files_directory = "/etc/advgetopt";
185 1 : options.f_configuration_files = configuration_files;
186 1 : options.f_configuration_filename = "advgetopt.conf";
187 1 : options.f_configuration_directories = configuration_directories;
188 1 : options.f_help_header = "Usage: try this one and we get a throw (valid options + usage calls)";
189 1 : options.f_help_footer = "And this is the footer where we can include many parameters:\n"
190 : " . Percent = [%%]\n"
191 : " . Project Name = [%a]\n"
192 : " . Build Date = [%b]\n"
193 : " . Copyright = [%c]\n"
194 : " . Directories = [%d]\n"
195 : " . All Directories = [%*d]\n"
196 : " . Environment Variable = [%e]\n"
197 : " . Environment Variable and Value = [%*e]\n"
198 : " . Configuration Files = [%f]\n"
199 : " . All Configuration Files = [%*f]\n"
200 : " . All Existing Configuration Files = [%g]\n"
201 : " . All Possible Configuration Files = [%*g]\n"
202 : " . Option File Directory = [%i]\n"
203 : " . License = [%l]\n"
204 : " . Output File [%o]\n"
205 : " . Program Name = [%p]\n"
206 : " . Program Fullname = [%*p]\n"
207 : " . Group Name = [%s]\n"
208 : " . Build Time = [%t]\n"
209 : " . Version = [%v]\n"
210 : " . Existing Writable Configuration Files = [%w]\n"
211 : ;
212 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
213 1 : options.f_version = "2.0.1";
214 1 : options.f_license = "MIT";
215 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved";
216 1 : options.f_build_date = "Jun 4 2019";
217 1 : options.f_build_time = "23:02:36";
218 1 : options.f_groups = groups;
219 :
220 : // this initialization works as expected
221 : //
222 2 : advgetopt::getopt opt(options, argc2, argv2);
223 :
224 1 : CATCH_REQUIRE(opt.get_group_name() == "grouptest");
225 :
226 : {
227 1 : advgetopt::group_description const * verbosity_group(opt.find_group(advgetopt::GETOPT_FLAG_GROUP_COMMANDS));
228 1 : CATCH_REQUIRE(verbosity_group != nullptr);
229 1 : CATCH_REQUIRE(verbosity_group->f_group == advgetopt::GETOPT_FLAG_GROUP_COMMANDS);
230 1 : CATCH_REQUIRE(verbosity_group->f_name == std::string("verbosity"));
231 1 : CATCH_REQUIRE(verbosity_group->f_description == std::string("Verbosity options:"));
232 : }
233 :
234 : {
235 1 : advgetopt::group_description const * option_group(opt.find_group(advgetopt::GETOPT_FLAG_GROUP_OPTIONS));
236 1 : CATCH_REQUIRE(option_group != nullptr);
237 1 : CATCH_REQUIRE(option_group->f_group == advgetopt::GETOPT_FLAG_GROUP_OPTIONS);
238 1 : CATCH_REQUIRE(option_group->f_name == std::string("option"));
239 1 : CATCH_REQUIRE(option_group->f_description == std::string("Special options:"));
240 : }
241 :
242 : {
243 1 : advgetopt::group_description const * group_seven(opt.find_group(advgetopt::GETOPT_FLAG_GROUP_SEVEN));
244 1 : CATCH_REQUIRE(group_seven == nullptr);
245 : }
246 :
247 1 : std::string const footer(advgetopt::getopt::breakup_line(
248 : "\n"
249 : "And this is the footer where we can include many parameters:\n"
250 : " . Percent = [%]\n"
251 : " . Project Name = [unittest]\n"
252 : " . Build Date = [Jun 4 2019]\n"
253 : " . Copyright = [Copyright (c) 2019 Made to Order Software Corp. -- All Rights "
254 : "Reserved]\n"
255 : " . Directories = [/etc/sys/advgetopt]\n"
256 : " . All Directories = [/etc/sys/advgetopt, /etc/advgetopt, "
257 : "/etc/advgetopt/advgetopt.d, ~/.config/advgetopt]\n"
258 : " . Environment Variable = [ADVGETOPT_TEST_OPTIONS]\n"
259 : " . Environment Variable and Value = [ADVGETOPT_TEST_OPTIONS (not set)]\n"
260 : " . Configuration Files = [advgetopt.conf]\n"
261 : " . All Configuration Files = [advgetopt.conf, advgetopt.ini, advgetopt.xml, "
262 : "advgetopt.yaml]\n"
263 : " . All Existing Configuration Files = []\n"
264 : " . All Possible Configuration Files = [advgetopt.conf, "
265 : "grouptest.d/50-advgetopt.conf, advgetopt.ini, grouptest.d/50-advgetopt.ini, "
266 : "advgetopt.xml, grouptest.d/50-advgetopt.xml, advgetopt.yaml, "
267 : "grouptest.d/50-advgetopt.yaml, /etc/sys/advgetopt/advgetopt.conf, "
268 : "/etc/sys/advgetopt/grouptest.d/50-advgetopt.conf, /etc/advgetopt/advgetopt.conf, "
269 : "/etc/advgetopt/grouptest.d/50-advgetopt.conf, "
270 : "/etc/advgetopt/advgetopt.d/advgetopt.conf, "
271 : "/etc/advgetopt/advgetopt.d/grouptest.d/50-advgetopt.conf, "
272 2 : + tmpdir + "/.config/advgetopt/advgetopt.conf]\n"
273 : " . Option File Directory = [/etc/advgetopt/]\n"
274 : " . License = [MIT]\n"
275 3 : " . Output File [" + tmpdir + "/.config/advgetopt/advgetopt.conf]\n"
276 : " . Program Name = [unittest_advgetopt]\n"
277 : " . Program Fullname = [tests/unittests/unittest_advgetopt]\n"
278 : " . Group Name = [grouptest]\n"
279 : " . Build Time = [23:02:36]\n"
280 : " . Version = [2.0.1]\n"
281 : " . Existing Writable Configuration Files = []\n"
282 3 : "", 0, advgetopt::getopt::get_line_width()));
283 :
284 : // test a standard "--help" type of option
285 : //
286 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
287 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
288 : advgetopt::getopt::breakup_line(
289 : "Usage: try this one and we get a throw (valid options + usage calls)"
290 : , 0
291 : , advgetopt::getopt::get_line_width())
292 : + advgetopt::getopt::format_usage_string(
293 : "--long <arg>"
294 : , "used to validate that invalid numbers generate an error."
295 : , 30
296 : , advgetopt::getopt::get_line_width())
297 : + advgetopt::getopt::format_usage_string(
298 : "--string <arg>"
299 : , "string parameter."
300 : , 30
301 : , advgetopt::getopt::get_line_width())
302 : + advgetopt::getopt::format_usage_string(
303 : "--unique or -u"
304 : , "make sure everything is unique."
305 : , 30
306 : , advgetopt::getopt::get_line_width())
307 : + advgetopt::getopt::format_usage_string(
308 : "--validate"
309 : , "this is used to validate different things."
310 : , 30
311 : , advgetopt::getopt::get_line_width())
312 : + "\n"
313 : "Verbosity options:\n"
314 : + advgetopt::getopt::format_usage_string(
315 : "--long-help or -?"
316 : , "show all the help from all the available options."
317 : , 30
318 : , advgetopt::getopt::get_line_width())
319 : + advgetopt::getopt::format_usage_string(
320 : "--option-help"
321 : , "show help from the \"option\" group of options."
322 : , 30
323 : , advgetopt::getopt::get_line_width())
324 : + advgetopt::getopt::format_usage_string(
325 : "--quiet or -q {<arg>}"
326 : , "make it quiet (opposite of verbose)."
327 : , 30
328 : , advgetopt::getopt::get_line_width())
329 : + advgetopt::getopt::format_usage_string(
330 : "--verbosity-help"
331 : , "show help from the \"verbosity\" group of options."
332 : , 30
333 : , advgetopt::getopt::get_line_width())
334 : + "\n"
335 : "Special options:\n"
336 : + advgetopt::getopt::format_usage_string(
337 : "--out-of-bounds or -o <arg>"
338 : , "valid values from 1 to 9."
339 : , 30
340 : , advgetopt::getopt::get_line_width())
341 : + advgetopt::getopt::format_usage_string(
342 : "[default arguments]"
343 : , "other parameters are viewed as filenames."
344 : , 30
345 : , advgetopt::getopt::get_line_width())
346 : + footer
347 : );
348 :
349 : // test a "--help-all" type of option
350 : //
351 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_ALL),
352 : advgetopt::getopt::breakup_line(
353 : "Usage: try this one and we get a throw (valid options + usage calls)"
354 : , 0
355 : , advgetopt::getopt::get_line_width())
356 : + advgetopt::getopt::format_usage_string(
357 : "--long <arg>"
358 : , "used to validate that invalid numbers generate an error."
359 : , 30
360 : , advgetopt::getopt::get_line_width())
361 : + advgetopt::getopt::format_usage_string(
362 : "--not-specified-with-invalid-default <arg> {<arg>}"
363 : " (default is \"123abc\")"
364 : , "test that an invalid default value can be returned as is."
365 : , 30
366 : , advgetopt::getopt::get_line_width())
367 : + advgetopt::getopt::format_usage_string(
368 : "--string <arg>"
369 : , "string parameter."
370 : , 30
371 : , advgetopt::getopt::get_line_width())
372 : + advgetopt::getopt::format_usage_string(
373 : "--unique or -u"
374 : , "make sure everything is unique."
375 : , 30
376 : , advgetopt::getopt::get_line_width())
377 : + advgetopt::getopt::format_usage_string(
378 : "--validate"
379 : , "this is used to validate different things."
380 : , 30
381 : , advgetopt::getopt::get_line_width())
382 : + "\n"
383 : "Verbosity options:\n"
384 : + advgetopt::getopt::format_usage_string(
385 : "--long-help or -?"
386 : , "show all the help from all the available options."
387 : , 30
388 : , advgetopt::getopt::get_line_width())
389 : + advgetopt::getopt::format_usage_string(
390 : "--option-help"
391 : , "show help from the \"option\" group of options."
392 : , 30
393 : , advgetopt::getopt::get_line_width())
394 : + advgetopt::getopt::format_usage_string(
395 : "--quiet or -q {<arg>}"
396 : , "make it quiet (opposite of verbose)."
397 : , 30
398 : , advgetopt::getopt::get_line_width())
399 : + advgetopt::getopt::format_usage_string(
400 : "--verbosity-help"
401 : , "show help from the \"verbosity\" group of options."
402 : , 30
403 : , advgetopt::getopt::get_line_width())
404 : + "\n"
405 : "Special options:\n"
406 : + advgetopt::getopt::format_usage_string(
407 : "--not-specified-and-no-default <arg>"
408 : , "test long without having used the option and no default."
409 : , 30
410 : , advgetopt::getopt::get_line_width())
411 : + advgetopt::getopt::format_usage_string(
412 : "--out-of-bounds or -o <arg>"
413 : , "valid values from 1 to 9."
414 : , 30
415 : , advgetopt::getopt::get_line_width())
416 : + advgetopt::getopt::format_usage_string(
417 : "[default arguments]"
418 : , "other parameters are viewed as filenames."
419 : , 30
420 : , advgetopt::getopt::get_line_width())
421 : + footer
422 : );
423 :
424 : // pretend an error occurred
425 : //
426 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR),
427 : advgetopt::getopt::breakup_line(
428 : "Usage: try this one and we get a throw (valid options + usage calls)"
429 : , 0
430 : , advgetopt::getopt::get_line_width())
431 : + advgetopt::getopt::format_usage_string(
432 : "--validate"
433 : , "this is used to validate different things."
434 : , 30
435 : , advgetopt::getopt::get_line_width())
436 : + "\n"
437 : "Verbosity options:\n"
438 : + advgetopt::getopt::format_usage_string(
439 : "--quiet or -q {<arg>}"
440 : , "make it quiet (opposite of verbose)."
441 : , 30
442 : , advgetopt::getopt::get_line_width())
443 : + footer
444 : );
445 :
446 : // show GROUP1
447 : //
448 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_GROUP1),
449 : advgetopt::getopt::breakup_line(
450 : "Usage: try this one and we get a throw (valid options + usage calls)"
451 : , 0
452 : , advgetopt::getopt::get_line_width())
453 : + "\n"
454 : "Special options:\n"
455 : + advgetopt::getopt::format_usage_string(
456 : "--not-specified-and-no-default <arg>"
457 : , "test long without having used the option and no default."
458 : , 30
459 : , advgetopt::getopt::get_line_width())
460 : + footer
461 : );
462 :
463 : // show GROUP2
464 : //
465 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_GROUP2),
466 : advgetopt::getopt::breakup_line(
467 : "Usage: try this one and we get a throw (valid options + usage calls)"
468 : , 0
469 : , advgetopt::getopt::get_line_width())
470 : + advgetopt::getopt::format_usage_string(
471 : "--not-specified-with-invalid-default <arg> {<arg>} (default is \"123abc\")"
472 : , "test that an invalid default value can be returned as is."
473 : , 30
474 : , advgetopt::getopt::get_line_width())
475 : + footer
476 : );
477 : }
478 : CATCH_END_SECTION()
479 :
480 8 : CATCH_START_SECTION("usage() using \"--filename\" for the default option accepting multiple entries which are required when \"--filename\" is used")
481 : {
482 1 : const advgetopt::option options_list[] =
483 : {
484 : advgetopt::define_option(
485 : advgetopt::Name("validate")
486 : , advgetopt::Flags(advgetopt::standalone_command_flags<advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
487 : , advgetopt::Help("this is used to validate different things.")
488 : ),
489 : advgetopt::define_option(
490 : advgetopt::Name("long")
491 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
492 : , advgetopt::Help("used to validate that invalid numbers generate an error.")
493 : ),
494 : advgetopt::define_option(
495 : advgetopt::Name("out-of-bounds")
496 : , advgetopt::ShortName('o')
497 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
498 : , advgetopt::Help("valid values from 1 to 9.")
499 : ),
500 : advgetopt::define_option(
501 : advgetopt::Name("not-specified-and-no-default")
502 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED, advgetopt::GETOPT_FLAG_SHOW_GROUP1>())
503 : , advgetopt::Help("test long without having used the option and no default.")
504 : ),
505 : advgetopt::define_option(
506 : advgetopt::Name("not-specified-with-invalid-default")
507 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED, advgetopt::GETOPT_FLAG_MULTIPLE, advgetopt::GETOPT_FLAG_SHOW_GROUP2>())
508 : , advgetopt::Help("test that an invalid default value can be returned as is.")
509 : , advgetopt::DefaultValue("123abc")
510 : ),
511 : advgetopt::define_option(
512 : advgetopt::Name("not-specified-string-without-default")
513 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
514 : , advgetopt::Alias("string")
515 : ),
516 : advgetopt::define_option(
517 : advgetopt::Name("string")
518 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
519 : , advgetopt::Help("string parameter.")
520 : ),
521 : advgetopt::define_option(
522 : advgetopt::Name("unique")
523 : , advgetopt::ShortName('u')
524 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
525 : , advgetopt::Help("make sure everything is unique.")
526 : ),
527 : advgetopt::define_option(
528 : advgetopt::Name("noisy")
529 : , advgetopt::ShortName('n')
530 : , advgetopt::Flags(advgetopt::standalone_command_flags<advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
531 : //, advgetopt::Help("make sure everything is unique.") -- do not show in --help
532 : ),
533 : advgetopt::define_option(
534 : advgetopt::Name("quiet")
535 : , advgetopt::ShortName('q')
536 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_MULTIPLE, advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
537 : , advgetopt::Help("make it quiet (opposite of verbose).")
538 : ),
539 : advgetopt::define_option(
540 : advgetopt::Name("filename")
541 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED, advgetopt::GETOPT_FLAG_MULTIPLE, advgetopt::GETOPT_FLAG_DEFAULT_OPTION>())
542 : , advgetopt::Help("other parameters are viewed as filenames.")
543 : ),
544 : advgetopt::end_options()
545 : };
546 1 : char const * cargv2[] =
547 : {
548 : "tests/unittests/unittest_advgetopt",
549 : "--validate",
550 : "--long",
551 : "123abc",
552 : "--out-of-bounds",
553 : "123",
554 : "--string",
555 : "string value",
556 : nullptr
557 : };
558 1 : int const argc2 = sizeof(cargv2) / sizeof(cargv2[0]) - 1;
559 1 : char ** argv2 = const_cast<char **>(cargv2);
560 :
561 1 : const char * const configuration_files[] =
562 : {
563 : "advgetopt.conf",
564 : "advgetopt.ini",
565 : "advgetopt.xml",
566 : "advgetopt.yaml",
567 : nullptr
568 : };
569 :
570 1 : const char * const configuration_directories[] =
571 : {
572 : "/etc/sys/advgetopt",
573 : "/etc/advgetopt",
574 : "/etc/advgetopt/advgetopt.d",
575 : "~/.config/advgetopt",
576 : nullptr
577 : };
578 :
579 1 : advgetopt::options_environment options;
580 1 : options.f_project_name = "unittest";
581 1 : options.f_options = options_list;
582 1 : options.f_options_files_directory = "/usr/share/advgetopt";
583 1 : options.f_configuration_files = configuration_files;
584 1 : options.f_configuration_filename = "advgetopt.conf";
585 1 : options.f_configuration_directories = configuration_directories;
586 1 : options.f_help_header = "Usage: try this one and we get a throw (valid options + usage calls)";
587 1 : options.f_help_footer = "And this is the footer where we can include many parameters:\n"
588 : " . Percent = [%%]\n"
589 : " . Project Name = [%a]\n"
590 : " . Build Date = [%b]\n"
591 : " . Copyright = [%c]\n"
592 : " . Directories = [%d]\n"
593 : " . All Directories = [%*d]\n"
594 : " . Environment Variable = [%e]\n"
595 : " . Environment Variable and Value = [%*e]\n"
596 : " . Configuration Files = [%f]\n"
597 : " . All Configuration Files = [%*f]\n"
598 : " . All Existing Configuration Files = [%g]\n"
599 : " . All Possible Configuration Files = [%*g]\n"
600 : " . Option File Directory = [%i]\n"
601 : " . License = [%l]\n"
602 : " . Output File [%o]\n"
603 : " . Program Name = [%p]\n"
604 : " . Program Fullname = [%*p]\n"
605 : " . Build Time = [%t]\n"
606 : " . Version = [%v]\n"
607 : " . Existing Writable Configuration Files = [%w]\n"
608 : ;
609 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
610 1 : options.f_version = "2.0.1";
611 1 : options.f_license = "MIT";
612 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved";
613 1 : options.f_build_date = "Jun 4 2019";
614 1 : options.f_build_time = "23:02:36";
615 :
616 : // this initialization works as expected
617 : //
618 2 : advgetopt::getopt opt(options, argc2, argv2);
619 :
620 1 : CATCH_REQUIRE(opt.find_group(advgetopt::GETOPT_FLAG_GROUP_COMMANDS) == nullptr);
621 1 : CATCH_REQUIRE(opt.find_group(advgetopt::GETOPT_FLAG_GROUP_OPTIONS) == nullptr);
622 :
623 1 : std::string const footer(advgetopt::getopt::breakup_line(
624 : "\n"
625 : "And this is the footer where we can include many parameters:\n"
626 : " . Percent = [%]\n"
627 : " . Project Name = [unittest]\n"
628 : " . Build Date = [Jun 4 2019]\n"
629 : " . Copyright = [Copyright (c) 2019 Made to Order Software Corp. -- All Rights "
630 : "Reserved]\n"
631 : " . Directories = [/etc/sys/advgetopt]\n"
632 : " . All Directories = [/etc/sys/advgetopt, /etc/advgetopt, "
633 : "/etc/advgetopt/advgetopt.d, ~/.config/advgetopt]\n"
634 : " . Environment Variable = [ADVGETOPT_TEST_OPTIONS]\n"
635 : " . Environment Variable and Value = [ADVGETOPT_TEST_OPTIONS (not set)]\n"
636 : " . Configuration Files = [advgetopt.conf]\n"
637 : " . All Configuration Files = [advgetopt.conf, advgetopt.ini, advgetopt.xml, "
638 : "advgetopt.yaml]\n"
639 : " . All Existing Configuration Files = []\n"
640 : " . All Possible Configuration Files = [advgetopt.conf, "
641 : "unittest.d/50-advgetopt.conf, advgetopt.ini, unittest.d/50-advgetopt.ini, "
642 : "advgetopt.xml, unittest.d/50-advgetopt.xml, advgetopt.yaml, "
643 : "unittest.d/50-advgetopt.yaml, /etc/sys/advgetopt/advgetopt.conf, "
644 : "/etc/sys/advgetopt/unittest.d/50-advgetopt.conf, /etc/advgetopt/advgetopt.conf, "
645 : "/etc/advgetopt/unittest.d/50-advgetopt.conf, "
646 : "/etc/advgetopt/advgetopt.d/advgetopt.conf, "
647 : "/etc/advgetopt/advgetopt.d/unittest.d/50-advgetopt.conf, "
648 2 : + tmpdir + "/.config/advgetopt/advgetopt.conf]\n"
649 : " . Option File Directory = [/usr/share/advgetopt/]\n"
650 : " . License = [MIT]\n"
651 3 : " . Output File [" + tmpdir + "/.config/advgetopt/advgetopt.conf]\n"
652 : " . Program Name = [unittest_advgetopt]\n"
653 : " . Program Fullname = [tests/unittests/unittest_advgetopt]\n"
654 : " . Build Time = [23:02:36]\n"
655 : " . Version = [2.0.1]\n"
656 : " . Existing Writable Configuration Files = []\n"
657 3 : , 0, advgetopt::getopt::get_line_width()));
658 :
659 : // test a standard "--help" type of option
660 : //
661 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
662 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
663 : advgetopt::getopt::breakup_line(
664 : "Usage: try this one and we get a throw (valid options + usage calls)"
665 : , 0
666 : , advgetopt::getopt::get_line_width())
667 : + advgetopt::getopt::format_usage_string(
668 : "--long <arg>"
669 : , "used to validate that invalid numbers generate an error."
670 : , 30
671 : , advgetopt::getopt::get_line_width())
672 : + advgetopt::getopt::format_usage_string(
673 : "--long-help or -?"
674 : , "show all the help from all the available options."
675 : , 30
676 : , advgetopt::getopt::get_line_width())
677 : + advgetopt::getopt::format_usage_string(
678 : "--out-of-bounds or -o <arg>"
679 : , "valid values from 1 to 9."
680 : , 30
681 : , advgetopt::getopt::get_line_width())
682 : + advgetopt::getopt::format_usage_string(
683 : "--quiet or -q {<arg>}"
684 : , "make it quiet (opposite of verbose)."
685 : , 30
686 : , advgetopt::getopt::get_line_width())
687 : + advgetopt::getopt::format_usage_string(
688 : "--string <arg>"
689 : , "string parameter."
690 : , 30
691 : , advgetopt::getopt::get_line_width())
692 : + advgetopt::getopt::format_usage_string(
693 : "--unique or -u"
694 : , "make sure everything is unique."
695 : , 30
696 : , advgetopt::getopt::get_line_width())
697 : + advgetopt::getopt::format_usage_string(
698 : "--validate"
699 : , "this is used to validate different things."
700 : , 30
701 : , advgetopt::getopt::get_line_width())
702 : + advgetopt::getopt::format_usage_string(
703 : "<default arguments>"
704 : , "other parameters are viewed as filenames."
705 : , 30
706 : , advgetopt::getopt::get_line_width())
707 : + footer
708 : );
709 :
710 : // test a "--help-all" type of option
711 : //
712 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_ALL),
713 : advgetopt::getopt::breakup_line(
714 : "Usage: try this one and we get a throw (valid options + usage calls)"
715 : , 0
716 : , advgetopt::getopt::get_line_width())
717 : + advgetopt::getopt::format_usage_string(
718 : "--long <arg>"
719 : , "used to validate that invalid numbers generate an error."
720 : , 30
721 : , advgetopt::getopt::get_line_width())
722 : + advgetopt::getopt::format_usage_string(
723 : "--long-help or -?"
724 : , "show all the help from all the available options."
725 : , 30
726 : , advgetopt::getopt::get_line_width())
727 : + advgetopt::getopt::format_usage_string(
728 : "--not-specified-and-no-default <arg>"
729 : , "test long without having used the option and no default."
730 : , 30
731 : , advgetopt::getopt::get_line_width())
732 : + advgetopt::getopt::format_usage_string(
733 : "--not-specified-with-invalid-default <arg> {<arg>} (default is \"123abc\")"
734 : , "test that an invalid default value can be returned as is."
735 : , 30
736 : , advgetopt::getopt::get_line_width())
737 : + advgetopt::getopt::format_usage_string(
738 : "--out-of-bounds or -o <arg>"
739 : , "valid values from 1 to 9."
740 : , 30
741 : , advgetopt::getopt::get_line_width())
742 : + advgetopt::getopt::format_usage_string(
743 : "--quiet or -q {<arg>}"
744 : , "make it quiet (opposite of verbose)."
745 : , 30
746 : , advgetopt::getopt::get_line_width())
747 : + advgetopt::getopt::format_usage_string(
748 : "--string <arg>"
749 : , "string parameter."
750 : , 30
751 : , advgetopt::getopt::get_line_width())
752 : + advgetopt::getopt::format_usage_string(
753 : "--unique or -u"
754 : , "make sure everything is unique."
755 : , 30
756 : , advgetopt::getopt::get_line_width())
757 : + advgetopt::getopt::format_usage_string(
758 : "--validate"
759 : , "this is used to validate different things."
760 : , 30
761 : , advgetopt::getopt::get_line_width())
762 : + advgetopt::getopt::format_usage_string(
763 : "<default arguments>"
764 : , "other parameters are viewed as filenames."
765 : , 30
766 : , advgetopt::getopt::get_line_width())
767 : + footer
768 : );
769 :
770 : // pretend an error occurred
771 : //
772 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR),
773 : "Usage: try this one and we get a throw (valid options + usage calls)\n"
774 : " --quiet or -q {<arg>} make it quiet (opposite of verbose).\n"
775 : " --validate this is used to validate different things.\n"
776 : + footer
777 : );
778 :
779 : // show GROUP1
780 : //
781 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_GROUP1),
782 : advgetopt::getopt::breakup_line(
783 : "Usage: try this one and we get a throw (valid options + usage calls)"
784 : , 0
785 : , advgetopt::getopt::get_line_width())
786 : + advgetopt::getopt::format_usage_string(
787 : "--not-specified-and-no-default <arg>"
788 : , "test long without having used the option and no default."
789 : , 30
790 : , advgetopt::getopt::get_line_width())
791 : + footer
792 : );
793 :
794 : // show GROUP2
795 : //
796 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_GROUP2),
797 : advgetopt::getopt::breakup_line(
798 : "Usage: try this one and we get a throw (valid options + usage calls)"
799 : , 0
800 : , advgetopt::getopt::get_line_width())
801 : + advgetopt::getopt::format_usage_string(
802 : "--not-specified-with-invalid-default <arg> {<arg>} (default is \"123abc\")"
803 : , "test that an invalid default value can be returned as is."
804 : , 30
805 : , advgetopt::getopt::get_line_width())
806 : + footer
807 : );
808 : }
809 : CATCH_END_SECTION()
810 :
811 8 : CATCH_START_SECTION("usage() using \"--filename\" for the default option accepting one required item")
812 : {
813 : // valid initialization + usage calls with a few different options
814 1 : const advgetopt::option options_list[] =
815 : {
816 : advgetopt::define_option(
817 : advgetopt::Name("validate")
818 : , advgetopt::Flags(advgetopt::standalone_command_flags<advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
819 : , advgetopt::Help("this is used to validate different things.")
820 : ),
821 : advgetopt::define_option(
822 : advgetopt::Name("long")
823 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_REQUIRED>())
824 : , advgetopt::Help("used to validate that invalid numbers generate an error.")
825 : ),
826 : advgetopt::define_option(
827 : advgetopt::Name("out-of-bounds")
828 : , advgetopt::ShortName('o')
829 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
830 : , advgetopt::Help("valid values from 1 to 9.")
831 : ),
832 : advgetopt::define_option(
833 : advgetopt::Name("not-specified-and-no-default")
834 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED, advgetopt::GETOPT_FLAG_SHOW_GROUP1>())
835 : , advgetopt::Help("test long without having used the option and no default.")
836 : ),
837 : advgetopt::define_option(
838 : advgetopt::Name("not-specified-with-invalid-default")
839 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED, advgetopt::GETOPT_FLAG_MULTIPLE, advgetopt::GETOPT_FLAG_SHOW_GROUP2>())
840 : , advgetopt::Help("test that an invalid default value can be returned as is.")
841 : , advgetopt::DefaultValue("123abc")
842 : ),
843 : advgetopt::define_option(
844 : advgetopt::Name("not-specified-string-without-default")
845 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
846 : , advgetopt::Alias("string")
847 : ),
848 : advgetopt::define_option(
849 : advgetopt::Name("string")
850 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED>())
851 : , advgetopt::Help("string parameter.")
852 : ),
853 : advgetopt::define_option(
854 : advgetopt::Name("unique")
855 : , advgetopt::ShortName('u')
856 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
857 : , advgetopt::Help("make sure everything is unique.")
858 : ),
859 : advgetopt::define_option(
860 : advgetopt::Name("quiet")
861 : , advgetopt::ShortName('q')
862 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_MULTIPLE, advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
863 : , advgetopt::Help("make it quiet (opposite of verbose).")
864 : ),
865 : advgetopt::define_option(
866 : advgetopt::Name("not-in-v2-though")
867 : , advgetopt::ShortName('l')
868 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE, advgetopt::GETOPT_FLAG_REQUIRED, advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
869 : , advgetopt::Help("long with just a letter.")
870 : ),
871 : advgetopt::define_option(
872 : advgetopt::Name("filename")
873 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_DEFAULT_OPTION, advgetopt::GETOPT_FLAG_REQUIRED>())
874 : , advgetopt::Help("other parameters are viewed as filenames; and we need at least one option with a very long help to check that it wraps perfectly (we'd really need to get the output of the command and check that against what is expected because at this time the test is rather blind in that respect! FIXED IN v2!)")
875 : ),
876 : advgetopt::end_options()
877 : };
878 :
879 1 : advgetopt::options_environment options;
880 1 : options.f_project_name = "unittest";
881 1 : options.f_options = options_list;
882 1 : options.f_help_header = "Usage: try this one and we get a throw (valid options + usage calls bis)";
883 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
884 :
885 1 : char const * cargv2[] =
886 : {
887 : "tests/unittests/unittest_advgetopt",
888 : "--validate",
889 : "--long",
890 : "123abc",
891 : "--out-of-bounds",
892 : "123",
893 : "--string",
894 : "string value",
895 : nullptr
896 : };
897 1 : int const argc2 = sizeof(cargv2) / sizeof(cargv2[0]) - 1;
898 1 : char ** argv2 = const_cast<char **>(cargv2);
899 :
900 : // this initialization works as expected
901 2 : advgetopt::getopt opt(options, argc2, argv2);
902 :
903 : // all of the following have the exiting exception
904 : // for(int i(static_cast<int>(advgetopt::getopt::status_t::no_error)); i <= static_cast<int>(advgetopt::getopt::status_t::fatal); ++i)
905 : // {
906 : // CATCH_REQUIRE_THROWS_AS(opt.usage(static_cast<advgetopt::getopt::status_t>(i), "test no error, warnings, errors..."), advgetopt::getopt_exit);
907 : // }
908 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_ALL),
909 : advgetopt::getopt::breakup_line(
910 : "Usage: try this one and we get a throw (valid options + usage calls bis)"
911 : , 0
912 : , advgetopt::getopt::get_line_width())
913 : + advgetopt::getopt::format_usage_string(
914 : "--long <arg>"
915 : , "used to validate that invalid numbers generate an error."
916 : , 30
917 : , advgetopt::getopt::get_line_width())
918 : + advgetopt::getopt::format_usage_string(
919 : "--long-help or -?"
920 : , "show all the help from all the available options."
921 : , 30
922 : , advgetopt::getopt::get_line_width())
923 : + advgetopt::getopt::format_usage_string(
924 : "--not-in-v2-though or -l <arg>"
925 : , "long with just a letter."
926 : , 30
927 : , advgetopt::getopt::get_line_width())
928 : + advgetopt::getopt::format_usage_string(
929 : "--not-specified-and-no-default <arg>"
930 : , "test long without having used the option and no default."
931 : , 30
932 : , advgetopt::getopt::get_line_width())
933 : + advgetopt::getopt::format_usage_string(
934 : "--not-specified-with-invalid-default <arg> {<arg>} (default is \"123abc\")"
935 : , "test that an invalid default value can be returned as is."
936 : , 30
937 : , advgetopt::getopt::get_line_width())
938 : + advgetopt::getopt::format_usage_string(
939 : "--out-of-bounds or -o <arg>"
940 : , "valid values from 1 to 9."
941 : , 30
942 : , advgetopt::getopt::get_line_width())
943 : + advgetopt::getopt::format_usage_string(
944 : "--quiet or -q {<arg>}"
945 : , "make it quiet (opposite of verbose)."
946 : , 30
947 : , advgetopt::getopt::get_line_width())
948 : + advgetopt::getopt::format_usage_string(
949 : "--string <arg>"
950 : , "string parameter."
951 : , 30
952 : , advgetopt::getopt::get_line_width())
953 : + advgetopt::getopt::format_usage_string(
954 : "--unique or -u"
955 : , "make sure everything is unique."
956 : , 30
957 : , advgetopt::getopt::get_line_width())
958 : + advgetopt::getopt::format_usage_string(
959 : "--validate"
960 : , "this is used to validate different things."
961 : , 30
962 : , advgetopt::getopt::get_line_width())
963 : + advgetopt::getopt::format_usage_string(
964 : "<default argument>"
965 : , "other parameters are viewed as filenames; and we"
966 : " need at least one option with a very long help to"
967 : " check that it wraps perfectly (we'd really need to"
968 : " get the output of the command and check that"
969 : " against what is expected because at this time the"
970 : " test is rather blind in that respect! FIXED IN"
971 : " v2!)"
972 : , 30
973 : , advgetopt::getopt::get_line_width())
974 : );
975 : }
976 : CATCH_END_SECTION()
977 :
978 8 : CATCH_START_SECTION("usage() using \"--\" for the default option accepting one item")
979 : {
980 : // valid initialization + usage calls with a few different options
981 1 : const advgetopt::option options_list[] =
982 : {
983 : advgetopt::define_option(
984 : advgetopt::Name("validate")
985 : , advgetopt::Flags(advgetopt::standalone_command_flags<advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
986 : , advgetopt::Help("this is used to validate different things.")
987 : ),
988 : advgetopt::define_option(
989 : advgetopt::Name("long")
990 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_REQUIRED>())
991 : , advgetopt::Help("used to validate that invalid numbers generate an error.")
992 : ),
993 : advgetopt::define_option(
994 : advgetopt::Name("out-of-bounds")
995 : , advgetopt::ShortName('o')
996 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
997 : , advgetopt::GETOPT_FLAG_REQUIRED>())
998 : , advgetopt::Help("valid values from 1 to 9.")
999 : ),
1000 : advgetopt::define_option(
1001 : advgetopt::Name("not-specified-and-no-default")
1002 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1003 : , advgetopt::GETOPT_FLAG_REQUIRED
1004 : , advgetopt::GETOPT_FLAG_SHOW_GROUP1>())
1005 : , advgetopt::Help("test long without having used the option and no default.")
1006 : ),
1007 : advgetopt::define_option(
1008 : advgetopt::Name("not-specified-with-invalid-default")
1009 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1010 : , advgetopt::GETOPT_FLAG_REQUIRED
1011 : , advgetopt::GETOPT_FLAG_MULTIPLE
1012 : , advgetopt::GETOPT_FLAG_SHOW_GROUP2>())
1013 : , advgetopt::Help("test that an invalid default value can be returned as is.")
1014 : , advgetopt::DefaultValue("123abc")
1015 : ),
1016 : advgetopt::define_option(
1017 : advgetopt::Name("not-specified-string-without-default")
1018 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1019 : , advgetopt::GETOPT_FLAG_REQUIRED>())
1020 : , advgetopt::Alias("string")
1021 : ),
1022 : advgetopt::define_option(
1023 : advgetopt::Name("string")
1024 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1025 : , advgetopt::GETOPT_FLAG_REQUIRED>())
1026 : , advgetopt::Help("string parameter.")
1027 : ),
1028 : advgetopt::define_option(
1029 : advgetopt::Name("unique")
1030 : , advgetopt::ShortName('u')
1031 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
1032 : , advgetopt::Help("make sure everything is unique.")
1033 : ),
1034 : advgetopt::define_option(
1035 : advgetopt::Name("quiet")
1036 : , advgetopt::ShortName('q')
1037 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1038 : , advgetopt::GETOPT_FLAG_MULTIPLE
1039 : , advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
1040 : , advgetopt::Help("make it quiet (opposite of verbose).")
1041 : ),
1042 : advgetopt::define_option(
1043 : advgetopt::Name("option-argument")
1044 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1045 : , advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
1046 : , advgetopt::Help("command line option which accepts an optional argument.")
1047 : ),
1048 : advgetopt::define_option(
1049 : advgetopt::Name("not-in-v2-though")
1050 : , advgetopt::ShortName('l')
1051 : , advgetopt::Flags(advgetopt::any_flags<advgetopt::GETOPT_FLAG_COMMAND_LINE
1052 : , advgetopt::GETOPT_FLAG_REQUIRED
1053 : , advgetopt::GETOPT_FLAG_SHOW_USAGE_ON_ERROR>())
1054 : , advgetopt::Help("long with just a letter.")
1055 : ),
1056 : advgetopt::define_option(
1057 : advgetopt::Name("--")
1058 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_DEFAULT_OPTION>())
1059 : , advgetopt::Help("other parameters are viewed as filenames; and we need at least one option with a very long help to check that it wraps perfectly (we'd really need to get the output of the command and check that against what is expected because at this time the test is rather blind in that respect! FIXED IN v2!)")
1060 : ),
1061 : advgetopt::end_options()
1062 : };
1063 :
1064 1 : advgetopt::options_environment options;
1065 1 : options.f_project_name = "unittest";
1066 1 : options.f_options = options_list;
1067 1 : options.f_help_header = "Usage: %p try this one and we get a throw (valid options + usage calls bis)";
1068 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1069 :
1070 1 : char const * cargv2[] =
1071 : {
1072 : "tests/unittests/unittest_advgetopt",
1073 : "--validate",
1074 : "--long",
1075 : "123abc",
1076 : "--out-of-bounds",
1077 : "123",
1078 : "--string",
1079 : "string value",
1080 : nullptr
1081 : };
1082 1 : int const argc2 = sizeof(cargv2) / sizeof(cargv2[0]) - 1;
1083 1 : char ** argv2 = const_cast<char **>(cargv2);
1084 :
1085 : // this initialization works as expected
1086 2 : advgetopt::getopt opt(options, argc2, argv2);
1087 :
1088 : // all of the following have the exiting exception
1089 : // for(int i(static_cast<int>(advgetopt::getopt::status_t::no_error)); i <= static_cast<int>(advgetopt::getopt::status_t::fatal); ++i)
1090 : // {
1091 : // CATCH_REQUIRE_THROWS_AS(opt.usage(static_cast<advgetopt::getopt::status_t>(i), "test no error, warnings, errors..."), advgetopt::getopt_exit);
1092 : // }
1093 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(advgetopt::GETOPT_FLAG_SHOW_ALL),
1094 : advgetopt::getopt::breakup_line(
1095 : "Usage: unittest_advgetopt try this one and we get a throw"
1096 : " (valid options + usage calls bis)"
1097 : , 0
1098 : , advgetopt::getopt::get_line_width())
1099 : + advgetopt::getopt::format_usage_string(
1100 : "--long <arg>"
1101 : , "used to validate that invalid numbers generate an error."
1102 : , 30
1103 : , advgetopt::getopt::get_line_width())
1104 : + advgetopt::getopt::format_usage_string(
1105 : "--long-help or -?"
1106 : , "show all the help from all the available options."
1107 : , 30
1108 : , advgetopt::getopt::get_line_width())
1109 : + advgetopt::getopt::format_usage_string(
1110 : "--not-in-v2-though or -l <arg>"
1111 : , "long with just a letter."
1112 : , 30
1113 : , advgetopt::getopt::get_line_width())
1114 : + advgetopt::getopt::format_usage_string(
1115 : "--not-specified-and-no-default <arg>"
1116 : , "test long without having used the option and no default."
1117 : , 30
1118 : , advgetopt::getopt::get_line_width())
1119 : + advgetopt::getopt::format_usage_string(
1120 : "--not-specified-with-invalid-default <arg> {<arg>} (default is \"123abc\")"
1121 : , "test that an invalid default value can be returned as is."
1122 : , 30
1123 : , advgetopt::getopt::get_line_width())
1124 : + advgetopt::getopt::format_usage_string(
1125 : "--option-argument [<arg>]"
1126 : , "command line option which accepts an optional argument."
1127 : , 30
1128 : , advgetopt::getopt::get_line_width())
1129 : + advgetopt::getopt::format_usage_string(
1130 : "--out-of-bounds or -o <arg>"
1131 : , "valid values from 1 to 9."
1132 : , 30
1133 : , advgetopt::getopt::get_line_width())
1134 : + advgetopt::getopt::format_usage_string(
1135 : "--quiet or -q {<arg>}"
1136 : , "make it quiet (opposite of verbose)."
1137 : , 30
1138 : , advgetopt::getopt::get_line_width())
1139 : + advgetopt::getopt::format_usage_string(
1140 : "--string <arg>"
1141 : , "string parameter."
1142 : , 30
1143 : , advgetopt::getopt::get_line_width())
1144 : + advgetopt::getopt::format_usage_string(
1145 : "--unique or -u"
1146 : , "make sure everything is unique."
1147 : , 30
1148 : , advgetopt::getopt::get_line_width())
1149 : + advgetopt::getopt::format_usage_string(
1150 : "--validate"
1151 : , "this is used to validate different things."
1152 : , 30
1153 : , advgetopt::getopt::get_line_width())
1154 : + advgetopt::getopt::format_usage_string(
1155 : "[default argument]"
1156 : , "other parameters are viewed as filenames; and we need at least"
1157 : " one option with a very long help to check that it wraps"
1158 : " perfectly (we'd really need to get the output of the command"
1159 : " and check that against what is expected because at this time"
1160 : " the test is rather blind in that respect! FIXED IN v2!)"
1161 : , 30
1162 : , advgetopt::getopt::get_line_width())
1163 : );
1164 : }
1165 : CATCH_END_SECTION()
1166 4 : }
1167 :
1168 :
1169 :
1170 :
1171 :
1172 3 : CATCH_TEST_CASE("help_string_percent", "[getopt][usage]")
1173 : {
1174 2 : CATCH_START_SECTION("Percent Percent")
1175 : {
1176 1 : const advgetopt::option options_list[] =
1177 : {
1178 : advgetopt::define_option(
1179 : advgetopt::Name("verbose")
1180 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1181 : , advgetopt::Help("inform you of what we're currently working on: %%.")
1182 : ),
1183 : advgetopt::define_option(
1184 : advgetopt::Name("this-is-a-very-long-argument-so-we-can-see-that-such-a-crazy-long-option-(who-does-that-though)-gets-broken-up-as-expected")
1185 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1186 : , advgetopt::Help("I guess the help is not necessary now...")
1187 : ),
1188 : advgetopt::end_options()
1189 : };
1190 1 : char const * cargv[] =
1191 : {
1192 : "tests/unittests/usage",
1193 : "--verbose",
1194 : nullptr
1195 : };
1196 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1197 1 : char ** argv = const_cast<char **>(cargv);
1198 :
1199 1 : advgetopt::options_environment options;
1200 1 : options.f_project_name = "unittest";
1201 1 : options.f_options = options_list;
1202 1 : options.f_options_files_directory = "/etc/advgetopt";
1203 1 : options.f_configuration_files = nullptr;
1204 1 : options.f_configuration_filename = "advgetopt.conf";
1205 1 : options.f_configuration_directories = nullptr;
1206 1 : options.f_help_header = "Usage: test usage: %%";
1207 1 : options.f_help_footer = "Percent Percent: %%";
1208 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1209 1 : options.f_version = "2.0.1-%%";
1210 1 : options.f_license = "MIT-%%";
1211 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %%";
1212 1 : options.f_build_date = "Jun 4 2019 %%";
1213 1 : options.f_build_time = "23:02:36 %%";
1214 :
1215 2 : advgetopt::getopt opt(options, argc, argv);
1216 :
1217 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1218 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1219 : advgetopt::getopt::breakup_line(
1220 : "Usage: test usage: %"
1221 : , 0
1222 : , advgetopt::getopt::get_line_width())
1223 : + advgetopt::getopt::format_usage_string(
1224 : "--this-is-a-very-long-argument-so-we-can-see-that-such-a-crazy-long-option-(who-does-that-though)-gets-broken-up-as-expected"
1225 : , "I guess the help is not necessary now..."
1226 : , 30
1227 : , advgetopt::getopt::get_line_width())
1228 : + advgetopt::getopt::format_usage_string(
1229 : "--verbose"
1230 : , "inform you of what we're currently working on: %."
1231 : , 30
1232 : , advgetopt::getopt::get_line_width()) + "\n"
1233 : + advgetopt::getopt::breakup_line(
1234 : "Percent Percent: %"
1235 : , 0
1236 : , advgetopt::getopt::get_line_width())
1237 : );
1238 :
1239 1 : CATCH_REQUIRE(opt.process_help_string(nullptr) == std::string());
1240 : }
1241 : CATCH_END_SECTION()
1242 1 : }
1243 :
1244 :
1245 :
1246 :
1247 5 : CATCH_TEST_CASE("help_string_project_name", "[getopt][usage]")
1248 : {
1249 6 : CATCH_START_SECTION("Percent Project Name (name defined)")
1250 : {
1251 1 : const advgetopt::option options_list[] =
1252 : {
1253 : advgetopt::define_option(
1254 : advgetopt::Name("verbose")
1255 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1256 : , advgetopt::Help("inform you of what we're currently working on: %a.")
1257 : ),
1258 : advgetopt::end_options()
1259 : };
1260 1 : char const * cargv[] =
1261 : {
1262 : "tests/unittests/usage",
1263 : "--verbose",
1264 : nullptr
1265 : };
1266 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1267 1 : char ** argv = const_cast<char **>(cargv);
1268 :
1269 1 : advgetopt::options_environment options;
1270 1 : options.f_project_name = "unittest";
1271 1 : options.f_options = options_list;
1272 1 : options.f_options_files_directory = "/etc/advgetopt";
1273 1 : options.f_configuration_files = nullptr;
1274 1 : options.f_configuration_filename = "advgetopt.conf";
1275 1 : options.f_configuration_directories = nullptr;
1276 1 : options.f_help_header = "Usage: test usage: %a";
1277 1 : options.f_help_footer = "Percent Project Name: %a";
1278 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1279 1 : options.f_version = "2.0.1-%a";
1280 1 : options.f_license = "MIT-%a";
1281 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %a";
1282 1 : options.f_build_date = "Jun 4 2019 %a";
1283 1 : options.f_build_time = "23:02:36 %a";
1284 :
1285 2 : advgetopt::getopt opt(options, argc, argv);
1286 :
1287 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1288 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1289 : advgetopt::getopt::breakup_line(
1290 : "Usage: test usage: unittest"
1291 : , 0
1292 : , advgetopt::getopt::get_line_width())
1293 : + advgetopt::getopt::format_usage_string(
1294 : "--verbose"
1295 : , "inform you of what we're currently working on: unittest."
1296 : , 30
1297 : , advgetopt::getopt::get_line_width()) + "\n"
1298 : + advgetopt::getopt::breakup_line(
1299 : "Percent Project Name: unittest"
1300 : , 0
1301 : , advgetopt::getopt::get_line_width())
1302 : );
1303 : }
1304 : CATCH_END_SECTION()
1305 :
1306 6 : CATCH_START_SECTION("Percent Project Name (nullptr)")
1307 : {
1308 1 : const advgetopt::option options_list[] =
1309 : {
1310 : advgetopt::define_option(
1311 : advgetopt::Name("verbose")
1312 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1313 : , advgetopt::Help("inform you of what we're currently working on: %a.")
1314 : ),
1315 : advgetopt::end_options()
1316 : };
1317 1 : char const * cargv[] =
1318 : {
1319 : "tests/unittests/usage",
1320 : "--verbose",
1321 : nullptr
1322 : };
1323 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1324 1 : char ** argv = const_cast<char **>(cargv);
1325 :
1326 1 : advgetopt::options_environment options;
1327 1 : options.f_project_name = nullptr;
1328 1 : options.f_options = options_list;
1329 1 : options.f_options_files_directory = "/etc/advgetopt";
1330 1 : options.f_configuration_files = nullptr;
1331 1 : options.f_configuration_filename = "advgetopt.conf";
1332 1 : options.f_configuration_directories = nullptr;
1333 1 : options.f_help_header = "Usage: test usage: %a";
1334 1 : options.f_help_footer = "Percent Project Name: %a";
1335 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1336 1 : options.f_version = "2.0.1-%a";
1337 1 : options.f_license = "MIT-%a";
1338 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %a";
1339 1 : options.f_build_date = "Jun 4 2019 %a";
1340 1 : options.f_build_time = "23:02:36 %a";
1341 :
1342 2 : advgetopt::getopt opt(options, argc, argv);
1343 :
1344 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1345 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1346 : "Usage: test usage: \n"
1347 : " --verbose inform you of what we're currently working on: .\n"
1348 : "\n"
1349 : "Percent Project Name: \n"
1350 : );
1351 : }
1352 : CATCH_END_SECTION()
1353 :
1354 6 : CATCH_START_SECTION("Percent Project Name (\"\")")
1355 : {
1356 1 : const advgetopt::option options_list[] =
1357 : {
1358 : advgetopt::define_option(
1359 : advgetopt::Name("verbose")
1360 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1361 : , advgetopt::Help("inform you of what we're currently working on: %a.")
1362 : ),
1363 : advgetopt::end_options()
1364 : };
1365 1 : char const * cargv[] =
1366 : {
1367 : "tests/unittests/usage",
1368 : "--verbose",
1369 : nullptr
1370 : };
1371 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1372 1 : char ** argv = const_cast<char **>(cargv);
1373 :
1374 1 : advgetopt::options_environment options;
1375 1 : options.f_project_name = "";
1376 1 : options.f_options = options_list;
1377 1 : options.f_options_files_directory = "/etc/advgetopt";
1378 1 : options.f_configuration_files = nullptr;
1379 1 : options.f_configuration_filename = "advgetopt.conf";
1380 1 : options.f_configuration_directories = nullptr;
1381 1 : options.f_help_header = "Usage: test usage: %a";
1382 1 : options.f_help_footer = "Percent Project Name: %a";
1383 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1384 1 : options.f_version = "2.0.1-%a";
1385 1 : options.f_license = "MIT-%a";
1386 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %a";
1387 1 : options.f_build_date = "Jun 4 2019 %a";
1388 1 : options.f_build_time = "23:02:36 %a";
1389 :
1390 2 : advgetopt::getopt opt(options, argc, argv);
1391 :
1392 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1393 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1394 : "Usage: test usage: \n"
1395 : " --verbose inform you of what we're currently working on: .\n"
1396 : "\n"
1397 : "Percent Project Name: \n"
1398 : );
1399 : }
1400 : CATCH_END_SECTION()
1401 3 : }
1402 :
1403 :
1404 :
1405 5 : CATCH_TEST_CASE("help_string_build_date", "[getopt][usage]")
1406 : {
1407 6 : CATCH_START_SECTION("Percent Build Date (defined)")
1408 : {
1409 1 : const advgetopt::option options_list[] =
1410 : {
1411 : advgetopt::define_option(
1412 : advgetopt::Name("verbose")
1413 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1414 : , advgetopt::Help("inform you of what we're currently working on: %b.")
1415 : ),
1416 : advgetopt::end_options()
1417 : };
1418 1 : char const * cargv[] =
1419 : {
1420 : "tests/unittests/usage",
1421 : "--verbose",
1422 : nullptr
1423 : };
1424 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1425 1 : char ** argv = const_cast<char **>(cargv);
1426 :
1427 1 : advgetopt::options_environment options;
1428 1 : options.f_project_name = "unittest";
1429 1 : options.f_options = options_list;
1430 1 : options.f_options_files_directory = "/etc/advgetopt";
1431 1 : options.f_configuration_files = nullptr;
1432 1 : options.f_configuration_filename = "advgetopt.conf";
1433 1 : options.f_configuration_directories = nullptr;
1434 1 : options.f_help_header = "Usage: test usage: %b";
1435 1 : options.f_help_footer = "Percent Build Date: %b";
1436 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1437 1 : options.f_version = "2.0.1-%b";
1438 1 : options.f_license = "MIT-%b";
1439 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %b";
1440 1 : options.f_build_date = "Jun 4 2019 %b";
1441 1 : options.f_build_time = "23:02:36 %b";
1442 :
1443 2 : advgetopt::getopt opt(options, argc, argv);
1444 :
1445 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1446 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1447 : advgetopt::getopt::breakup_line(
1448 : "Usage: test usage: Jun 4 2019 %b"
1449 : , 0
1450 : , advgetopt::getopt::get_line_width())
1451 : + advgetopt::getopt::format_usage_string(
1452 : "--verbose"
1453 : , "inform you of what we're currently working on: Jun 4 2019 %b."
1454 : , 30
1455 : , advgetopt::getopt::get_line_width()) + "\n"
1456 : + advgetopt::getopt::breakup_line(
1457 : "Percent Build Date: Jun 4 2019 %b"
1458 : , 0
1459 : , advgetopt::getopt::get_line_width())
1460 : );
1461 : }
1462 : CATCH_END_SECTION()
1463 :
1464 6 : CATCH_START_SECTION("Percent Build Date (nullptr)")
1465 : {
1466 1 : const advgetopt::option options_list[] =
1467 : {
1468 : advgetopt::define_option(
1469 : advgetopt::Name("verbose")
1470 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1471 : , advgetopt::Help("inform you of what we're currently working on: %b.")
1472 : ),
1473 : advgetopt::end_options()
1474 : };
1475 1 : char const * cargv[] =
1476 : {
1477 : "tests/unittests/usage",
1478 : "--verbose",
1479 : nullptr
1480 : };
1481 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1482 1 : char ** argv = const_cast<char **>(cargv);
1483 :
1484 1 : advgetopt::options_environment options;
1485 1 : options.f_project_name = "unittest";
1486 1 : options.f_options = options_list;
1487 1 : options.f_options_files_directory = "/etc/advgetopt";
1488 1 : options.f_configuration_files = nullptr;
1489 1 : options.f_configuration_filename = "advgetopt.conf";
1490 1 : options.f_configuration_directories = nullptr;
1491 1 : options.f_help_header = "Usage: test usage: %b";
1492 1 : options.f_help_footer = "Percent Build Date: %b";
1493 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1494 1 : options.f_version = "2.0.1-%b";
1495 1 : options.f_license = "MIT-%b";
1496 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %b";
1497 1 : options.f_build_date = nullptr;
1498 1 : options.f_build_time = "23:02:36 %b";
1499 :
1500 2 : advgetopt::getopt opt(options, argc, argv);
1501 :
1502 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1503 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1504 : "Usage: test usage: \n"
1505 : " --verbose inform you of what we're currently working on: .\n"
1506 : "\n"
1507 : "Percent Build Date: \n"
1508 : );
1509 : }
1510 : CATCH_END_SECTION()
1511 :
1512 6 : CATCH_START_SECTION("Percent Build Date (\"\")")
1513 : {
1514 1 : const advgetopt::option options_list[] =
1515 : {
1516 : advgetopt::define_option(
1517 : advgetopt::Name("verbose")
1518 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1519 : , advgetopt::Help("inform you of what we're currently working on: %b.")
1520 : ),
1521 : advgetopt::end_options()
1522 : };
1523 1 : char const * cargv[] =
1524 : {
1525 : "tests/unittests/usage",
1526 : "--verbose",
1527 : nullptr
1528 : };
1529 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1530 1 : char ** argv = const_cast<char **>(cargv);
1531 :
1532 1 : advgetopt::options_environment options;
1533 1 : options.f_project_name = "unittest";
1534 1 : options.f_options = options_list;
1535 1 : options.f_options_files_directory = "/etc/advgetopt";
1536 1 : options.f_configuration_files = nullptr;
1537 1 : options.f_configuration_filename = "advgetopt.conf";
1538 1 : options.f_configuration_directories = nullptr;
1539 1 : options.f_help_header = "Usage: test usage: %b";
1540 1 : options.f_help_footer = "Percent Build Date: %b";
1541 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1542 1 : options.f_version = "2.0.1-%b";
1543 1 : options.f_license = "MIT-%b";
1544 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %b";
1545 1 : options.f_build_date = "";
1546 1 : options.f_build_time = "23:02:36 %b";
1547 :
1548 2 : advgetopt::getopt opt(options, argc, argv);
1549 :
1550 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1551 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1552 : "Usage: test usage: \n"
1553 : " --verbose inform you of what we're currently working on: .\n"
1554 : "\n"
1555 : "Percent Build Date: \n"
1556 : );
1557 : }
1558 : CATCH_END_SECTION()
1559 3 : }
1560 :
1561 :
1562 :
1563 :
1564 5 : CATCH_TEST_CASE("help_string_copyright", "[getopt][usage]")
1565 : {
1566 6 : CATCH_START_SECTION("Percent Copyright (defined)")
1567 : {
1568 1 : const advgetopt::option options_list[] =
1569 : {
1570 : advgetopt::define_option(
1571 : advgetopt::Name("verbose")
1572 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1573 : , advgetopt::Help("inform you of what we're currently working on: %c.")
1574 : ),
1575 : advgetopt::end_options()
1576 : };
1577 1 : char const * cargv[] =
1578 : {
1579 : "tests/unittests/usage",
1580 : "--verbose",
1581 : nullptr
1582 : };
1583 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1584 1 : char ** argv = const_cast<char **>(cargv);
1585 :
1586 1 : advgetopt::options_environment options;
1587 1 : options.f_project_name = "unittest";
1588 1 : options.f_options = options_list;
1589 1 : options.f_options_files_directory = "/etc/advgetopt";
1590 1 : options.f_configuration_files = nullptr;
1591 1 : options.f_configuration_filename = "advgetopt.conf";
1592 1 : options.f_configuration_directories = nullptr;
1593 1 : options.f_help_header = "Usage: test usage: %c";
1594 1 : options.f_help_footer = "Percent Copyright: %c";
1595 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1596 1 : options.f_version = "2.0.1-%c";
1597 1 : options.f_license = "MIT-%c";
1598 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %c";
1599 1 : options.f_build_date = "Jun 4 2019 %c";
1600 1 : options.f_build_time = "23:02:36 %c";
1601 :
1602 2 : advgetopt::getopt opt(options, argc, argv);
1603 :
1604 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1605 :
1606 : //std::string a = opt.usage();
1607 : //std::string b = "Usage: test usage: Copyright (c) 2019 Made to Order Software Corp. -- All\n"
1608 : //"Rights Reserved %c\n"
1609 : //" --verbose inform you of what we're currently working on:\n"
1610 : //" Copyright (c) 2019 Made to Order Software Corp.\n"
1611 : //" -- All Rights Reserved %c.\n"
1612 : //"\n"
1613 : //"Percent Copyright: Copyright (c) 2019 Made to Order Software Corp. -- All\n"
1614 : //"Rights Reserved %c\n";
1615 : //int max(std::min(a.length(), b.length()));
1616 : //for(int idx(0); idx < max;++idx)
1617 : //{
1618 : // std::cerr << "[" << a[idx] << "] == [" << b[idx] << "] = " << (a[idx] == b[idx] ? "TRUE" : "FALSE") << "\n";
1619 : //}
1620 :
1621 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1622 : advgetopt::getopt::breakup_line(
1623 : "Usage: test usage: Copyright (c) 2019 Made to Order Software Corp. -- All"
1624 : " Rights Reserved %c"
1625 : , 0
1626 : , advgetopt::getopt::get_line_width())
1627 : + advgetopt::getopt::format_usage_string(
1628 : "--verbose"
1629 : , "inform you of what we're currently working on:"
1630 : " Copyright (c) 2019 Made to Order Software Corp."
1631 : " -- All Rights Reserved %c."
1632 : , 30
1633 : , advgetopt::getopt::get_line_width()) + "\n"
1634 : + advgetopt::getopt::breakup_line(
1635 : "Percent Copyright: Copyright (c) 2019 Made to Order Software"
1636 : " Corp. -- All Rights Reserved %c"
1637 : , 0
1638 : , advgetopt::getopt::get_line_width())
1639 : );
1640 : }
1641 : CATCH_END_SECTION()
1642 :
1643 6 : CATCH_START_SECTION("Percent Copyright (nullptr)")
1644 : {
1645 1 : const advgetopt::option options_list[] =
1646 : {
1647 : advgetopt::define_option(
1648 : advgetopt::Name("verbose")
1649 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1650 : , advgetopt::Help("inform you of what we're currently working on: %c.")
1651 : ),
1652 : advgetopt::end_options()
1653 : };
1654 1 : char const * cargv[] =
1655 : {
1656 : "tests/unittests/usage",
1657 : "--verbose",
1658 : nullptr
1659 : };
1660 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1661 1 : char ** argv = const_cast<char **>(cargv);
1662 :
1663 1 : advgetopt::options_environment options;
1664 1 : options.f_project_name = "unittest";
1665 1 : options.f_options = options_list;
1666 1 : options.f_options_files_directory = "/etc/advgetopt";
1667 1 : options.f_configuration_files = nullptr;
1668 1 : options.f_configuration_filename = "advgetopt.conf";
1669 1 : options.f_configuration_directories = nullptr;
1670 1 : options.f_help_header = "Usage: test usage: %c";
1671 1 : options.f_help_footer = "Percent Copyright: %c";
1672 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1673 1 : options.f_version = "2.0.1-%c";
1674 1 : options.f_license = "MIT-%c";
1675 1 : options.f_copyright = nullptr;
1676 1 : options.f_build_date = "Jun 4 2019 %c";
1677 1 : options.f_build_time = "23:02:36 %c";
1678 :
1679 2 : advgetopt::getopt opt(options, argc, argv);
1680 :
1681 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1682 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1683 : "Usage: test usage: \n"
1684 : " --verbose inform you of what we're currently working on: .\n"
1685 : "\n"
1686 : "Percent Copyright: \n"
1687 : );
1688 : }
1689 : CATCH_END_SECTION()
1690 :
1691 6 : CATCH_START_SECTION("Percent Copyright (\"\")")
1692 : {
1693 1 : const advgetopt::option options_list[] =
1694 : {
1695 : advgetopt::define_option(
1696 : advgetopt::Name("verbose")
1697 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1698 : , advgetopt::Help("inform you of what we're currently working on: %c.")
1699 : ),
1700 : advgetopt::end_options()
1701 : };
1702 1 : char const * cargv[] =
1703 : {
1704 : "tests/unittests/usage",
1705 : "--verbose",
1706 : nullptr
1707 : };
1708 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1709 1 : char ** argv = const_cast<char **>(cargv);
1710 :
1711 1 : advgetopt::options_environment options;
1712 1 : options.f_project_name = "unittest";
1713 1 : options.f_options = options_list;
1714 1 : options.f_options_files_directory = "/etc/advgetopt";
1715 1 : options.f_configuration_files = nullptr;
1716 1 : options.f_configuration_filename = "advgetopt.conf";
1717 1 : options.f_configuration_directories = nullptr;
1718 1 : options.f_help_header = "Usage: test usage: %c";
1719 1 : options.f_help_footer = "Percent Copyright: %c";
1720 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1721 1 : options.f_version = "2.0.1-%c";
1722 1 : options.f_license = "MIT-%c";
1723 1 : options.f_copyright = "";
1724 1 : options.f_build_date = "Jun 4 2019 %c";
1725 1 : options.f_build_time = "23:02:36 %c";
1726 :
1727 2 : advgetopt::getopt opt(options, argc, argv);
1728 :
1729 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1730 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1731 : "Usage: test usage: \n"
1732 : " --verbose inform you of what we're currently working on: .\n"
1733 : "\n"
1734 : "Percent Copyright: \n"
1735 : );
1736 : }
1737 : CATCH_END_SECTION()
1738 3 : }
1739 :
1740 :
1741 :
1742 :
1743 8 : CATCH_TEST_CASE("help_string_directories", "[getopt][usage][config]")
1744 : {
1745 12 : CATCH_START_SECTION("Percent Directories (fully defined)")
1746 : {
1747 1 : const advgetopt::option options_list[] =
1748 : {
1749 : advgetopt::define_option(
1750 : advgetopt::Name("verbose")
1751 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1752 : , advgetopt::Help("inform you of what we're currently working on: %d.")
1753 : ),
1754 : advgetopt::end_options()
1755 : };
1756 1 : char const * cargv[] =
1757 : {
1758 : "tests/unittests/usage",
1759 : "--verbose",
1760 : nullptr
1761 : };
1762 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1763 1 : char ** argv = const_cast<char **>(cargv);
1764 :
1765 1 : const char * const configuration_directories[] =
1766 : {
1767 : "/etc/sys/advgetopt",
1768 : "/etc/advgetopt",
1769 : "/etc/advgetopt/advgetopt.d",
1770 : "~/.config/advgetopt",
1771 : nullptr
1772 : };
1773 :
1774 1 : advgetopt::options_environment options;
1775 1 : options.f_project_name = "unittest";
1776 1 : options.f_options = options_list;
1777 1 : options.f_options_files_directory = "/etc/advgetopt";
1778 1 : options.f_configuration_files = nullptr;
1779 1 : options.f_configuration_filename = "advgetopt.conf";
1780 1 : options.f_configuration_directories = configuration_directories;
1781 1 : options.f_help_header = "Usage: test usage: %d";
1782 1 : options.f_help_footer = "Percent Directories: %d";
1783 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1784 1 : options.f_version = "2.0.1-%d";
1785 1 : options.f_license = "MIT-%d";
1786 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %d";
1787 1 : options.f_build_date = "Jun 4 2019 %d";
1788 1 : options.f_build_time = "23:02:36 %d";
1789 :
1790 2 : advgetopt::getopt opt(options, argc, argv);
1791 :
1792 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1793 :
1794 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1795 : advgetopt::getopt::breakup_line(
1796 : "Usage: test usage: /etc/sys/advgetopt"
1797 : , 0
1798 : , advgetopt::getopt::get_line_width())
1799 : + advgetopt::getopt::format_usage_string(
1800 : "--verbose"
1801 : , "inform you of what we're currently working on:"
1802 : " /etc/sys/advgetopt."
1803 : , 30
1804 : , advgetopt::getopt::get_line_width()) + "\n"
1805 : + advgetopt::getopt::breakup_line(
1806 : "Percent Directories: /etc/sys/advgetopt"
1807 : , 0
1808 : , advgetopt::getopt::get_line_width())
1809 : );
1810 : }
1811 : CATCH_END_SECTION()
1812 :
1813 12 : CATCH_START_SECTION("Percent Asterisk Directories (fully defined)")
1814 : {
1815 1 : const advgetopt::option options_list[] =
1816 : {
1817 : advgetopt::define_option(
1818 : advgetopt::Name("verbose")
1819 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1820 : , advgetopt::Help("inform you of what we're currently working on: %*d.")
1821 : ),
1822 : advgetopt::end_options()
1823 : };
1824 1 : char const * cargv[] =
1825 : {
1826 : "tests/unittests/usage",
1827 : "--verbose",
1828 : nullptr
1829 : };
1830 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1831 1 : char ** argv = const_cast<char **>(cargv);
1832 :
1833 1 : const char * const configuration_directories[] =
1834 : {
1835 : "/etc/sys/advgetopt",
1836 : "/etc/advgetopt",
1837 : "/etc/advgetopt/advgetopt.d",
1838 : "~/.config/advgetopt",
1839 : nullptr
1840 : };
1841 :
1842 1 : advgetopt::options_environment options;
1843 1 : options.f_project_name = "unittest";
1844 1 : options.f_options = options_list;
1845 1 : options.f_options_files_directory = "/etc/advgetopt";
1846 1 : options.f_configuration_files = nullptr;
1847 1 : options.f_configuration_filename = "advgetopt.conf";
1848 1 : options.f_configuration_directories = configuration_directories;
1849 1 : options.f_help_header = "Usage: test usage: %*d";
1850 1 : options.f_help_footer = "Percent Directories: %*d";
1851 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1852 1 : options.f_version = "2.0.1-%*d";
1853 1 : options.f_license = "MIT-%*d";
1854 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*d";
1855 1 : options.f_build_date = "Jun 4 2019 %*d";
1856 1 : options.f_build_time = "23:02:36 %*d";
1857 :
1858 2 : advgetopt::getopt opt(options, argc, argv);
1859 :
1860 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1861 :
1862 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1863 : advgetopt::getopt::breakup_line(
1864 : "Usage: test usage: /etc/sys/advgetopt, /etc/advgetopt,"
1865 : " /etc/advgetopt/advgetopt.d, ~/.config/advgetopt"
1866 : , 0
1867 : , advgetopt::getopt::get_line_width())
1868 : + advgetopt::getopt::format_usage_string(
1869 : "--verbose"
1870 : , "inform you of what we're currently working on:"
1871 : " /etc/sys/advgetopt, /etc/advgetopt,"
1872 : " /etc/advgetopt/advgetopt.d, ~/.config/advgetopt."
1873 : , 30
1874 : , advgetopt::getopt::get_line_width()) + "\n"
1875 : + advgetopt::getopt::breakup_line(
1876 : "Percent Directories: /etc/sys/advgetopt, /etc/advgetopt,"
1877 : " /etc/advgetopt/advgetopt.d, ~/.config/advgetopt"
1878 : , 0
1879 : , advgetopt::getopt::get_line_width())
1880 : );
1881 : }
1882 : CATCH_END_SECTION()
1883 :
1884 12 : CATCH_START_SECTION("Percent Directories (nullptr)")
1885 : {
1886 1 : const advgetopt::option options_list[] =
1887 : {
1888 : advgetopt::define_option(
1889 : advgetopt::Name("verbose")
1890 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1891 : , advgetopt::Help("inform you of what we're currently working on: %d.")
1892 : ),
1893 : advgetopt::end_options()
1894 : };
1895 1 : char const * cargv[] =
1896 : {
1897 : "tests/unittests/usage",
1898 : "--verbose",
1899 : nullptr
1900 : };
1901 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1902 1 : char ** argv = const_cast<char **>(cargv);
1903 :
1904 1 : advgetopt::options_environment options;
1905 1 : options.f_project_name = "unittest";
1906 1 : options.f_options = options_list;
1907 1 : options.f_options_files_directory = "/etc/advgetopt";
1908 1 : options.f_configuration_files = nullptr;
1909 1 : options.f_configuration_filename = "advgetopt.conf";
1910 1 : options.f_configuration_directories = nullptr;
1911 1 : options.f_help_header = "Usage: test usage: %d";
1912 1 : options.f_help_footer = "Percent Directories: %d";
1913 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1914 1 : options.f_version = "2.0.1-%d";
1915 1 : options.f_license = "MIT-%d";
1916 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %d";
1917 1 : options.f_build_date = "Jun 4 2019 %d";
1918 1 : options.f_build_time = "23:02:36 %d";
1919 :
1920 2 : advgetopt::getopt opt(options, argc, argv);
1921 :
1922 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1923 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1924 : "Usage: test usage: \n"
1925 : " --verbose inform you of what we're currently working on: .\n"
1926 : "\n"
1927 : "Percent Directories: \n"
1928 : );
1929 : }
1930 : CATCH_END_SECTION()
1931 :
1932 12 : CATCH_START_SECTION("Percent Asterisk Directories (nullptr)")
1933 : {
1934 1 : const advgetopt::option options_list[] =
1935 : {
1936 : advgetopt::define_option(
1937 : advgetopt::Name("verbose")
1938 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1939 : , advgetopt::Help("inform you of what we're currently working on: %*d.")
1940 : ),
1941 : advgetopt::end_options()
1942 : };
1943 1 : char const * cargv[] =
1944 : {
1945 : "tests/unittests/usage",
1946 : "--verbose",
1947 : nullptr
1948 : };
1949 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1950 1 : char ** argv = const_cast<char **>(cargv);
1951 :
1952 1 : advgetopt::options_environment options;
1953 1 : options.f_project_name = "unittest";
1954 1 : options.f_options = options_list;
1955 1 : options.f_options_files_directory = "/etc/advgetopt";
1956 1 : options.f_configuration_files = nullptr;
1957 1 : options.f_configuration_filename = "advgetopt.conf";
1958 1 : options.f_configuration_directories = nullptr;
1959 1 : options.f_help_header = "Usage: test usage: %*d";
1960 1 : options.f_help_footer = "Percent Directories: %*d";
1961 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
1962 1 : options.f_version = "2.0.1-%*d";
1963 1 : options.f_license = "MIT-%*d";
1964 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*d";
1965 1 : options.f_build_date = "Jun 4 2019 %*d";
1966 1 : options.f_build_time = "23:02:36 %*d";
1967 :
1968 2 : advgetopt::getopt opt(options, argc, argv);
1969 :
1970 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
1971 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
1972 : "Usage: test usage: \n"
1973 : " --verbose inform you of what we're currently working on: .\n"
1974 : "\n"
1975 : "Percent Directories: \n"
1976 : );
1977 : }
1978 : CATCH_END_SECTION()
1979 :
1980 12 : CATCH_START_SECTION("Percent Directories (empty array)")
1981 : {
1982 1 : const advgetopt::option options_list[] =
1983 : {
1984 : advgetopt::define_option(
1985 : advgetopt::Name("verbose")
1986 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
1987 : , advgetopt::Help("inform you of what we're currently working on: %d.")
1988 : ),
1989 : advgetopt::end_options()
1990 : };
1991 1 : char const * cargv[] =
1992 : {
1993 : "tests/unittests/usage",
1994 : "--verbose",
1995 : nullptr
1996 : };
1997 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
1998 1 : char ** argv = const_cast<char **>(cargv);
1999 :
2000 1 : const char * const configuration_directories[] =
2001 : {
2002 : nullptr
2003 : };
2004 :
2005 1 : advgetopt::options_environment options;
2006 1 : options.f_project_name = "unittest";
2007 1 : options.f_options = options_list;
2008 1 : options.f_options_files_directory = "/etc/advgetopt";
2009 1 : options.f_configuration_files = nullptr;
2010 1 : options.f_configuration_filename = "advgetopt.conf";
2011 1 : options.f_configuration_directories = configuration_directories;
2012 1 : options.f_help_header = "Usage: test usage: %d";
2013 1 : options.f_help_footer = "Percent Directories: %d";
2014 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2015 1 : options.f_version = "2.0.1-%d";
2016 1 : options.f_license = "MIT-%d";
2017 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %d";
2018 1 : options.f_build_date = "Jun 4 2019 %d";
2019 1 : options.f_build_time = "23:02:36 %d";
2020 :
2021 2 : advgetopt::getopt opt(options, argc, argv);
2022 :
2023 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2024 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2025 : "Usage: test usage: \n"
2026 : " --verbose inform you of what we're currently working on: .\n"
2027 : "\n"
2028 : "Percent Directories: \n"
2029 : );
2030 : }
2031 : CATCH_END_SECTION()
2032 :
2033 12 : CATCH_START_SECTION("Percent Asterisk Directories (empty array)")
2034 : {
2035 1 : const advgetopt::option options_list[] =
2036 : {
2037 : advgetopt::define_option(
2038 : advgetopt::Name("verbose")
2039 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
2040 : , advgetopt::Help("inform you of what we're currently working on: %*d.")
2041 : ),
2042 : advgetopt::end_options()
2043 : };
2044 1 : char const * cargv[] =
2045 : {
2046 : "tests/unittests/usage",
2047 : "--verbose",
2048 : nullptr
2049 : };
2050 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2051 1 : char ** argv = const_cast<char **>(cargv);
2052 :
2053 1 : const char * const configuration_directories[] =
2054 : {
2055 : nullptr
2056 : };
2057 :
2058 1 : advgetopt::options_environment options;
2059 1 : options.f_project_name = "unittest";
2060 1 : options.f_options = options_list;
2061 1 : options.f_options_files_directory = "/etc/advgetopt";
2062 1 : options.f_configuration_files = nullptr;
2063 1 : options.f_configuration_filename = "advgetopt.conf";
2064 1 : options.f_configuration_directories = configuration_directories;
2065 1 : options.f_help_header = "Usage: test usage: %*d";
2066 1 : options.f_help_footer = "Percent Directories: %*d";
2067 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2068 1 : options.f_version = "2.0.1-%*d";
2069 1 : options.f_license = "MIT-%*d";
2070 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*d";
2071 1 : options.f_build_date = "Jun 4 2019 %*d";
2072 1 : options.f_build_time = "23:02:36 %*d";
2073 :
2074 2 : advgetopt::getopt opt(options, argc, argv);
2075 :
2076 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2077 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2078 : "Usage: test usage: \n"
2079 : " --verbose inform you of what we're currently working on: .\n"
2080 : "\n"
2081 : "Percent Directories: \n"
2082 : );
2083 : }
2084 : CATCH_END_SECTION()
2085 6 : }
2086 :
2087 :
2088 :
2089 :
2090 14 : CATCH_TEST_CASE("help_string_environment_variable", "[getopt][usage]")
2091 : {
2092 24 : CATCH_START_SECTION("Percent Environment Variable (fully defined, variable set)")
2093 : {
2094 2 : snap::safe_setenv env("ADVGETOPT_TEST_OPTIONS", "--verbose");
2095 :
2096 1 : const advgetopt::option options_list[] =
2097 : {
2098 : advgetopt::define_option(
2099 : advgetopt::Name("verbose")
2100 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2101 : , advgetopt::Help("inform you of what we're currently working on: %e.")
2102 : ),
2103 : advgetopt::end_options()
2104 : };
2105 1 : char const * cargv[] =
2106 : {
2107 : "tests/unittests/usage",
2108 : nullptr
2109 : };
2110 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2111 1 : char ** argv = const_cast<char **>(cargv);
2112 :
2113 1 : advgetopt::options_environment options;
2114 1 : options.f_project_name = "unittest";
2115 1 : options.f_options = options_list;
2116 1 : options.f_options_files_directory = "/etc/advgetopt";
2117 1 : options.f_configuration_files = nullptr;
2118 1 : options.f_configuration_filename = "advgetopt.conf";
2119 1 : options.f_configuration_directories = nullptr;
2120 1 : options.f_help_header = "Usage: test usage: %e";
2121 1 : options.f_help_footer = "Percent Environment Variable: %e";
2122 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2123 1 : options.f_version = "2.0.1-%e";
2124 1 : options.f_license = "MIT-%e";
2125 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %e";
2126 1 : options.f_build_date = "Jun 4 2019 %e";
2127 1 : options.f_build_time = "23:02:36 %e";
2128 :
2129 2 : advgetopt::getopt opt(options, argc, argv);
2130 :
2131 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2132 :
2133 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2134 : advgetopt::getopt::breakup_line(
2135 : "Usage: test usage: ADVGETOPT_TEST_OPTIONS"
2136 : , 0
2137 : , advgetopt::getopt::get_line_width())
2138 : + advgetopt::getopt::format_usage_string(
2139 : "--verbose"
2140 : , "inform you of what we're currently working on:"
2141 : " ADVGETOPT_TEST_OPTIONS."
2142 : , 30
2143 : , advgetopt::getopt::get_line_width()) + "\n"
2144 : + advgetopt::getopt::breakup_line(
2145 : "Percent Environment Variable: ADVGETOPT_TEST_OPTIONS"
2146 : , 0
2147 : , advgetopt::getopt::get_line_width())
2148 : );
2149 : }
2150 : CATCH_END_SECTION()
2151 :
2152 24 : CATCH_START_SECTION("Percent Environment Variable (fully defined, variable not set)")
2153 : {
2154 1 : const advgetopt::option options_list[] =
2155 : {
2156 : advgetopt::define_option(
2157 : advgetopt::Name("verbose")
2158 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2159 : , advgetopt::Help("inform you of what we're currently working on: %e.")
2160 : ),
2161 : advgetopt::end_options()
2162 : };
2163 1 : char const * cargv[] =
2164 : {
2165 : "tests/unittests/usage",
2166 : nullptr
2167 : };
2168 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2169 1 : char ** argv = const_cast<char **>(cargv);
2170 :
2171 1 : advgetopt::options_environment options;
2172 1 : options.f_project_name = "unittest";
2173 1 : options.f_options = options_list;
2174 1 : options.f_options_files_directory = "/etc/advgetopt";
2175 1 : options.f_configuration_files = nullptr;
2176 1 : options.f_configuration_filename = "advgetopt.conf";
2177 1 : options.f_configuration_directories = nullptr;
2178 1 : options.f_help_header = "Usage: test usage: %e";
2179 1 : options.f_help_footer = "Percent Environment Variable: %e";
2180 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2181 1 : options.f_version = "2.0.1-%e";
2182 1 : options.f_license = "MIT-%e";
2183 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %e";
2184 1 : options.f_build_date = "Jun 4 2019 %e";
2185 1 : options.f_build_time = "23:02:36 %e";
2186 :
2187 2 : advgetopt::getopt opt(options, argc, argv);
2188 :
2189 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2190 :
2191 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2192 : advgetopt::getopt::breakup_line(
2193 : "Usage: test usage: ADVGETOPT_TEST_OPTIONS"
2194 : , 0
2195 : , advgetopt::getopt::get_line_width())
2196 : + advgetopt::getopt::format_usage_string(
2197 : "--verbose"
2198 : , "inform you of what we're currently working on:"
2199 : " ADVGETOPT_TEST_OPTIONS."
2200 : , 30
2201 : , advgetopt::getopt::get_line_width()) + "\n"
2202 : + advgetopt::getopt::breakup_line(
2203 : "Percent Environment Variable: ADVGETOPT_TEST_OPTIONS"
2204 : , 0
2205 : , advgetopt::getopt::get_line_width())
2206 : );
2207 : }
2208 : CATCH_END_SECTION()
2209 :
2210 24 : CATCH_START_SECTION("Percent Asterisk Environment Variable (fully defined, variable set)")
2211 : {
2212 2 : snap::safe_setenv env("ADVGETOPT_TEST_OPTIONS", "--verbose");
2213 :
2214 1 : const advgetopt::option options_list[] =
2215 : {
2216 : advgetopt::define_option(
2217 : advgetopt::Name("verbose")
2218 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2219 : , advgetopt::Help("inform you of what we're currently working on: %*e.")
2220 : ),
2221 : advgetopt::end_options()
2222 : };
2223 1 : char const * cargv[] =
2224 : {
2225 : "tests/unittests/usage",
2226 : nullptr
2227 : };
2228 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2229 1 : char ** argv = const_cast<char **>(cargv);
2230 :
2231 1 : advgetopt::options_environment options;
2232 1 : options.f_project_name = "unittest";
2233 1 : options.f_options = options_list;
2234 1 : options.f_options_files_directory = "/etc/advgetopt";
2235 1 : options.f_configuration_files = nullptr;
2236 1 : options.f_configuration_filename = "advgetopt.conf";
2237 1 : options.f_configuration_directories = nullptr;
2238 1 : options.f_help_header = "Usage: test usage: %*e";
2239 1 : options.f_help_footer = "Percent Environment Variable: %*e";
2240 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2241 1 : options.f_version = "2.0.1-%*e";
2242 1 : options.f_license = "MIT-%*e";
2243 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*e";
2244 1 : options.f_build_date = "Jun 4 2019 %*e";
2245 1 : options.f_build_time = "23:02:36 %*e";
2246 :
2247 2 : advgetopt::getopt opt(options, argc, argv);
2248 :
2249 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2250 :
2251 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2252 : advgetopt::getopt::breakup_line(
2253 : "Usage: test usage: ADVGETOPT_TEST_OPTIONS=--verbose"
2254 : , 0
2255 : , advgetopt::getopt::get_line_width())
2256 : + advgetopt::getopt::format_usage_string(
2257 : "--verbose"
2258 : , "inform you of what we're currently working on:"
2259 : " ADVGETOPT_TEST_OPTIONS=--verbose."
2260 : , 30
2261 : , advgetopt::getopt::get_line_width()) + "\n"
2262 : + advgetopt::getopt::breakup_line(
2263 : "Percent Environment Variable: ADVGETOPT_TEST_OPTIONS=--verbose"
2264 : , 0
2265 : , advgetopt::getopt::get_line_width())
2266 : );
2267 : }
2268 : CATCH_END_SECTION()
2269 :
2270 24 : CATCH_START_SECTION("Percent Asterisk Environment Variable (fully defined, variable not set)")
2271 : {
2272 1 : const advgetopt::option options_list[] =
2273 : {
2274 : advgetopt::define_option(
2275 : advgetopt::Name("verbose")
2276 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2277 : , advgetopt::Help("inform you of what we're currently working on: %*e.")
2278 : ),
2279 : advgetopt::end_options()
2280 : };
2281 1 : char const * cargv[] =
2282 : {
2283 : "tests/unittests/usage",
2284 : nullptr
2285 : };
2286 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2287 1 : char ** argv = const_cast<char **>(cargv);
2288 :
2289 1 : advgetopt::options_environment options;
2290 1 : options.f_project_name = "unittest";
2291 1 : options.f_options = options_list;
2292 1 : options.f_options_files_directory = "/etc/advgetopt";
2293 1 : options.f_configuration_files = nullptr;
2294 1 : options.f_configuration_filename = "advgetopt.conf";
2295 1 : options.f_configuration_directories = nullptr;
2296 1 : options.f_help_header = "Usage: test usage: %*e";
2297 1 : options.f_help_footer = "Percent Environment Variable: %*e";
2298 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2299 1 : options.f_version = "2.0.1-%*e";
2300 1 : options.f_license = "MIT-%*e";
2301 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*e";
2302 1 : options.f_build_date = "Jun 4 2019 %*e";
2303 1 : options.f_build_time = "23:02:36 %*e";
2304 :
2305 2 : advgetopt::getopt opt(options, argc, argv);
2306 :
2307 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2308 :
2309 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2310 : advgetopt::getopt::breakup_line(
2311 : "Usage: test usage: ADVGETOPT_TEST_OPTIONS (not set)"
2312 : , 0
2313 : , advgetopt::getopt::get_line_width())
2314 : + advgetopt::getopt::format_usage_string(
2315 : "--verbose"
2316 : , "inform you of what we're currently working on:"
2317 : " ADVGETOPT_TEST_OPTIONS (not set)."
2318 : , 30
2319 : , advgetopt::getopt::get_line_width()) + "\n"
2320 : + advgetopt::getopt::breakup_line(
2321 : "Percent Environment Variable: ADVGETOPT_TEST_OPTIONS (not set)"
2322 : , 0
2323 : , advgetopt::getopt::get_line_width())
2324 : );
2325 : }
2326 : CATCH_END_SECTION()
2327 :
2328 24 : CATCH_START_SECTION("Percent Environment Variable (nullptr, variable set)")
2329 : {
2330 2 : snap::safe_setenv env("ADVGETOPT_TEST_OPTIONS", "--verbose");
2331 :
2332 1 : const advgetopt::option options_list[] =
2333 : {
2334 : advgetopt::define_option(
2335 : advgetopt::Name("verbose")
2336 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2337 : , advgetopt::Help("inform you of what we're currently working on: %e.")
2338 : ),
2339 : advgetopt::end_options()
2340 : };
2341 1 : char const * cargv[] =
2342 : {
2343 : "tests/unittests/usage",
2344 : nullptr
2345 : };
2346 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2347 1 : char ** argv = const_cast<char **>(cargv);
2348 :
2349 1 : advgetopt::options_environment options;
2350 1 : options.f_project_name = "unittest";
2351 1 : options.f_options = options_list;
2352 1 : options.f_options_files_directory = "/etc/advgetopt";
2353 1 : options.f_configuration_files = nullptr;
2354 1 : options.f_configuration_filename = "advgetopt.conf";
2355 1 : options.f_configuration_directories = nullptr;
2356 1 : options.f_help_header = "Usage: test usage: %e";
2357 1 : options.f_help_footer = "Percent Environment Variable: %e";
2358 1 : options.f_environment_variable_name = nullptr;
2359 1 : options.f_version = "2.0.1-%e";
2360 1 : options.f_license = "MIT-%e";
2361 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %e";
2362 1 : options.f_build_date = "Jun 4 2019 %e";
2363 1 : options.f_build_time = "23:02:36 %e";
2364 :
2365 2 : advgetopt::getopt opt(options, argc, argv);
2366 :
2367 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2368 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2369 : "Usage: test usage: \n"
2370 : " --verbose inform you of what we're currently working on: .\n"
2371 : "\n"
2372 : "Percent Environment Variable: \n"
2373 : );
2374 : }
2375 : CATCH_END_SECTION()
2376 :
2377 24 : CATCH_START_SECTION("Percent Environment Variable (nullptr, variable not set)")
2378 : {
2379 1 : const advgetopt::option options_list[] =
2380 : {
2381 : advgetopt::define_option(
2382 : advgetopt::Name("verbose")
2383 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2384 : , advgetopt::Help("inform you of what we're currently working on: %e.")
2385 : ),
2386 : advgetopt::end_options()
2387 : };
2388 1 : char const * cargv[] =
2389 : {
2390 : "tests/unittests/usage",
2391 : nullptr
2392 : };
2393 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2394 1 : char ** argv = const_cast<char **>(cargv);
2395 :
2396 1 : advgetopt::options_environment options;
2397 1 : options.f_project_name = "unittest";
2398 1 : options.f_options = options_list;
2399 1 : options.f_options_files_directory = "/etc/advgetopt";
2400 1 : options.f_configuration_files = nullptr;
2401 1 : options.f_configuration_filename = "advgetopt.conf";
2402 1 : options.f_configuration_directories = nullptr;
2403 1 : options.f_help_header = "Usage: test usage: %e";
2404 1 : options.f_help_footer = "Percent Environment Variable: %e";
2405 1 : options.f_environment_variable_name = nullptr;
2406 1 : options.f_version = "2.0.1-%e";
2407 1 : options.f_license = "MIT-%e";
2408 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %e";
2409 1 : options.f_build_date = "Jun 4 2019 %e";
2410 1 : options.f_build_time = "23:02:36 %e";
2411 :
2412 2 : advgetopt::getopt opt(options, argc, argv);
2413 :
2414 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2415 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2416 : "Usage: test usage: \n"
2417 : " --verbose inform you of what we're currently working on: .\n"
2418 : "\n"
2419 : "Percent Environment Variable: \n"
2420 : );
2421 : }
2422 : CATCH_END_SECTION()
2423 :
2424 24 : CATCH_START_SECTION("Percent Asterisk Environment Variable (nullptr, variable set)")
2425 : {
2426 2 : snap::safe_setenv env("ADVGETOPT_TEST_OPTIONS", "--verbose");
2427 :
2428 1 : const advgetopt::option options_list[] =
2429 : {
2430 : advgetopt::define_option(
2431 : advgetopt::Name("verbose")
2432 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2433 : , advgetopt::Help("inform you of what we're currently working on: %*e.")
2434 : ),
2435 : advgetopt::end_options()
2436 : };
2437 1 : char const * cargv[] =
2438 : {
2439 : "tests/unittests/usage",
2440 : nullptr
2441 : };
2442 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2443 1 : char ** argv = const_cast<char **>(cargv);
2444 :
2445 1 : advgetopt::options_environment options;
2446 1 : options.f_project_name = "unittest";
2447 1 : options.f_options = options_list;
2448 1 : options.f_options_files_directory = "/etc/advgetopt";
2449 1 : options.f_configuration_files = nullptr;
2450 1 : options.f_configuration_filename = "advgetopt.conf";
2451 1 : options.f_configuration_directories = nullptr;
2452 1 : options.f_help_header = "Usage: test usage: %*e";
2453 1 : options.f_help_footer = "Percent Environment Variable: %*e";
2454 1 : options.f_environment_variable_name = nullptr;
2455 1 : options.f_version = "2.0.1-%*e";
2456 1 : options.f_license = "MIT-%*e";
2457 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*e";
2458 1 : options.f_build_date = "Jun 4 2019 %*e";
2459 1 : options.f_build_time = "23:02:36 %*e";
2460 :
2461 2 : advgetopt::getopt opt(options, argc, argv);
2462 :
2463 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2464 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2465 : "Usage: test usage: \n"
2466 : " --verbose inform you of what we're currently working on: .\n"
2467 : "\n"
2468 : "Percent Environment Variable: \n"
2469 : );
2470 : }
2471 : CATCH_END_SECTION()
2472 :
2473 24 : CATCH_START_SECTION("Percent Asterisk Environment Variable (nullptr, variable not set)")
2474 : {
2475 1 : const advgetopt::option options_list[] =
2476 : {
2477 : advgetopt::define_option(
2478 : advgetopt::Name("verbose")
2479 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2480 : , advgetopt::Help("inform you of what we're currently working on: %*e.")
2481 : ),
2482 : advgetopt::end_options()
2483 : };
2484 1 : char const * cargv[] =
2485 : {
2486 : "tests/unittests/usage",
2487 : nullptr
2488 : };
2489 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2490 1 : char ** argv = const_cast<char **>(cargv);
2491 :
2492 1 : advgetopt::options_environment options;
2493 1 : options.f_project_name = "unittest";
2494 1 : options.f_options = options_list;
2495 1 : options.f_options_files_directory = "/etc/advgetopt";
2496 1 : options.f_configuration_files = nullptr;
2497 1 : options.f_configuration_filename = "advgetopt.conf";
2498 1 : options.f_configuration_directories = nullptr;
2499 1 : options.f_help_header = "Usage: test usage: %*e";
2500 1 : options.f_help_footer = "Percent Environment Variable: %*e";
2501 1 : options.f_environment_variable_name = nullptr;
2502 1 : options.f_version = "2.0.1-%*e";
2503 1 : options.f_license = "MIT-%*e";
2504 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*e";
2505 1 : options.f_build_date = "Jun 4 2019 %*e";
2506 1 : options.f_build_time = "23:02:36 %*e";
2507 :
2508 2 : advgetopt::getopt opt(options, argc, argv);
2509 :
2510 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2511 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2512 : "Usage: test usage: \n"
2513 : " --verbose inform you of what we're currently working on: .\n"
2514 : "\n"
2515 : "Percent Environment Variable: \n"
2516 : );
2517 : }
2518 : CATCH_END_SECTION()
2519 :
2520 24 : CATCH_START_SECTION("Percent Environment Variable (empty string, variable set)")
2521 : {
2522 2 : snap::safe_setenv env("ADVGETOPT_TEST_OPTIONS", "--verbose");
2523 :
2524 1 : const advgetopt::option options_list[] =
2525 : {
2526 : advgetopt::define_option(
2527 : advgetopt::Name("verbose")
2528 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2529 : , advgetopt::Help("inform you of what we're currently working on: %e.")
2530 : ),
2531 : advgetopt::end_options()
2532 : };
2533 1 : char const * cargv[] =
2534 : {
2535 : "tests/unittests/usage",
2536 : nullptr
2537 : };
2538 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2539 1 : char ** argv = const_cast<char **>(cargv);
2540 :
2541 :
2542 1 : advgetopt::options_environment options;
2543 1 : options.f_project_name = "unittest";
2544 1 : options.f_options = options_list;
2545 1 : options.f_options_files_directory = "/etc/advgetopt";
2546 1 : options.f_configuration_files = nullptr;
2547 1 : options.f_configuration_filename = "advgetopt.conf";
2548 1 : options.f_configuration_directories = nullptr;
2549 1 : options.f_help_header = "Usage: test usage: %e";
2550 1 : options.f_help_footer = "Percent Environment Variable: %e";
2551 1 : options.f_environment_variable_name = "";
2552 1 : options.f_version = "2.0.1-%e";
2553 1 : options.f_license = "MIT-%e";
2554 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %e";
2555 1 : options.f_build_date = "Jun 4 2019 %e";
2556 1 : options.f_build_time = "23:02:36 %e";
2557 :
2558 2 : advgetopt::getopt opt(options, argc, argv);
2559 :
2560 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2561 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2562 : "Usage: test usage: \n"
2563 : " --verbose inform you of what we're currently working on: .\n"
2564 : "\n"
2565 : "Percent Environment Variable: \n"
2566 : );
2567 : }
2568 : CATCH_END_SECTION()
2569 :
2570 24 : CATCH_START_SECTION("Percent Environment Variable (empty string, variable not set)")
2571 : {
2572 1 : const advgetopt::option options_list[] =
2573 : {
2574 : advgetopt::define_option(
2575 : advgetopt::Name("verbose")
2576 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2577 : , advgetopt::Help("inform you of what we're currently working on: %e.")
2578 : ),
2579 : advgetopt::end_options()
2580 : };
2581 1 : char const * cargv[] =
2582 : {
2583 : "tests/unittests/usage",
2584 : nullptr
2585 : };
2586 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2587 1 : char ** argv = const_cast<char **>(cargv);
2588 :
2589 :
2590 1 : advgetopt::options_environment options;
2591 1 : options.f_project_name = "unittest";
2592 1 : options.f_options = options_list;
2593 1 : options.f_options_files_directory = "/etc/advgetopt";
2594 1 : options.f_configuration_files = nullptr;
2595 1 : options.f_configuration_filename = "advgetopt.conf";
2596 1 : options.f_configuration_directories = nullptr;
2597 1 : options.f_help_header = "Usage: test usage: %e";
2598 1 : options.f_help_footer = "Percent Environment Variable: %e";
2599 1 : options.f_environment_variable_name = "";
2600 1 : options.f_version = "2.0.1-%e";
2601 1 : options.f_license = "MIT-%e";
2602 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %e";
2603 1 : options.f_build_date = "Jun 4 2019 %e";
2604 1 : options.f_build_time = "23:02:36 %e";
2605 :
2606 2 : advgetopt::getopt opt(options, argc, argv);
2607 :
2608 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2609 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2610 : "Usage: test usage: \n"
2611 : " --verbose inform you of what we're currently working on: .\n"
2612 : "\n"
2613 : "Percent Environment Variable: \n"
2614 : );
2615 : }
2616 : CATCH_END_SECTION()
2617 :
2618 24 : CATCH_START_SECTION("Percent Asterisk Environment Variable (empty string, variable set)")
2619 : {
2620 2 : snap::safe_setenv env("ADVGETOPT_TEST_OPTIONS", "--verbose");
2621 :
2622 1 : const advgetopt::option options_list[] =
2623 : {
2624 : advgetopt::define_option(
2625 : advgetopt::Name("verbose")
2626 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2627 : , advgetopt::Help("inform you of what we're currently working on: %*e.")
2628 : ),
2629 : advgetopt::end_options()
2630 : };
2631 1 : char const * cargv[] =
2632 : {
2633 : "tests/unittests/usage",
2634 : nullptr
2635 : };
2636 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2637 1 : char ** argv = const_cast<char **>(cargv);
2638 :
2639 1 : advgetopt::options_environment options;
2640 1 : options.f_project_name = "unittest";
2641 1 : options.f_options = options_list;
2642 1 : options.f_options_files_directory = "/etc/advgetopt";
2643 1 : options.f_configuration_files = nullptr;
2644 1 : options.f_configuration_filename = "advgetopt.conf";
2645 1 : options.f_configuration_directories = nullptr;
2646 1 : options.f_help_header = "Usage: test usage: %*e";
2647 1 : options.f_help_footer = "Percent Environment Variable: %*e";
2648 1 : options.f_environment_variable_name = "";
2649 1 : options.f_version = "2.0.1-%*e";
2650 1 : options.f_license = "MIT-%*e";
2651 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*e";
2652 1 : options.f_build_date = "Jun 4 2019 %*e";
2653 1 : options.f_build_time = "23:02:36 %*e";
2654 :
2655 2 : advgetopt::getopt opt(options, argc, argv);
2656 :
2657 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2658 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2659 : "Usage: test usage: \n"
2660 : " --verbose inform you of what we're currently working on: .\n"
2661 : "\n"
2662 : "Percent Environment Variable: \n"
2663 : );
2664 : }
2665 : CATCH_END_SECTION()
2666 :
2667 24 : CATCH_START_SECTION("Percent Asterisk Environment Variable (empty string, variable not set)")
2668 : {
2669 1 : const advgetopt::option options_list[] =
2670 : {
2671 : advgetopt::define_option(
2672 : advgetopt::Name("verbose")
2673 : , advgetopt::Flags(advgetopt::var_flags<advgetopt::GETOPT_FLAG_FLAG>())
2674 : , advgetopt::Help("inform you of what we're currently working on: %*e.")
2675 : ),
2676 : advgetopt::end_options()
2677 : };
2678 1 : char const * cargv[] =
2679 : {
2680 : "tests/unittests/usage",
2681 : nullptr
2682 : };
2683 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2684 1 : char ** argv = const_cast<char **>(cargv);
2685 :
2686 1 : advgetopt::options_environment options;
2687 1 : options.f_project_name = "unittest";
2688 1 : options.f_options = options_list;
2689 1 : options.f_options_files_directory = "/etc/advgetopt";
2690 1 : options.f_configuration_files = nullptr;
2691 1 : options.f_configuration_filename = "advgetopt.conf";
2692 1 : options.f_configuration_directories = nullptr;
2693 1 : options.f_help_header = "Usage: test usage: %*e";
2694 1 : options.f_help_footer = "Percent Environment Variable: %*e";
2695 1 : options.f_environment_variable_name = "";
2696 1 : options.f_version = "2.0.1-%*e";
2697 1 : options.f_license = "MIT-%*e";
2698 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*e";
2699 1 : options.f_build_date = "Jun 4 2019 %*e";
2700 1 : options.f_build_time = "23:02:36 %*e";
2701 :
2702 2 : advgetopt::getopt opt(options, argc, argv);
2703 :
2704 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2705 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2706 : "Usage: test usage: \n"
2707 : " --verbose inform you of what we're currently working on: .\n"
2708 : "\n"
2709 : "Percent Environment Variable: \n"
2710 : );
2711 : }
2712 : CATCH_END_SECTION()
2713 12 : }
2714 :
2715 :
2716 :
2717 :
2718 :
2719 8 : CATCH_TEST_CASE("help_string_configuration_files", "[getopt][usage][config]")
2720 : {
2721 12 : CATCH_START_SECTION("Percent Configuration Files with f (fully defined)")
2722 : {
2723 1 : const advgetopt::option options_list[] =
2724 : {
2725 : advgetopt::define_option(
2726 : advgetopt::Name("verbose")
2727 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
2728 : , advgetopt::Help("inform you of what we're currently working on: %f.")
2729 : ),
2730 : advgetopt::end_options()
2731 : };
2732 1 : char const * cargv[] =
2733 : {
2734 : "tests/unittests/usage",
2735 : "--verbose",
2736 : nullptr
2737 : };
2738 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2739 1 : char ** argv = const_cast<char **>(cargv);
2740 :
2741 1 : const char * const configuration_files[] =
2742 : {
2743 : "system.conf",
2744 : "advgetopt.conf",
2745 : "advgetopt.ini",
2746 : "user.config",
2747 : nullptr
2748 : };
2749 :
2750 1 : advgetopt::options_environment options;
2751 1 : options.f_project_name = "unittest";
2752 1 : options.f_options = options_list;
2753 1 : options.f_options_files_directory = "/etc/advgetopt";
2754 1 : options.f_configuration_files = configuration_files;
2755 1 : options.f_configuration_filename = "advgetopt.conf";
2756 1 : options.f_configuration_directories = nullptr;
2757 1 : options.f_help_header = "Usage: test usage: %f";
2758 1 : options.f_help_footer = "Percent Configuration Files: %f";
2759 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2760 1 : options.f_version = "2.0.1-%f";
2761 1 : options.f_license = "MIT-%f";
2762 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %f";
2763 1 : options.f_build_date = "Jun 4 2019 %f";
2764 1 : options.f_build_time = "23:02:36 %f";
2765 :
2766 2 : advgetopt::getopt opt(options, argc, argv);
2767 :
2768 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2769 :
2770 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2771 : advgetopt::getopt::breakup_line(
2772 : "Usage: test usage: system.conf"
2773 : , 0
2774 : , advgetopt::getopt::get_line_width())
2775 : + advgetopt::getopt::format_usage_string(
2776 : "--verbose"
2777 : , "inform you of what we're currently working on: system.conf."
2778 : , 30
2779 : , advgetopt::getopt::get_line_width()) + "\n"
2780 : + advgetopt::getopt::breakup_line(
2781 : "Percent Configuration Files: system.conf"
2782 : , 0
2783 : , advgetopt::getopt::get_line_width())
2784 : );
2785 : }
2786 : CATCH_END_SECTION()
2787 :
2788 12 : CATCH_START_SECTION("Percent Asterisk Configuration Files with f (fully defined)")
2789 : {
2790 1 : const advgetopt::option options_list[] =
2791 : {
2792 : advgetopt::define_option(
2793 : advgetopt::Name("verbose")
2794 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
2795 : , advgetopt::Help("inform you of what we're currently working on: %*f.")
2796 : ),
2797 : advgetopt::end_options()
2798 : };
2799 1 : char const * cargv[] =
2800 : {
2801 : "tests/unittests/usage",
2802 : "--verbose",
2803 : nullptr
2804 : };
2805 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2806 1 : char ** argv = const_cast<char **>(cargv);
2807 :
2808 1 : const char * const configuration_files[] =
2809 : {
2810 : "system.conf",
2811 : "advgetopt.conf",
2812 : "advgetopt.ini",
2813 : "user.config",
2814 : nullptr
2815 : };
2816 :
2817 1 : advgetopt::options_environment options;
2818 1 : options.f_project_name = "unittest";
2819 1 : options.f_options = options_list;
2820 1 : options.f_options_files_directory = "/etc/advgetopt";
2821 1 : options.f_configuration_files = configuration_files;
2822 1 : options.f_configuration_filename = "advgetopt.conf";
2823 1 : options.f_configuration_directories = nullptr;
2824 1 : options.f_help_header = "Usage: test usage: %*f";
2825 1 : options.f_help_footer = "Percent Configuration Files: %*f";
2826 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2827 1 : options.f_version = "2.0.1-%*f";
2828 1 : options.f_license = "MIT-%*f";
2829 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*f";
2830 1 : options.f_build_date = "Jun 4 2019 %*f";
2831 1 : options.f_build_time = "23:02:36 %*f";
2832 :
2833 2 : advgetopt::getopt opt(options, argc, argv);
2834 :
2835 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2836 :
2837 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2838 : advgetopt::getopt::breakup_line(
2839 : "Usage: test usage: system.conf, advgetopt.conf,"
2840 : " advgetopt.ini, user.config"
2841 : , 0
2842 : , advgetopt::getopt::get_line_width())
2843 : + advgetopt::getopt::format_usage_string(
2844 : "--verbose"
2845 : , "inform you of what we're currently working on:"
2846 : " system.conf, advgetopt.conf, advgetopt.ini,"
2847 : " user.config."
2848 : , 30
2849 : , advgetopt::getopt::get_line_width()) + "\n"
2850 : + advgetopt::getopt::breakup_line(
2851 : "Percent Configuration Files: system.conf, advgetopt.conf,"
2852 : " advgetopt.ini, user.config"
2853 : , 0
2854 : , advgetopt::getopt::get_line_width())
2855 : );
2856 : }
2857 : CATCH_END_SECTION()
2858 :
2859 12 : CATCH_START_SECTION("Percent Configuration Files with f (nullptr)")
2860 : {
2861 1 : const advgetopt::option options_list[] =
2862 : {
2863 : advgetopt::define_option(
2864 : advgetopt::Name("verbose")
2865 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
2866 : , advgetopt::Help("inform you of what we're currently working on: %f.")
2867 : ),
2868 : advgetopt::end_options()
2869 : };
2870 1 : char const * cargv[] =
2871 : {
2872 : "tests/unittests/usage",
2873 : "--verbose",
2874 : nullptr
2875 : };
2876 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2877 1 : char ** argv = const_cast<char **>(cargv);
2878 :
2879 1 : advgetopt::options_environment options;
2880 1 : options.f_project_name = "unittest";
2881 1 : options.f_options = options_list;
2882 1 : options.f_options_files_directory = "/etc/advgetopt";
2883 1 : options.f_configuration_files = nullptr;
2884 1 : options.f_configuration_filename = "advgetopt.conf";
2885 1 : options.f_configuration_directories = nullptr;
2886 1 : options.f_help_header = "Usage: test usage: %f";
2887 1 : options.f_help_footer = "Percent Configuration Files: %f";
2888 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2889 1 : options.f_version = "2.0.1-%f";
2890 1 : options.f_license = "MIT-%f";
2891 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %f";
2892 1 : options.f_build_date = "Jun 4 2019 %f";
2893 1 : options.f_build_time = "23:02:36 %f";
2894 :
2895 2 : advgetopt::getopt opt(options, argc, argv);
2896 :
2897 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2898 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2899 : "Usage: test usage: \n"
2900 : " --verbose inform you of what we're currently working on: .\n"
2901 : "\n"
2902 : "Percent Configuration Files: \n"
2903 : );
2904 : }
2905 : CATCH_END_SECTION()
2906 :
2907 12 : CATCH_START_SECTION("Percent Asterisk Configuration Files with f (nullptr)")
2908 : {
2909 1 : const advgetopt::option options_list[] =
2910 : {
2911 : advgetopt::define_option(
2912 : advgetopt::Name("verbose")
2913 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
2914 : , advgetopt::Help("inform you of what we're currently working on: %*f.")
2915 : ),
2916 : advgetopt::end_options()
2917 : };
2918 1 : char const * cargv[] =
2919 : {
2920 : "tests/unittests/usage",
2921 : "--verbose",
2922 : nullptr
2923 : };
2924 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2925 1 : char ** argv = const_cast<char **>(cargv);
2926 :
2927 1 : advgetopt::options_environment options;
2928 1 : options.f_project_name = "unittest";
2929 1 : options.f_options = options_list;
2930 1 : options.f_options_files_directory = "/etc/advgetopt";
2931 1 : options.f_configuration_files = nullptr;
2932 1 : options.f_configuration_filename = "advgetopt.conf";
2933 1 : options.f_configuration_directories = nullptr;
2934 1 : options.f_help_header = "Usage: test usage: %*f";
2935 1 : options.f_help_footer = "Percent Configuration Files: %*f";
2936 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2937 1 : options.f_version = "2.0.1-%*f";
2938 1 : options.f_license = "MIT-%*f";
2939 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*f";
2940 1 : options.f_build_date = "Jun 4 2019 %*f";
2941 1 : options.f_build_time = "23:02:36 %*f";
2942 :
2943 2 : advgetopt::getopt opt(options, argc, argv);
2944 :
2945 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2946 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
2947 : "Usage: test usage: \n"
2948 : " --verbose inform you of what we're currently working on: .\n"
2949 : "\n"
2950 : "Percent Configuration Files: \n"
2951 : );
2952 : }
2953 : CATCH_END_SECTION()
2954 :
2955 12 : CATCH_START_SECTION("Percent Configuration Files with f (empty array)")
2956 : {
2957 1 : const advgetopt::option options_list[] =
2958 : {
2959 : advgetopt::define_option(
2960 : advgetopt::Name("verbose")
2961 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
2962 : , advgetopt::Help("inform you of what we're currently working on: %f.")
2963 : ),
2964 : advgetopt::end_options()
2965 : };
2966 1 : char const * cargv[] =
2967 : {
2968 : "tests/unittests/usage",
2969 : "--verbose",
2970 : nullptr
2971 : };
2972 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
2973 1 : char ** argv = const_cast<char **>(cargv);
2974 :
2975 1 : const char * const configuration_files[] =
2976 : {
2977 : nullptr
2978 : };
2979 :
2980 1 : advgetopt::options_environment options;
2981 1 : options.f_project_name = "unittest";
2982 1 : options.f_options = options_list;
2983 1 : options.f_options_files_directory = "/etc/advgetopt";
2984 1 : options.f_configuration_files = configuration_files;
2985 1 : options.f_configuration_filename = "advgetopt.conf";
2986 1 : options.f_configuration_directories = nullptr;
2987 1 : options.f_help_header = "Usage: test usage: %f";
2988 1 : options.f_help_footer = "Percent Configuration Files: %f";
2989 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
2990 1 : options.f_version = "2.0.1-%f";
2991 1 : options.f_license = "MIT-%f";
2992 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %f";
2993 1 : options.f_build_date = "Jun 4 2019 %f";
2994 1 : options.f_build_time = "23:02:36 %f";
2995 :
2996 2 : advgetopt::getopt opt(options, argc, argv);
2997 :
2998 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
2999 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3000 : "Usage: test usage: \n"
3001 : " --verbose inform you of what we're currently working on: .\n"
3002 : "\n"
3003 : "Percent Configuration Files: \n"
3004 : );
3005 : }
3006 : CATCH_END_SECTION()
3007 :
3008 12 : CATCH_START_SECTION("Percent Asterisk Configuration Files with f (empty array)")
3009 : {
3010 1 : const advgetopt::option options_list[] =
3011 : {
3012 : advgetopt::define_option(
3013 : advgetopt::Name("verbose")
3014 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3015 : , advgetopt::Help("inform you of what we're currently working on: %*f.")
3016 : ),
3017 : advgetopt::end_options()
3018 : };
3019 1 : char const * cargv[] =
3020 : {
3021 : "tests/unittests/usage",
3022 : "--verbose",
3023 : nullptr
3024 : };
3025 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3026 1 : char ** argv = const_cast<char **>(cargv);
3027 :
3028 1 : const char * const configuration_files[] =
3029 : {
3030 : nullptr
3031 : };
3032 :
3033 1 : advgetopt::options_environment options;
3034 1 : options.f_project_name = "unittest";
3035 1 : options.f_options = options_list;
3036 1 : options.f_options_files_directory = "/etc/advgetopt";
3037 1 : options.f_configuration_files = configuration_files;
3038 1 : options.f_configuration_filename = "advgetopt.conf";
3039 1 : options.f_configuration_directories = nullptr;
3040 1 : options.f_help_header = "Usage: test usage: %*f";
3041 1 : options.f_help_footer = "Percent Configuration Files: %*f";
3042 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3043 1 : options.f_version = "2.0.1-%*f";
3044 1 : options.f_license = "MIT-%*f";
3045 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*f";
3046 1 : options.f_build_date = "Jun 4 2019 %*f";
3047 1 : options.f_build_time = "23:02:36 %*f";
3048 :
3049 2 : advgetopt::getopt opt(options, argc, argv);
3050 :
3051 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3052 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3053 : "Usage: test usage: \n"
3054 : " --verbose inform you of what we're currently working on: .\n"
3055 : "\n"
3056 : "Percent Configuration Files: \n"
3057 : );
3058 : }
3059 : CATCH_END_SECTION()
3060 6 : }
3061 :
3062 :
3063 :
3064 :
3065 9 : CATCH_TEST_CASE("help_string_configuration_files_functions", "[getopt][usage][config]")
3066 : {
3067 14 : CATCH_START_SECTION("Percent Configuration Files with g (fully defined)")
3068 : {
3069 1 : SNAP_CATCH2_NAMESPACE::init_tmp_dir("config_filenames", "existing_g");
3070 :
3071 : {
3072 2 : std::ofstream config_file;
3073 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
3074 1 : CATCH_REQUIRE(config_file.good());
3075 1 : config_file <<
3076 : "# Auto-generated\n"
3077 : ;
3078 : }
3079 :
3080 : {
3081 2 : std::ofstream config_file;
3082 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_project_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
3083 1 : CATCH_REQUIRE(config_file.good());
3084 1 : config_file <<
3085 : "# Auto-generated\n"
3086 : ;
3087 : }
3088 :
3089 1 : const advgetopt::option options_list[] =
3090 : {
3091 : advgetopt::define_option(
3092 : advgetopt::Name("verbose")
3093 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3094 : , advgetopt::Help("inform you of what we're currently working on: %g.")
3095 : ),
3096 : advgetopt::end_options()
3097 : };
3098 1 : char const * cargv[] =
3099 : {
3100 : "tests/unittests/usage",
3101 : "--verbose",
3102 : nullptr
3103 : };
3104 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3105 1 : char ** argv = const_cast<char **>(cargv);
3106 :
3107 1 : const char * const configuration_files[] =
3108 : {
3109 : "system.conf",
3110 1 : SNAP_CATCH2_NAMESPACE::g_config_filename.c_str(),
3111 : "advgetopt.conf",
3112 : "advgetopt.ini",
3113 : "user.config",
3114 1 : SNAP_CATCH2_NAMESPACE::g_config_project_filename.c_str(), // <- this is wrong, it should be done automatically, but we have a name mismatch...
3115 : nullptr
3116 2 : };
3117 :
3118 1 : advgetopt::options_environment options;
3119 1 : options.f_project_name = "unittest"; // name mismatch on purpose
3120 1 : options.f_options = options_list;
3121 1 : options.f_options_files_directory = "/etc/advgetopt";
3122 1 : options.f_configuration_files = configuration_files;
3123 1 : options.f_configuration_filename = "advgetopt.conf";
3124 1 : options.f_configuration_directories = nullptr;
3125 1 : options.f_help_header = "Usage: test usage: %g";
3126 1 : options.f_help_footer = "Percent Configuration Files: %g";
3127 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3128 1 : options.f_version = "2.0.1-%g";
3129 1 : options.f_license = "MIT-%g";
3130 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %g";
3131 1 : options.f_build_date = "Jun 4 2019 %g";
3132 1 : options.f_build_time = "23:02:36 %g";
3133 :
3134 2 : advgetopt::getopt opt(options, argc, argv);
3135 :
3136 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3137 :
3138 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3139 : advgetopt::getopt::breakup_line(
3140 : "Usage: test usage: "
3141 : + SNAP_CATCH2_NAMESPACE::g_config_filename
3142 : + ", "
3143 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
3144 : , 0
3145 : , advgetopt::getopt::get_line_width())
3146 : + advgetopt::getopt::format_usage_string(
3147 : "--verbose", "inform you of what we're currently working on: "
3148 : + SNAP_CATCH2_NAMESPACE::g_config_filename + ", "
3149 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename + "."
3150 : , 30
3151 : , advgetopt::getopt::get_line_width()) + "\n"
3152 : + advgetopt::getopt::breakup_line(
3153 : "Percent Configuration Files: "
3154 : + SNAP_CATCH2_NAMESPACE::g_config_filename
3155 : + ", "
3156 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
3157 : , 0
3158 : , advgetopt::getopt::get_line_width())
3159 : );
3160 : }
3161 : CATCH_END_SECTION()
3162 :
3163 14 : CATCH_START_SECTION("Percent Configuration Files with g (fully defined)")
3164 : {
3165 1 : SNAP_CATCH2_NAMESPACE::init_tmp_dir("config_file_names", "with_existing_g");
3166 :
3167 : {
3168 2 : std::ofstream config_file;
3169 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
3170 1 : CATCH_REQUIRE(config_file.good());
3171 1 : config_file <<
3172 : "# Auto-generated\n"
3173 : ;
3174 : }
3175 :
3176 : {
3177 2 : std::ofstream config_file;
3178 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_project_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
3179 1 : CATCH_REQUIRE(config_file.good());
3180 1 : config_file <<
3181 : "# Auto-generated\n"
3182 : ;
3183 : }
3184 :
3185 1 : const advgetopt::option options_list[] =
3186 : {
3187 : advgetopt::define_option(
3188 : advgetopt::Name("verbose")
3189 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3190 : , advgetopt::Help("inform you of what we're currently working on: %g.")
3191 : ),
3192 : advgetopt::end_options()
3193 : };
3194 1 : char const * cargv[] =
3195 : {
3196 : "tests/unittests/usage",
3197 : "--verbose",
3198 : nullptr
3199 : };
3200 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3201 1 : char ** argv = const_cast<char **>(cargv);
3202 :
3203 1 : const char * const configuration_files[] =
3204 : {
3205 : "system.conf",
3206 1 : SNAP_CATCH2_NAMESPACE::g_config_filename.c_str(),
3207 : "advgetopt.conf",
3208 : "advgetopt.ini",
3209 : "user.config",
3210 : nullptr
3211 1 : };
3212 :
3213 1 : advgetopt::options_environment options;
3214 1 : options.f_project_name = "config_file_names";
3215 1 : options.f_options = options_list;
3216 1 : options.f_options_files_directory = "/etc/advgetopt";
3217 1 : options.f_configuration_files = configuration_files;
3218 1 : options.f_configuration_filename = "advgetopt.conf";
3219 1 : options.f_configuration_directories = nullptr;
3220 1 : options.f_help_header = "Usage: test usage: %g";
3221 1 : options.f_help_footer = "Percent Configuration Files: %g";
3222 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3223 1 : options.f_version = "2.0.1-%g";
3224 1 : options.f_license = "MIT-%g";
3225 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %g";
3226 1 : options.f_build_date = "Jun 4 2019 %g";
3227 1 : options.f_build_time = "23:02:36 %g";
3228 :
3229 2 : advgetopt::getopt opt(options, argc, argv);
3230 :
3231 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3232 :
3233 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3234 : advgetopt::getopt::breakup_line(
3235 : "Usage: test usage: "
3236 : + SNAP_CATCH2_NAMESPACE::g_config_filename
3237 : + ", "
3238 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
3239 : , 0
3240 : , advgetopt::getopt::get_line_width())
3241 : + advgetopt::getopt::format_usage_string(
3242 : "--verbose", "inform you of what we're currently working on: "
3243 : + SNAP_CATCH2_NAMESPACE::g_config_filename + ", "
3244 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename + "."
3245 : , 30
3246 : , advgetopt::getopt::get_line_width()) + "\n"
3247 : + advgetopt::getopt::breakup_line(
3248 : "Percent Configuration Files: "
3249 : + SNAP_CATCH2_NAMESPACE::g_config_filename
3250 : + ", "
3251 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
3252 : , 0
3253 : , advgetopt::getopt::get_line_width())
3254 : );
3255 : }
3256 : CATCH_END_SECTION()
3257 :
3258 14 : CATCH_START_SECTION("Percent Asterisk Configuration Files with g (fully defined)")
3259 : {
3260 1 : const advgetopt::option options_list[] =
3261 : {
3262 : advgetopt::define_option(
3263 : advgetopt::Name("verbose")
3264 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3265 : , advgetopt::Help("inform you of what we're currently working on: %*g.")
3266 : ),
3267 : advgetopt::end_options()
3268 : };
3269 1 : char const * cargv[] =
3270 : {
3271 : "tests/unittests/usage",
3272 : "--verbose",
3273 : nullptr
3274 : };
3275 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3276 1 : char ** argv = const_cast<char **>(cargv);
3277 :
3278 1 : const char * const configuration_files[] =
3279 : {
3280 : "system.conf",
3281 : "advgetopt.conf",
3282 : "advgetopt.ini",
3283 : "user.config",
3284 : nullptr
3285 : };
3286 :
3287 1 : advgetopt::options_environment options;
3288 1 : options.f_project_name = "unittest";
3289 1 : options.f_options = options_list;
3290 1 : options.f_options_files_directory = "/etc/advgetopt";
3291 1 : options.f_configuration_files = configuration_files;
3292 1 : options.f_configuration_filename = "advgetopt.conf";
3293 1 : options.f_configuration_directories = nullptr;
3294 1 : options.f_help_header = "Usage: test usage: %*g";
3295 1 : options.f_help_footer = "Percent Configuration Files: %*g";
3296 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3297 1 : options.f_version = "2.0.1-%*g";
3298 1 : options.f_license = "MIT-%*g";
3299 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*g";
3300 1 : options.f_build_date = "Jun 4 2019 %*g";
3301 1 : options.f_build_time = "23:02:36 %*g";
3302 :
3303 2 : advgetopt::getopt opt(options, argc, argv);
3304 :
3305 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3306 :
3307 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3308 : advgetopt::getopt::breakup_line(
3309 : "Usage: test usage: system.conf, unittest.d/50-system.conf,"
3310 : " advgetopt.conf, unittest.d/50-advgetopt.conf, advgetopt.ini,"
3311 : " unittest.d/50-advgetopt.ini, user.config,"
3312 : " unittest.d/50-user.config"
3313 : , 0
3314 : , advgetopt::getopt::get_line_width())
3315 : + advgetopt::getopt::format_usage_string(
3316 : "--verbose"
3317 : , "inform you of what we're currently working on:"
3318 : " system.conf, unittest.d/50-system.conf,"
3319 : " advgetopt.conf, unittest.d/50-advgetopt.conf,"
3320 : " advgetopt.ini, unittest.d/50-advgetopt.ini,"
3321 : " user.config, unittest.d/50-user.config."
3322 : , 30
3323 : , advgetopt::getopt::get_line_width()) + "\n"
3324 : + advgetopt::getopt::breakup_line(
3325 : "Percent Configuration Files: system.conf, unittest.d/50-system.conf,"
3326 : " advgetopt.conf, unittest.d/50-advgetopt.conf, advgetopt.ini,"
3327 : " unittest.d/50-advgetopt.ini, user.config, unittest.d/50-user.config"
3328 : , 0
3329 : , advgetopt::getopt::get_line_width())
3330 : );
3331 : }
3332 : CATCH_END_SECTION()
3333 :
3334 14 : CATCH_START_SECTION("Percent Configuration Files with g (nullptr)")
3335 : {
3336 1 : const advgetopt::option options_list[] =
3337 : {
3338 : advgetopt::define_option(
3339 : advgetopt::Name("verbose")
3340 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3341 : , advgetopt::Help("inform you of what we're currently working on: %g.")
3342 : ),
3343 : advgetopt::end_options()
3344 : };
3345 1 : char const * cargv[] =
3346 : {
3347 : "tests/unittests/usage",
3348 : "--verbose",
3349 : nullptr
3350 : };
3351 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3352 1 : char ** argv = const_cast<char **>(cargv);
3353 :
3354 1 : advgetopt::options_environment options;
3355 1 : options.f_project_name = "unittest";
3356 1 : options.f_options = options_list;
3357 1 : options.f_options_files_directory = "/etc/advgetopt";
3358 1 : options.f_configuration_files = nullptr;
3359 1 : options.f_configuration_filename = "advgetopt.conf";
3360 1 : options.f_configuration_directories = nullptr;
3361 1 : options.f_help_header = "Usage: test usage: %g";
3362 1 : options.f_help_footer = "Percent Configuration Files: %g";
3363 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3364 1 : options.f_version = "2.0.1-%g";
3365 1 : options.f_license = "MIT-%g";
3366 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %g";
3367 1 : options.f_build_date = "Jun 4 2019 %g";
3368 1 : options.f_build_time = "23:02:36 %g";
3369 :
3370 2 : advgetopt::getopt opt(options, argc, argv);
3371 :
3372 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3373 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3374 : "Usage: test usage: \n"
3375 : " --verbose inform you of what we're currently working on: .\n"
3376 : "\n"
3377 : "Percent Configuration Files: \n"
3378 : );
3379 : }
3380 : CATCH_END_SECTION()
3381 :
3382 14 : CATCH_START_SECTION("Percent Asterisk Configuration Files with g (nullptr)")
3383 : {
3384 1 : const advgetopt::option options_list[] =
3385 : {
3386 : advgetopt::define_option(
3387 : advgetopt::Name("verbose")
3388 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3389 : , advgetopt::Help("inform you of what we're currently working on: %*g.")
3390 : ),
3391 : advgetopt::end_options()
3392 : };
3393 1 : char const * cargv[] =
3394 : {
3395 : "tests/unittests/usage",
3396 : "--verbose",
3397 : nullptr
3398 : };
3399 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3400 1 : char ** argv = const_cast<char **>(cargv);
3401 :
3402 1 : advgetopt::options_environment options;
3403 1 : options.f_project_name = "unittest";
3404 1 : options.f_options = options_list;
3405 1 : options.f_options_files_directory = "/etc/advgetopt";
3406 1 : options.f_configuration_files = nullptr;
3407 1 : options.f_configuration_filename = "advgetopt.conf";
3408 1 : options.f_configuration_directories = nullptr;
3409 1 : options.f_help_header = "Usage: test usage: %*g";
3410 1 : options.f_help_footer = "Percent Configuration Files: %*g";
3411 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3412 1 : options.f_version = "2.0.1-%*g";
3413 1 : options.f_license = "MIT-%*g";
3414 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*g";
3415 1 : options.f_build_date = "Jun 4 2019 %*g";
3416 1 : options.f_build_time = "23:02:36 %*g";
3417 :
3418 2 : advgetopt::getopt opt(options, argc, argv);
3419 :
3420 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3421 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3422 : "Usage: test usage: \n"
3423 : " --verbose inform you of what we're currently working on: .\n"
3424 : "\n"
3425 : "Percent Configuration Files: \n"
3426 : );
3427 : }
3428 : CATCH_END_SECTION()
3429 :
3430 14 : CATCH_START_SECTION("Percent Configuration Files with g (empty array)")
3431 : {
3432 1 : const advgetopt::option options_list[] =
3433 : {
3434 : advgetopt::define_option(
3435 : advgetopt::Name("verbose")
3436 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3437 : , advgetopt::Help("inform you of what we're currently working on: %g.")
3438 : ),
3439 : advgetopt::end_options()
3440 : };
3441 1 : char const * cargv[] =
3442 : {
3443 : "tests/unittests/usage",
3444 : "--verbose",
3445 : nullptr
3446 : };
3447 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3448 1 : char ** argv = const_cast<char **>(cargv);
3449 :
3450 1 : const char * const configuration_files[] =
3451 : {
3452 : nullptr
3453 : };
3454 :
3455 1 : advgetopt::options_environment options;
3456 1 : options.f_project_name = "unittest";
3457 1 : options.f_options = options_list;
3458 1 : options.f_options_files_directory = "/etc/advgetopt";
3459 1 : options.f_configuration_files = configuration_files;
3460 1 : options.f_configuration_filename = "advgetopt.conf";
3461 1 : options.f_configuration_directories = nullptr;
3462 1 : options.f_help_header = "Usage: test usage: %g";
3463 1 : options.f_help_footer = "Percent Configuration Files: %g";
3464 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3465 1 : options.f_version = "2.0.1-%g";
3466 1 : options.f_license = "MIT-%g";
3467 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %g";
3468 1 : options.f_build_date = "Jun 4 2019 %g";
3469 1 : options.f_build_time = "23:02:36 %g";
3470 :
3471 2 : advgetopt::getopt opt(options, argc, argv);
3472 :
3473 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3474 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3475 : "Usage: test usage: \n"
3476 : " --verbose inform you of what we're currently working on: .\n"
3477 : "\n"
3478 : "Percent Configuration Files: \n"
3479 : );
3480 : }
3481 : CATCH_END_SECTION()
3482 :
3483 14 : CATCH_START_SECTION("Percent Asterisk Configuration Files with g (empty array)")
3484 : {
3485 1 : const advgetopt::option options_list[] =
3486 : {
3487 : advgetopt::define_option(
3488 : advgetopt::Name("verbose")
3489 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3490 : , advgetopt::Help("inform you of what we're currently working on: %*g.")
3491 : ),
3492 : advgetopt::end_options()
3493 : };
3494 1 : char const * cargv[] =
3495 : {
3496 : "tests/unittests/usage",
3497 : "--verbose",
3498 : nullptr
3499 : };
3500 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3501 1 : char ** argv = const_cast<char **>(cargv);
3502 :
3503 1 : const char * const configuration_files[] =
3504 : {
3505 : nullptr
3506 : };
3507 :
3508 1 : advgetopt::options_environment options;
3509 1 : options.f_project_name = "unittest";
3510 1 : options.f_options = options_list;
3511 1 : options.f_options_files_directory = "/etc/advgetopt";
3512 1 : options.f_configuration_files = configuration_files;
3513 1 : options.f_configuration_filename = "advgetopt.conf";
3514 1 : options.f_configuration_directories = nullptr;
3515 1 : options.f_help_header = "Usage: test usage: %*g";
3516 1 : options.f_help_footer = "Percent Configuration Files: %*g";
3517 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3518 1 : options.f_version = "2.0.1-%*g";
3519 1 : options.f_license = "MIT-%*g";
3520 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*g";
3521 1 : options.f_build_date = "Jun 4 2019 %*g";
3522 1 : options.f_build_time = "23:02:36 %*g";
3523 :
3524 2 : advgetopt::getopt opt(options, argc, argv);
3525 :
3526 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3527 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3528 : "Usage: test usage: \n"
3529 : " --verbose inform you of what we're currently working on: .\n"
3530 : "\n"
3531 : "Percent Configuration Files: \n"
3532 : );
3533 : }
3534 : CATCH_END_SECTION()
3535 7 : }
3536 :
3537 :
3538 :
3539 :
3540 5 : CATCH_TEST_CASE("help_string_option_file_directory", "[getopt][usage][config]")
3541 : {
3542 6 : CATCH_START_SECTION("Percent Configuration Files with i (fully defined)")
3543 : {
3544 1 : const advgetopt::option options_list[] =
3545 : {
3546 : advgetopt::define_option(
3547 : advgetopt::Name("verbose")
3548 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3549 : , advgetopt::Help("inform you of what we're currently working on: %i.")
3550 : ),
3551 : advgetopt::end_options()
3552 : };
3553 1 : char const * cargv[] =
3554 : {
3555 : "tests/unittests/usage",
3556 : "--verbose",
3557 : nullptr
3558 : };
3559 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3560 1 : char ** argv = const_cast<char **>(cargv);
3561 :
3562 1 : const char * const configuration_files[] =
3563 : {
3564 : "advgetopt.conf",
3565 : "advgetopt.ini",
3566 : nullptr
3567 : };
3568 :
3569 1 : advgetopt::options_environment options;
3570 1 : options.f_project_name = "unittest";
3571 1 : options.f_options = options_list;
3572 1 : options.f_options_files_directory = "/opt/advgetopt/config";
3573 1 : options.f_configuration_files = configuration_files;
3574 1 : options.f_configuration_filename = "advgetopt.conf";
3575 1 : options.f_configuration_directories = nullptr;
3576 1 : options.f_help_header = "Usage: test usage: %i";
3577 1 : options.f_help_footer = "Percent Configuration Files: %i";
3578 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3579 1 : options.f_version = "2.0.1-%i";
3580 1 : options.f_license = "MIT-%i";
3581 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %i";
3582 1 : options.f_build_date = "Jun 4 2019 %i";
3583 1 : options.f_build_time = "23:02:36 %i";
3584 :
3585 2 : advgetopt::getopt opt(options, argc, argv);
3586 :
3587 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3588 :
3589 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3590 : "Usage: test usage: /opt/advgetopt/config/\n"
3591 : + advgetopt::getopt::format_usage_string(
3592 : "--verbose", "inform you of what we're currently working on: "
3593 : "/opt/advgetopt/config/."
3594 : , 30
3595 : , advgetopt::getopt::get_line_width()) + "\n"
3596 : + advgetopt::getopt::breakup_line(
3597 : "Percent Configuration Files: /opt/advgetopt/config/"
3598 : , 0
3599 : , advgetopt::getopt::get_line_width())
3600 : );
3601 : }
3602 : CATCH_END_SECTION()
3603 :
3604 6 : CATCH_START_SECTION("Percent Configuration Files with i (nullptr)")
3605 : {
3606 1 : const advgetopt::option options_list[] =
3607 : {
3608 : advgetopt::define_option(
3609 : advgetopt::Name("verbose")
3610 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3611 : , advgetopt::Help("inform you of what we're currently working on: %i.")
3612 : ),
3613 : advgetopt::end_options()
3614 : };
3615 1 : char const * cargv[] =
3616 : {
3617 : "tests/unittests/usage",
3618 : "--verbose",
3619 : nullptr
3620 : };
3621 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3622 1 : char ** argv = const_cast<char **>(cargv);
3623 :
3624 1 : const char * const configuration_files[] =
3625 : {
3626 : "/ignored/in/this/test",
3627 : nullptr
3628 : };
3629 :
3630 1 : advgetopt::options_environment options;
3631 1 : options.f_project_name = "unittest";
3632 1 : options.f_options = options_list;
3633 1 : options.f_options_files_directory = nullptr;
3634 1 : options.f_configuration_files = configuration_files;
3635 1 : options.f_configuration_filename = "advgetopt.conf";
3636 1 : options.f_configuration_directories = nullptr;
3637 1 : options.f_help_header = "Usage: test usage: %i";
3638 1 : options.f_help_footer = "Percent Configuration Files: %i";
3639 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3640 1 : options.f_version = "2.0.1-%i";
3641 1 : options.f_license = "MIT-%i";
3642 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %i";
3643 1 : options.f_build_date = "Jun 4 2019 %i";
3644 1 : options.f_build_time = "23:02:36 %i";
3645 :
3646 2 : advgetopt::getopt opt(options, argc, argv);
3647 :
3648 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3649 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3650 : advgetopt::getopt::breakup_line("Usage: test usage: /usr/share/advgetopt/options/", 0, advgetopt::getopt::get_line_width())
3651 : + advgetopt::getopt::format_usage_string(
3652 : "--verbose"
3653 : , "inform you of what we're currently working on: /usr/share/advgetopt/options/."
3654 : , 30
3655 : , advgetopt::getopt::get_line_width()) + "\n"
3656 : + advgetopt::getopt::breakup_line("Percent Configuration Files: /usr/share/advgetopt/options/", 0, advgetopt::getopt::get_line_width())
3657 : );
3658 : }
3659 : CATCH_END_SECTION()
3660 :
3661 6 : CATCH_START_SECTION("Percent Configuration Files with i (empty string)")
3662 : {
3663 1 : const advgetopt::option options_list[] =
3664 : {
3665 : advgetopt::define_option(
3666 : advgetopt::Name("verbose")
3667 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3668 : , advgetopt::Help("inform you of what we're currently working on: %i.")
3669 : ),
3670 : advgetopt::end_options()
3671 : };
3672 1 : char const * cargv[] =
3673 : {
3674 : "tests/unittests/usage",
3675 : "--verbose",
3676 : nullptr
3677 : };
3678 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3679 1 : char ** argv = const_cast<char **>(cargv);
3680 :
3681 1 : const char * const configuration_files[] =
3682 : {
3683 : "/ignored/in/this/test",
3684 : nullptr
3685 : };
3686 :
3687 1 : advgetopt::options_environment options;
3688 1 : options.f_project_name = "unittest";
3689 1 : options.f_options = options_list;
3690 1 : options.f_options_files_directory = "";
3691 1 : options.f_configuration_files = configuration_files;
3692 1 : options.f_configuration_filename = "advgetopt.conf";
3693 1 : options.f_configuration_directories = nullptr;
3694 1 : options.f_help_header = "Usage: test usage: %i";
3695 1 : options.f_help_footer = "Percent Configuration Files: %i";
3696 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3697 1 : options.f_version = "2.0.1-%i";
3698 1 : options.f_license = "MIT-%i";
3699 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %i";
3700 1 : options.f_build_date = "Jun 4 2019 %i";
3701 1 : options.f_build_time = "23:02:36 %i";
3702 :
3703 2 : advgetopt::getopt opt(options, argc, argv);
3704 :
3705 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3706 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3707 : advgetopt::getopt::breakup_line("Usage: test usage: /usr/share/advgetopt/options/", 0, advgetopt::getopt::get_line_width())
3708 : + advgetopt::getopt::format_usage_string(
3709 : "--verbose"
3710 : , "inform you of what we're currently working on: /usr/share/advgetopt/options/."
3711 : , 30
3712 : , advgetopt::getopt::get_line_width()) + "\n"
3713 : + advgetopt::getopt::breakup_line("Percent Configuration Files: /usr/share/advgetopt/options/", 0, advgetopt::getopt::get_line_width())
3714 : );
3715 : }
3716 : CATCH_END_SECTION()
3717 3 : }
3718 :
3719 :
3720 :
3721 :
3722 5 : CATCH_TEST_CASE("help_string_license", "[getopt][usage]")
3723 : {
3724 6 : CATCH_START_SECTION("Percent License (defined)")
3725 : {
3726 1 : const advgetopt::option options_list[] =
3727 : {
3728 : advgetopt::define_option(
3729 : advgetopt::Name("verbose")
3730 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3731 : , advgetopt::Help("inform you of what we're currently working on: %l.")
3732 : ),
3733 : advgetopt::end_options()
3734 : };
3735 1 : char const * cargv[] =
3736 : {
3737 : "tests/unittests/usage",
3738 : "--verbose",
3739 : nullptr
3740 : };
3741 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3742 1 : char ** argv = const_cast<char **>(cargv);
3743 :
3744 1 : advgetopt::options_environment options;
3745 1 : options.f_project_name = "unittest";
3746 1 : options.f_options = options_list;
3747 1 : options.f_options_files_directory = "/etc/advgetopt";
3748 1 : options.f_configuration_files = nullptr;
3749 1 : options.f_configuration_filename = "advgetopt.conf";
3750 1 : options.f_configuration_directories = nullptr;
3751 1 : options.f_help_header = "Usage: test usage: %l";
3752 1 : options.f_help_footer = "Percent License: %l";
3753 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3754 1 : options.f_version = "2.0.1-%l";
3755 1 : options.f_license = "MIT-%l";
3756 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %l";
3757 1 : options.f_build_date = "Jun 4 2019 %l";
3758 1 : options.f_build_time = "23:02:36 %l";
3759 :
3760 2 : advgetopt::getopt opt(options, argc, argv);
3761 :
3762 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3763 :
3764 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3765 : advgetopt::getopt::breakup_line("Usage: test usage: MIT-%l", 0, advgetopt::getopt::get_line_width())
3766 : + advgetopt::getopt::format_usage_string(
3767 : "--verbose"
3768 : , "inform you of what we're currently working on: MIT-%l."
3769 : , 30
3770 : , advgetopt::getopt::get_line_width()) + "\n"
3771 : + advgetopt::getopt::breakup_line("Percent License: MIT-%l", 0, advgetopt::getopt::get_line_width())
3772 : );
3773 : }
3774 : CATCH_END_SECTION()
3775 :
3776 6 : CATCH_START_SECTION("Percent License (nullptr)")
3777 : {
3778 1 : const advgetopt::option options_list[] =
3779 : {
3780 : advgetopt::define_option(
3781 : advgetopt::Name("verbose")
3782 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3783 : , advgetopt::Help("inform you of what we're currently working on: %l.")
3784 : ),
3785 : advgetopt::end_options()
3786 : };
3787 1 : char const * cargv[] =
3788 : {
3789 : "tests/unittests/usage",
3790 : "--verbose",
3791 : nullptr
3792 : };
3793 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3794 1 : char ** argv = const_cast<char **>(cargv);
3795 :
3796 1 : advgetopt::options_environment options;
3797 1 : options.f_project_name = "unittest";
3798 1 : options.f_options = options_list;
3799 1 : options.f_options_files_directory = "/etc/advgetopt";
3800 1 : options.f_configuration_files = nullptr;
3801 1 : options.f_configuration_filename = "advgetopt.conf";
3802 1 : options.f_configuration_directories = nullptr;
3803 1 : options.f_help_header = "Usage: test usage: %l";
3804 1 : options.f_help_footer = "Percent License: %l";
3805 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3806 1 : options.f_version = "2.0.1-%l";
3807 1 : options.f_license = nullptr;
3808 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %l";
3809 1 : options.f_build_date = "Jun 4 2019 %l";
3810 1 : options.f_build_time = "23:02:36 %l";
3811 :
3812 2 : advgetopt::getopt opt(options, argc, argv);
3813 :
3814 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3815 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3816 : "Usage: test usage: \n"
3817 : " --verbose inform you of what we're currently working on: .\n"
3818 : "\n"
3819 : "Percent License: \n"
3820 : );
3821 : }
3822 : CATCH_END_SECTION()
3823 :
3824 6 : CATCH_START_SECTION("Percent License (\"\")")
3825 : {
3826 1 : const advgetopt::option options_list[] =
3827 : {
3828 : advgetopt::define_option(
3829 : advgetopt::Name("verbose")
3830 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3831 : , advgetopt::Help("inform you of what we're currently working on: %l.")
3832 : ),
3833 : advgetopt::end_options()
3834 : };
3835 1 : char const * cargv[] =
3836 : {
3837 : "tests/unittests/usage",
3838 : "--verbose",
3839 : nullptr
3840 : };
3841 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3842 1 : char ** argv = const_cast<char **>(cargv);
3843 :
3844 1 : advgetopt::options_environment options;
3845 1 : options.f_project_name = "unittest";
3846 1 : options.f_options = options_list;
3847 1 : options.f_options_files_directory = "/etc/advgetopt";
3848 1 : options.f_configuration_files = nullptr;
3849 1 : options.f_configuration_filename = "advgetopt.conf";
3850 1 : options.f_configuration_directories = nullptr;
3851 1 : options.f_help_header = "Usage: test usage: %l";
3852 1 : options.f_help_footer = "Percent License: %l";
3853 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3854 1 : options.f_version = "2.0.1-%l";
3855 1 : options.f_license = "";
3856 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %l";
3857 1 : options.f_build_date = "Jun 4 2019 %l";
3858 1 : options.f_build_time = "23:02:36 %l";
3859 :
3860 2 : advgetopt::getopt opt(options, argc, argv);
3861 :
3862 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3863 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3864 : "Usage: test usage: \n"
3865 : " --verbose inform you of what we're currently working on: .\n"
3866 : "\n"
3867 : "Percent License: \n"
3868 : );
3869 : }
3870 : CATCH_END_SECTION()
3871 3 : }
3872 :
3873 :
3874 :
3875 :
3876 5 : CATCH_TEST_CASE("help_string_configuration_output_file", "[getopt][usage][config]")
3877 : {
3878 6 : CATCH_START_SECTION("Percent Configuration Output File (fully defined)")
3879 : {
3880 1 : const advgetopt::option options_list[] =
3881 : {
3882 : advgetopt::define_option(
3883 : advgetopt::Name("verbose")
3884 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3885 : , advgetopt::Help("inform you of what we're currently working on: %o.")
3886 : ),
3887 : advgetopt::end_options()
3888 : };
3889 1 : char const * cargv[] =
3890 : {
3891 : "tests/unittests/usage",
3892 : "--verbose",
3893 : nullptr
3894 : };
3895 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3896 1 : char ** argv = const_cast<char **>(cargv);
3897 :
3898 1 : const char * const configuration_files[] =
3899 : {
3900 : "system.conf",
3901 : "advgetopt.conf",
3902 : "advgetopt.ini",
3903 : "user.config",
3904 : nullptr
3905 : };
3906 :
3907 1 : advgetopt::options_environment options;
3908 1 : options.f_project_name = "unittest";
3909 1 : options.f_options = options_list;
3910 1 : options.f_options_files_directory = "/etc/advgetopt";
3911 1 : options.f_configuration_files = configuration_files;
3912 1 : options.f_configuration_filename = "advgetopt.conf";
3913 1 : options.f_configuration_directories = nullptr;
3914 1 : options.f_help_header = "Usage: test usage: %o";
3915 1 : options.f_help_footer = "Percent Configuration Files: %o";
3916 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3917 1 : options.f_version = "2.0.1-%o";
3918 1 : options.f_license = "MIT-%o";
3919 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %o";
3920 1 : options.f_build_date = "Jun 4 2019 %o";
3921 1 : options.f_build_time = "23:02:36 %o";
3922 :
3923 2 : advgetopt::getopt opt(options, argc, argv);
3924 :
3925 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3926 :
3927 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3928 : advgetopt::getopt::breakup_line("Usage: test usage: unittest.d/50-user.config", 0, advgetopt::getopt::get_line_width())
3929 : + advgetopt::getopt::format_usage_string(
3930 : "--verbose"
3931 : , "inform you of what we're currently working on: unittest.d/50-user.config."
3932 : , 30
3933 : , advgetopt::getopt::get_line_width()) + "\n"
3934 : + advgetopt::getopt::breakup_line("Percent Configuration Files: unittest.d/50-user.config", 0, advgetopt::getopt::get_line_width())
3935 : );
3936 : }
3937 : CATCH_END_SECTION()
3938 :
3939 6 : CATCH_START_SECTION("Percent Configuration Output File (nullptr)")
3940 : {
3941 1 : const advgetopt::option options_list[] =
3942 : {
3943 : advgetopt::define_option(
3944 : advgetopt::Name("verbose")
3945 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3946 : , advgetopt::Help("inform you of what we're currently working on: %o.")
3947 : ),
3948 : advgetopt::end_options()
3949 : };
3950 1 : char const * cargv[] =
3951 : {
3952 : "tests/unittests/usage",
3953 : "--verbose",
3954 : nullptr
3955 : };
3956 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
3957 1 : char ** argv = const_cast<char **>(cargv);
3958 :
3959 1 : advgetopt::options_environment options;
3960 1 : options.f_project_name = "unittest";
3961 1 : options.f_options = options_list;
3962 1 : options.f_options_files_directory = "/etc/advgetopt";
3963 1 : options.f_configuration_files = nullptr;
3964 1 : options.f_configuration_filename = "advgetopt.conf";
3965 1 : options.f_configuration_directories = nullptr;
3966 1 : options.f_help_header = "Usage: test usage: %o";
3967 1 : options.f_help_footer = "Percent Configuration Files: %o";
3968 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
3969 1 : options.f_version = "2.0.1-%o";
3970 1 : options.f_license = "MIT-%o";
3971 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %o";
3972 1 : options.f_build_date = "Jun 4 2019 %o";
3973 1 : options.f_build_time = "23:02:36 %o";
3974 :
3975 2 : advgetopt::getopt opt(options, argc, argv);
3976 :
3977 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
3978 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
3979 : "Usage: test usage: \n"
3980 : " --verbose inform you of what we're currently working on: .\n"
3981 : "\n"
3982 : "Percent Configuration Files: \n"
3983 : );
3984 : }
3985 : CATCH_END_SECTION()
3986 :
3987 6 : CATCH_START_SECTION("Percent Configuration Output File (empty array)")
3988 : {
3989 1 : const advgetopt::option options_list[] =
3990 : {
3991 : advgetopt::define_option(
3992 : advgetopt::Name("verbose")
3993 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
3994 : , advgetopt::Help("inform you of what we're currently working on: %o.")
3995 : ),
3996 : advgetopt::end_options()
3997 : };
3998 1 : char const * cargv[] =
3999 : {
4000 : "tests/unittests/usage",
4001 : "--verbose",
4002 : nullptr
4003 : };
4004 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4005 1 : char ** argv = const_cast<char **>(cargv);
4006 :
4007 1 : const char * const configuration_files[] =
4008 : {
4009 : nullptr
4010 : };
4011 :
4012 1 : advgetopt::options_environment options;
4013 1 : options.f_project_name = "unittest";
4014 1 : options.f_options = options_list;
4015 1 : options.f_options_files_directory = "/etc/advgetopt";
4016 1 : options.f_configuration_files = configuration_files;
4017 1 : options.f_configuration_filename = "advgetopt.conf";
4018 1 : options.f_configuration_directories = nullptr;
4019 1 : options.f_help_header = "Usage: test usage: %o";
4020 1 : options.f_help_footer = "Percent Configuration Files: %o";
4021 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4022 1 : options.f_version = "2.0.1-%o";
4023 1 : options.f_license = "MIT-%o";
4024 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %o";
4025 1 : options.f_build_date = "Jun 4 2019 %o";
4026 1 : options.f_build_time = "23:02:36 %o";
4027 :
4028 2 : advgetopt::getopt opt(options, argc, argv);
4029 :
4030 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4031 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4032 : "Usage: test usage: \n"
4033 : " --verbose inform you of what we're currently working on: .\n"
4034 : "\n"
4035 : "Percent Configuration Files: \n"
4036 : );
4037 : }
4038 : CATCH_END_SECTION()
4039 3 : }
4040 :
4041 :
4042 :
4043 :
4044 :
4045 :
4046 5 : CATCH_TEST_CASE("help_string_program_name", "[getopt][usage]")
4047 : {
4048 6 : CATCH_START_SECTION("Percent Program Name")
4049 : {
4050 1 : const advgetopt::option options_list[] =
4051 : {
4052 : advgetopt::define_option(
4053 : advgetopt::Name("verbose")
4054 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
4055 : , advgetopt::Help("inform you of what we're currently working on: %p.")
4056 : ),
4057 : advgetopt::end_options()
4058 : };
4059 1 : char const * cargv[] =
4060 : {
4061 : "tests/unittests/usage",
4062 : "--verbose",
4063 : nullptr
4064 : };
4065 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4066 1 : char ** argv = const_cast<char **>(cargv);
4067 :
4068 1 : advgetopt::options_environment options;
4069 1 : options.f_project_name = "unittest";
4070 1 : options.f_options = options_list;
4071 1 : options.f_options_files_directory = "/etc/advgetopt";
4072 1 : options.f_configuration_files = nullptr;
4073 1 : options.f_configuration_filename = "advgetopt.conf";
4074 1 : options.f_configuration_directories = nullptr;
4075 1 : options.f_help_header = "Usage: test usage: %p";
4076 1 : options.f_help_footer = "Percent Program Name: %p";
4077 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4078 1 : options.f_version = "2.0.1-%p";
4079 1 : options.f_license = "MIT-%p";
4080 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %p";
4081 1 : options.f_build_date = "Jun 4 2019 %p";
4082 1 : options.f_build_time = "23:02:36 %p";
4083 :
4084 2 : advgetopt::getopt opt(options, argc, argv);
4085 :
4086 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4087 :
4088 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4089 : advgetopt::getopt::breakup_line("Usage: test usage: usage", 0, advgetopt::getopt::get_line_width())
4090 : + advgetopt::getopt::format_usage_string(
4091 : "--verbose"
4092 : , "inform you of what we're currently working on: usage."
4093 : , 30
4094 : , advgetopt::getopt::get_line_width()) + "\n"
4095 : + advgetopt::getopt::breakup_line("Percent Program Name: usage", 0, advgetopt::getopt::get_line_width())
4096 : );
4097 : }
4098 : CATCH_END_SECTION()
4099 :
4100 6 : CATCH_START_SECTION("Percent Asterisk Program Name")
4101 : {
4102 1 : const advgetopt::option options_list[] =
4103 : {
4104 : advgetopt::define_option(
4105 : advgetopt::Name("verbose")
4106 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
4107 : , advgetopt::Help("inform you of what we're currently working on: %*p.")
4108 : ),
4109 : advgetopt::end_options()
4110 : };
4111 1 : char const * cargv[] =
4112 : {
4113 : "tests/unittests/usage",
4114 : "--verbose",
4115 : nullptr
4116 : };
4117 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4118 1 : char ** argv = const_cast<char **>(cargv);
4119 :
4120 1 : advgetopt::options_environment options;
4121 1 : options.f_project_name = "unittest";
4122 1 : options.f_options = options_list;
4123 1 : options.f_options_files_directory = "/etc/advgetopt";
4124 1 : options.f_configuration_files = nullptr;
4125 1 : options.f_configuration_filename = "advgetopt.conf";
4126 1 : options.f_configuration_directories = nullptr;
4127 1 : options.f_help_header = "Usage: test usage: %*p";
4128 1 : options.f_help_footer = "Percent Program Name: %*p";
4129 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4130 1 : options.f_version = "2.0.1-%*p";
4131 1 : options.f_license = "MIT-%*p";
4132 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %*p";
4133 1 : options.f_build_date = "Jun 4 2019 %*p";
4134 1 : options.f_build_time = "23:02:36 %*p";
4135 :
4136 2 : advgetopt::getopt opt(options, argc, argv);
4137 :
4138 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4139 :
4140 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4141 : advgetopt::getopt::breakup_line("Usage: test usage: tests/unittests/usage", 0, advgetopt::getopt::get_line_width())
4142 : + advgetopt::getopt::format_usage_string(
4143 : "--verbose"
4144 : , "inform you of what we're currently working on: tests/unittests/usage."
4145 : , 30
4146 : , advgetopt::getopt::get_line_width()) + "\n"
4147 : + advgetopt::getopt::breakup_line("Percent Program Name: tests/unittests/usage", 0, advgetopt::getopt::get_line_width())
4148 : );
4149 : }
4150 : CATCH_END_SECTION()
4151 :
4152 6 : CATCH_START_SECTION("Percent Program Name (empty--before parsing the arguments)")
4153 : {
4154 1 : const advgetopt::option options_list[] =
4155 : {
4156 : advgetopt::define_option(
4157 : advgetopt::Name("verbose")
4158 : , advgetopt::Flags(advgetopt::command_flags<advgetopt::GETOPT_FLAG_FLAG>())
4159 : , advgetopt::Help("inform you of what we're currently working on: %p.")
4160 : ),
4161 : advgetopt::end_options()
4162 : };
4163 :
4164 1 : advgetopt::options_environment options;
4165 1 : options.f_project_name = "unittest";
4166 1 : options.f_options = options_list;
4167 1 : options.f_options_files_directory = "/etc/advgetopt";
4168 1 : options.f_configuration_files = nullptr;
4169 1 : options.f_configuration_filename = "advgetopt.conf";
4170 1 : options.f_configuration_directories = nullptr;
4171 1 : options.f_help_header = "Usage: test usage: %p";
4172 1 : options.f_help_footer = "Percent Program Name: %p";
4173 1 : options.f_environment_variable_name = nullptr;
4174 1 : options.f_version = "2.0.1-%p";
4175 1 : options.f_license = "MIT-%p";
4176 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %p";
4177 1 : options.f_build_date = "Jun 4 2019 %p";
4178 1 : options.f_build_time = "23:02:36 %p";
4179 :
4180 2 : advgetopt::getopt opt(options);
4181 :
4182 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4183 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4184 : "Usage: test usage: \n"
4185 : " --verbose inform you of what we're currently working on: .\n"
4186 : "\n"
4187 : "Percent Program Name: \n"
4188 : );
4189 : }
4190 : CATCH_END_SECTION()
4191 3 : }
4192 :
4193 :
4194 :
4195 :
4196 :
4197 5 : CATCH_TEST_CASE("help_string_build_time", "[getopt][usage]")
4198 : {
4199 6 : CATCH_START_SECTION("Percent Build Time (defined)")
4200 : {
4201 1 : const advgetopt::option options_list[] =
4202 : {
4203 : advgetopt::define_option(
4204 : advgetopt::Name("verbose")
4205 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4206 : , advgetopt::Help("inform you of what we're currently working on: %t.")
4207 : ),
4208 : advgetopt::end_options()
4209 : };
4210 1 : char const * cargv[] =
4211 : {
4212 : "tests/unittests/usage",
4213 : "--verbose",
4214 : nullptr
4215 : };
4216 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4217 1 : char ** argv = const_cast<char **>(cargv);
4218 :
4219 1 : advgetopt::options_environment options;
4220 1 : options.f_project_name = "unittest";
4221 1 : options.f_options = options_list;
4222 1 : options.f_options_files_directory = "/etc/advgetopt";
4223 1 : options.f_configuration_files = nullptr;
4224 1 : options.f_configuration_filename = "advgetopt.conf";
4225 1 : options.f_configuration_directories = nullptr;
4226 1 : options.f_help_header = "Usage: test usage: %t";
4227 1 : options.f_help_footer = "Percent Build Time: %t";
4228 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4229 1 : options.f_version = "2.0.1-%t";
4230 1 : options.f_license = "MIT-%t";
4231 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %t";
4232 1 : options.f_build_date = "Jun 4 2019 %t";
4233 1 : options.f_build_time = "23:02:36 %t";
4234 :
4235 2 : advgetopt::getopt opt(options, argc, argv);
4236 :
4237 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4238 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4239 : advgetopt::getopt::breakup_line("Usage: test usage: 23:02:36 %t", 0, advgetopt::getopt::get_line_width())
4240 : + advgetopt::getopt::format_usage_string(
4241 : "--verbose"
4242 : , "inform you of what we're currently working on: 23:02:36 %t."
4243 : , 30
4244 : , advgetopt::getopt::get_line_width()) + "\n"
4245 : + advgetopt::getopt::breakup_line("Percent Build Time: 23:02:36 %t", 0, advgetopt::getopt::get_line_width())
4246 : );
4247 : }
4248 : CATCH_END_SECTION()
4249 :
4250 6 : CATCH_START_SECTION("Percent Build Time (nullptr)")
4251 : {
4252 1 : const advgetopt::option options_list[] =
4253 : {
4254 : advgetopt::define_option(
4255 : advgetopt::Name("verbose")
4256 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4257 : , advgetopt::Help("inform you of what we're currently working on: %t.")
4258 : ),
4259 : advgetopt::end_options()
4260 : };
4261 1 : char const * cargv[] =
4262 : {
4263 : "tests/unittests/usage",
4264 : "--verbose",
4265 : nullptr
4266 : };
4267 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4268 1 : char ** argv = const_cast<char **>(cargv);
4269 :
4270 1 : advgetopt::options_environment options;
4271 1 : options.f_project_name = "unittest";
4272 1 : options.f_options = options_list;
4273 1 : options.f_options_files_directory = "/etc/advgetopt";
4274 1 : options.f_configuration_files = nullptr;
4275 1 : options.f_configuration_filename = "advgetopt.conf";
4276 1 : options.f_configuration_directories = nullptr;
4277 1 : options.f_help_header = "Usage: test usage: %t";
4278 1 : options.f_help_footer = "Percent Build Time: %t";
4279 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4280 1 : options.f_version = "2.0.1-%t";
4281 1 : options.f_license = "MIT-%t";
4282 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %t";
4283 1 : options.f_build_date = "Jun 4 2019 %t";
4284 1 : options.f_build_time = nullptr;
4285 :
4286 2 : advgetopt::getopt opt(options, argc, argv);
4287 :
4288 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4289 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4290 : "Usage: test usage: \n"
4291 : " --verbose inform you of what we're currently working on: .\n"
4292 : "\n"
4293 : "Percent Build Time: \n"
4294 : // TBD -- apparently that works as is?!
4295 : //advgetopt::getopt::breakup_line("Usage: test usage: ", 0, advgetopt::getopt::get_line_width())
4296 : //+ advgetopt::getopt::format_usage_string(
4297 : // "--verbose"
4298 : // , "inform you of what we're currently working on: ."
4299 : // , 30
4300 : // , advgetopt::getopt::get_line_width()) + "\n"
4301 : //+ advgetopt::getopt::breakup_line("Percent Build Time: ", 0, advgetopt::getopt::get_line_width())
4302 : );
4303 : }
4304 : CATCH_END_SECTION()
4305 :
4306 6 : CATCH_START_SECTION("Percent Build Time (\"\")")
4307 : {
4308 1 : const advgetopt::option options_list[] =
4309 : {
4310 : advgetopt::define_option(
4311 : advgetopt::Name("verbose")
4312 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4313 : , advgetopt::Help("inform you of what we're currently working on: %t.")
4314 : ),
4315 : advgetopt::end_options()
4316 : };
4317 1 : char const * cargv[] =
4318 : {
4319 : "tests/unittests/usage",
4320 : "--verbose",
4321 : nullptr
4322 : };
4323 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4324 1 : char ** argv = const_cast<char **>(cargv);
4325 :
4326 1 : advgetopt::options_environment options;
4327 1 : options.f_project_name = "unittest";
4328 1 : options.f_options = options_list;
4329 1 : options.f_options_files_directory = "/etc/advgetopt";
4330 1 : options.f_configuration_files = nullptr;
4331 1 : options.f_configuration_filename = "advgetopt.conf";
4332 1 : options.f_configuration_directories = nullptr;
4333 1 : options.f_help_header = "Usage: test usage: %t";
4334 1 : options.f_help_footer = "Percent Build Time: %t";
4335 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4336 1 : options.f_version = "2.0.1-%t";
4337 1 : options.f_license = "MIT-%t";
4338 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %t";
4339 1 : options.f_build_date = "Jun 4 2019 %t";
4340 1 : options.f_build_time = "";
4341 :
4342 2 : advgetopt::getopt opt(options, argc, argv);
4343 :
4344 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4345 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4346 : "Usage: test usage: \n"
4347 : " --verbose inform you of what we're currently working on: .\n"
4348 : "\n"
4349 : "Percent Build Time: \n"
4350 : );
4351 : }
4352 : CATCH_END_SECTION()
4353 3 : }
4354 :
4355 :
4356 :
4357 :
4358 5 : CATCH_TEST_CASE("help_string_version", "[getopt][usage]")
4359 : {
4360 6 : CATCH_START_SECTION("Percent Version (defined)")
4361 : {
4362 1 : const advgetopt::option options_list[] =
4363 : {
4364 : advgetopt::define_option(
4365 : advgetopt::Name("verbose")
4366 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4367 : , advgetopt::Help("inform you of what we're currently working on: %v.")
4368 : ),
4369 : advgetopt::end_options()
4370 : };
4371 1 : char const * cargv[] =
4372 : {
4373 : "tests/unittests/usage",
4374 : "--verbose",
4375 : nullptr
4376 : };
4377 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4378 1 : char ** argv = const_cast<char **>(cargv);
4379 :
4380 1 : advgetopt::options_environment options;
4381 1 : options.f_project_name = "unittest";
4382 1 : options.f_options = options_list;
4383 1 : options.f_options_files_directory = "/etc/advgetopt";
4384 1 : options.f_configuration_files = nullptr;
4385 1 : options.f_configuration_filename = "advgetopt.conf";
4386 1 : options.f_configuration_directories = nullptr;
4387 1 : options.f_help_header = "Usage: test usage: %v";
4388 1 : options.f_help_footer = "Percent Version: %v";
4389 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4390 1 : options.f_version = "2.0.1-%v";
4391 1 : options.f_license = "MIT-%v";
4392 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %v";
4393 1 : options.f_build_date = "Jun 4 2019 %v";
4394 1 : options.f_build_time = "23:02:36 %v";
4395 :
4396 2 : advgetopt::getopt opt(options, argc, argv);
4397 :
4398 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4399 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4400 : advgetopt::getopt::breakup_line("Usage: test usage: 2.0.1-%v", 0, advgetopt::getopt::get_line_width())
4401 : + advgetopt::getopt::format_usage_string(
4402 : "--verbose"
4403 : , "inform you of what we're currently working on: 2.0.1-%v."
4404 : , 30
4405 : , advgetopt::getopt::get_line_width()) + "\n"
4406 : "Percent Version: 2.0.1-%v\n"
4407 : );
4408 : }
4409 : CATCH_END_SECTION()
4410 :
4411 6 : CATCH_START_SECTION("Percent Version (nullptr)")
4412 : {
4413 1 : const advgetopt::option options_list[] =
4414 : {
4415 : advgetopt::define_option(
4416 : advgetopt::Name("verbose")
4417 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4418 : , advgetopt::Help("inform you of what we're currently working on: %v.")
4419 : ),
4420 : advgetopt::end_options()
4421 : };
4422 1 : char const * cargv[] =
4423 : {
4424 : "tests/unittests/usage",
4425 : "--verbose",
4426 : nullptr
4427 : };
4428 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4429 1 : char ** argv = const_cast<char **>(cargv);
4430 :
4431 1 : advgetopt::options_environment options;
4432 1 : options.f_project_name = "unittest";
4433 1 : options.f_options = options_list;
4434 1 : options.f_options_files_directory = "/etc/advgetopt";
4435 1 : options.f_configuration_files = nullptr;
4436 1 : options.f_configuration_filename = "advgetopt.conf";
4437 1 : options.f_configuration_directories = nullptr;
4438 1 : options.f_help_header = "Usage: test usage: %v";
4439 1 : options.f_help_footer = "Percent Version: %v";
4440 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4441 1 : options.f_version = nullptr;
4442 1 : options.f_license = "MIT-%v";
4443 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %v";
4444 1 : options.f_build_date = "Jun 4 2019 %v";
4445 1 : options.f_build_time = "23:02:36 %v";
4446 :
4447 2 : advgetopt::getopt opt(options, argc, argv);
4448 :
4449 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4450 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4451 : "Usage: test usage: \n"
4452 : " --verbose inform you of what we're currently working on: .\n"
4453 : "\n"
4454 : "Percent Version: \n"
4455 : );
4456 : }
4457 : CATCH_END_SECTION()
4458 :
4459 6 : CATCH_START_SECTION("Percent Version (\"\")")
4460 : {
4461 1 : const advgetopt::option options_list[] =
4462 : {
4463 : advgetopt::define_option(
4464 : advgetopt::Name("verbose")
4465 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4466 : , advgetopt::Help("inform you of what we're currently working on: %v.")
4467 : ),
4468 : advgetopt::end_options()
4469 : };
4470 1 : char const * cargv[] =
4471 : {
4472 : "tests/unittests/usage",
4473 : "--verbose",
4474 : nullptr
4475 : };
4476 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4477 1 : char ** argv = const_cast<char **>(cargv);
4478 :
4479 1 : advgetopt::options_environment options;
4480 1 : options.f_project_name = "unittest";
4481 1 : options.f_options = options_list;
4482 1 : options.f_options_files_directory = "/etc/advgetopt";
4483 1 : options.f_configuration_files = nullptr;
4484 1 : options.f_configuration_filename = "advgetopt.conf";
4485 1 : options.f_configuration_directories = nullptr;
4486 1 : options.f_help_header = "Usage: test usage: %v";
4487 1 : options.f_help_footer = "Percent Version: %v";
4488 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4489 1 : options.f_version = "";
4490 1 : options.f_license = "MIT-%v";
4491 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %v";
4492 1 : options.f_build_date = "Jun 4 2019 %v";
4493 1 : options.f_build_time = "23:02:36 %v";
4494 :
4495 2 : advgetopt::getopt opt(options, argc, argv);
4496 :
4497 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4498 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4499 : "Usage: test usage: \n"
4500 : " --verbose inform you of what we're currently working on: .\n"
4501 : "\n"
4502 : "Percent Version: \n"
4503 : );
4504 : }
4505 : CATCH_END_SECTION()
4506 3 : }
4507 :
4508 :
4509 :
4510 :
4511 :
4512 6 : CATCH_TEST_CASE("help_string_writable_configuration_files", "[getopt][usage][config]")
4513 : {
4514 8 : CATCH_START_SECTION("Percent Writable Configuration Files (fully defined--one file)")
4515 : {
4516 1 : SNAP_CATCH2_NAMESPACE::init_tmp_dir("config_writable_filenames", "writable_filenames");
4517 :
4518 : {
4519 2 : std::ofstream config_file;
4520 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
4521 1 : CATCH_REQUIRE(config_file.good());
4522 1 : config_file <<
4523 : "# Auto-generated\n"
4524 : ;
4525 : }
4526 :
4527 : {
4528 2 : std::ofstream config_file;
4529 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_project_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
4530 1 : CATCH_REQUIRE(config_file.good());
4531 1 : config_file <<
4532 : "# Auto-generated\n"
4533 : ;
4534 : }
4535 :
4536 1 : const advgetopt::option options_list[] =
4537 : {
4538 : advgetopt::define_option(
4539 : advgetopt::Name("verbose")
4540 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4541 : , advgetopt::Help("inform you of what we're currently working on: %w.")
4542 : ),
4543 : advgetopt::end_options()
4544 : };
4545 1 : char const * cargv[] =
4546 : {
4547 : "tests/unittests/usage",
4548 : "--verbose",
4549 : nullptr
4550 : };
4551 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4552 1 : char ** argv = const_cast<char **>(cargv);
4553 :
4554 1 : const char * const configuration_files[] =
4555 : {
4556 : "system.conf",
4557 : "advgetopt.conf",
4558 1 : SNAP_CATCH2_NAMESPACE::g_config_filename.c_str(),
4559 : "advgetopt.ini",
4560 : "user.config",
4561 1 : SNAP_CATCH2_NAMESPACE::g_config_project_filename.c_str(),
4562 : nullptr
4563 2 : };
4564 :
4565 1 : advgetopt::options_environment options;
4566 1 : options.f_project_name = "config_writable_filenames";
4567 1 : options.f_options = options_list;
4568 1 : options.f_options_files_directory = "/etc/advgetopt";
4569 1 : options.f_configuration_files = configuration_files;
4570 1 : options.f_configuration_filename = "advgetopt.conf";
4571 1 : options.f_configuration_directories = nullptr;
4572 1 : options.f_help_header = "Usage: test usage: %w";
4573 1 : options.f_help_footer = "Percent Configuration Files: %w";
4574 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4575 1 : options.f_version = "2.0.1-%w";
4576 1 : options.f_license = "MIT-%w";
4577 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %w";
4578 1 : options.f_build_date = "Jun 4 2019 %w";
4579 1 : options.f_build_time = "23:02:36 %w";
4580 :
4581 2 : advgetopt::getopt opt(options, argc, argv);
4582 :
4583 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4584 :
4585 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4586 : advgetopt::getopt::breakup_line(
4587 : "Usage: test usage: "
4588 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
4589 : , 0
4590 : , advgetopt::getopt::get_line_width())
4591 : + advgetopt::getopt::format_usage_string(
4592 : "--verbose", "inform you of what we're currently working on: "
4593 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename + "."
4594 : , 30
4595 : , advgetopt::getopt::get_line_width()) + "\n"
4596 : + advgetopt::getopt::breakup_line(
4597 : "Percent Configuration Files: "
4598 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
4599 : , 0
4600 : , advgetopt::getopt::get_line_width())
4601 : );
4602 : }
4603 : CATCH_END_SECTION()
4604 :
4605 8 : CATCH_START_SECTION("Percent Writable Configuration Files (fully defined)")
4606 : {
4607 1 : SNAP_CATCH2_NAMESPACE::init_tmp_dir("config_writable_filenames", "writable_filenames");
4608 2 : std::string const save_config_filename(SNAP_CATCH2_NAMESPACE::g_config_filename);
4609 2 : std::string const save_config_project_filename(SNAP_CATCH2_NAMESPACE::g_config_project_filename);
4610 :
4611 1 : SNAP_CATCH2_NAMESPACE::init_tmp_dir("config_writable_filenames", "writable_filenames_two");
4612 :
4613 : {
4614 2 : std::ofstream config_file;
4615 1 : config_file.open(save_config_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
4616 1 : CATCH_REQUIRE(config_file.good());
4617 1 : config_file <<
4618 : "# Auto-generated\n"
4619 : ;
4620 : }
4621 :
4622 : {
4623 2 : std::ofstream config_file;
4624 1 : config_file.open(save_config_project_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
4625 1 : CATCH_REQUIRE(config_file.good());
4626 1 : config_file <<
4627 : "# Auto-generated\n"
4628 : ;
4629 : }
4630 :
4631 : {
4632 2 : std::ofstream config_file;
4633 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
4634 1 : CATCH_REQUIRE(config_file.good());
4635 1 : config_file <<
4636 : "# Auto-generated\n"
4637 : ;
4638 : }
4639 :
4640 : {
4641 2 : std::ofstream config_file;
4642 1 : config_file.open(SNAP_CATCH2_NAMESPACE::g_config_project_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
4643 1 : CATCH_REQUIRE(config_file.good());
4644 1 : config_file <<
4645 : "# Auto-generated\n"
4646 : ;
4647 : }
4648 :
4649 1 : const advgetopt::option options_list[] =
4650 : {
4651 : advgetopt::define_option(
4652 : advgetopt::Name("verbose")
4653 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4654 : , advgetopt::Help("inform you of what we're currently working on: %w.")
4655 : ),
4656 : advgetopt::end_options()
4657 : };
4658 1 : char const * cargv[] =
4659 : {
4660 : "tests/unittests/usage",
4661 : "--verbose",
4662 : nullptr
4663 : };
4664 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4665 1 : char ** argv = const_cast<char **>(cargv);
4666 :
4667 1 : const char * const configuration_files[] =
4668 : {
4669 : "system.conf",
4670 1 : save_config_project_filename.c_str(),
4671 : "advgetopt.conf",
4672 1 : SNAP_CATCH2_NAMESPACE::g_config_filename.c_str(),
4673 : "advgetopt.ini",
4674 1 : save_config_filename.c_str(),
4675 : "user.config",
4676 1 : SNAP_CATCH2_NAMESPACE::g_config_project_filename.c_str(),
4677 : nullptr
4678 4 : };
4679 :
4680 1 : advgetopt::options_environment options;
4681 1 : options.f_project_name = "config_writable_filenames";
4682 1 : options.f_options = options_list;
4683 1 : options.f_options_files_directory = "/etc/advgetopt";
4684 1 : options.f_configuration_files = configuration_files;
4685 1 : options.f_configuration_filename = "advgetopt.conf";
4686 1 : options.f_configuration_directories = nullptr;
4687 1 : options.f_help_header = "Usage: test usage: %w";
4688 1 : options.f_help_footer = "Percent Configuration Files: %w";
4689 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4690 1 : options.f_version = "2.0.1-%w";
4691 1 : options.f_license = "MIT-%w";
4692 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %w";
4693 1 : options.f_build_date = "Jun 4 2019 %w";
4694 1 : options.f_build_time = "23:02:36 %w";
4695 :
4696 2 : advgetopt::getopt opt(options, argc, argv);
4697 :
4698 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4699 :
4700 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4701 : advgetopt::getopt::breakup_line(
4702 : "Usage: test usage: "
4703 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
4704 : + ", "
4705 : + save_config_project_filename
4706 : , 0
4707 : , advgetopt::getopt::get_line_width())
4708 : + advgetopt::getopt::format_usage_string(
4709 : "--verbose", "inform you of what we're currently working on: "
4710 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
4711 : + ", "
4712 : + save_config_project_filename + "."
4713 : , 30
4714 : , advgetopt::getopt::get_line_width()) + "\n"
4715 : + advgetopt::getopt::breakup_line(
4716 : "Percent Configuration Files: "
4717 : + SNAP_CATCH2_NAMESPACE::g_config_project_filename
4718 : + ", "
4719 : + save_config_project_filename
4720 : , 0
4721 : , advgetopt::getopt::get_line_width())
4722 : );
4723 : }
4724 : CATCH_END_SECTION()
4725 :
4726 8 : CATCH_START_SECTION("Percent Writable Configuration Files (nullptr)")
4727 : {
4728 1 : const advgetopt::option options_list[] =
4729 : {
4730 : advgetopt::define_option(
4731 : advgetopt::Name("verbose")
4732 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4733 : , advgetopt::Help("inform you of what we're currently working on: %w.")
4734 : ),
4735 : advgetopt::end_options()
4736 : };
4737 1 : char const * cargv[] =
4738 : {
4739 : "tests/unittests/usage",
4740 : "--verbose",
4741 : nullptr
4742 : };
4743 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4744 1 : char ** argv = const_cast<char **>(cargv);
4745 :
4746 1 : advgetopt::options_environment options;
4747 1 : options.f_project_name = "unittest";
4748 1 : options.f_options = options_list;
4749 1 : options.f_options_files_directory = "/etc/advgetopt";
4750 1 : options.f_configuration_files = nullptr;
4751 1 : options.f_configuration_filename = "advgetopt.conf";
4752 1 : options.f_configuration_directories = nullptr;
4753 1 : options.f_help_header = "Usage: test usage: %w";
4754 1 : options.f_help_footer = "Percent Configuration Files: %w";
4755 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4756 1 : options.f_version = "2.0.1-%w";
4757 1 : options.f_license = "MIT-%w";
4758 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %w";
4759 1 : options.f_build_date = "Jun 4 2019 %w";
4760 1 : options.f_build_time = "23:02:36 %w";
4761 :
4762 2 : advgetopt::getopt opt(options, argc, argv);
4763 :
4764 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4765 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4766 : "Usage: test usage: \n"
4767 : " --verbose inform you of what we're currently working on: .\n"
4768 : "\n"
4769 : "Percent Configuration Files: \n"
4770 : );
4771 : }
4772 : CATCH_END_SECTION()
4773 :
4774 8 : CATCH_START_SECTION("Percent Writable Configuration Files (empty array)")
4775 : {
4776 1 : const advgetopt::option options_list[] =
4777 : {
4778 : advgetopt::define_option(
4779 : advgetopt::Name("verbose")
4780 : , advgetopt::Flags(advgetopt::standalone_command_flags<>())
4781 : , advgetopt::Help("inform you of what we're currently working on: %w.")
4782 : ),
4783 : advgetopt::end_options()
4784 : };
4785 1 : char const * cargv[] =
4786 : {
4787 : "tests/unittests/usage",
4788 : "--verbose",
4789 : nullptr
4790 : };
4791 1 : int const argc = sizeof(cargv) / sizeof(cargv[0]) - 1;
4792 1 : char ** argv = const_cast<char **>(cargv);
4793 :
4794 1 : const char * const configuration_files[] =
4795 : {
4796 : nullptr
4797 : };
4798 :
4799 1 : advgetopt::options_environment options;
4800 1 : options.f_project_name = "unittest";
4801 1 : options.f_options = options_list;
4802 1 : options.f_options_files_directory = "/etc/advgetopt";
4803 1 : options.f_configuration_files = configuration_files;
4804 1 : options.f_configuration_filename = "advgetopt.conf";
4805 1 : options.f_configuration_directories = nullptr;
4806 1 : options.f_help_header = "Usage: test usage: %w";
4807 1 : options.f_help_footer = "Percent Configuration Files: %w";
4808 1 : options.f_environment_variable_name = "ADVGETOPT_TEST_OPTIONS";
4809 1 : options.f_version = "2.0.1-%w";
4810 1 : options.f_license = "MIT-%w";
4811 1 : options.f_copyright = "Copyright (c) 2019 Made to Order Software Corp. -- All Rights Reserved %w";
4812 1 : options.f_build_date = "Jun 4 2019 %w";
4813 1 : options.f_build_time = "23:02:36 %w";
4814 :
4815 2 : advgetopt::getopt opt(options, argc, argv);
4816 :
4817 1 : CATCH_REQUIRE(advgetopt::GETOPT_FLAG_SHOW_MOST == 0);
4818 1 : CATCH_REQUIRE_LONG_STRING(opt.usage(),
4819 : "Usage: test usage: \n"
4820 : " --verbose inform you of what we're currently working on: .\n"
4821 : "\n"
4822 : "Percent Configuration Files: \n"
4823 : );
4824 : }
4825 : CATCH_END_SECTION()
4826 4 : }
4827 :
4828 :
4829 :
4830 :
4831 5 : CATCH_TEST_CASE("invalid_group_for_find_group", "[getopt][usage][config][invalid]")
4832 : {
4833 6 : CATCH_START_SECTION("find_group() with invalid flags")
4834 : {
4835 33 : for(int idx(0); idx < 32; ++idx)
4836 : {
4837 32 : advgetopt::flag_t const invalid_group(1UL << idx);
4838 32 : if((invalid_group & ~advgetopt::GETOPT_FLAG_GROUP_MASK) == 0)
4839 : {
4840 : // this is a valid group, skip
4841 : //
4842 3 : continue;
4843 : }
4844 :
4845 29 : advgetopt::group_description const groups[] =
4846 : {
4847 : advgetopt::define_group(
4848 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_COMMANDS)
4849 : ),
4850 : advgetopt::define_group(
4851 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_OPTIONS)
4852 : ),
4853 : advgetopt::end_groups()
4854 : };
4855 :
4856 :
4857 29 : advgetopt::options_environment options;
4858 29 : options.f_project_name = "unittest";
4859 29 : options.f_groups = groups;
4860 58 : advgetopt::getopt opt(options);
4861 :
4862 29 : CATCH_REQUIRE_THROWS_MATCHES(
4863 : opt.find_group(invalid_group)
4864 : , advgetopt::getopt_logic_error
4865 : , Catch::Matchers::ExceptionMessage(
4866 : "getopt_logic_error: group parameter must represent a valid group."));
4867 : }
4868 : }
4869 : CATCH_END_SECTION()
4870 :
4871 6 : CATCH_START_SECTION("find_group() with GETOPT_FLAG_GROUP_NONE")
4872 : {
4873 1 : advgetopt::group_description const groups[] =
4874 : {
4875 : advgetopt::define_group(
4876 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_COMMANDS)
4877 : ),
4878 : advgetopt::define_group(
4879 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_OPTIONS)
4880 : ),
4881 : advgetopt::end_groups()
4882 : };
4883 :
4884 1 : advgetopt::options_environment options;
4885 1 : options.f_project_name = "unittest";
4886 1 : options.f_groups = groups;
4887 2 : advgetopt::getopt opt(options);
4888 :
4889 1 : CATCH_REQUIRE_THROWS_MATCHES(
4890 : opt.find_group(advgetopt::GETOPT_FLAG_GROUP_NONE)
4891 : , advgetopt::getopt_logic_error
4892 : , Catch::Matchers::ExceptionMessage(
4893 : "getopt_logic_error: group NONE cannot be assigned a name so you cannot search for it."));
4894 : }
4895 : CATCH_END_SECTION()
4896 :
4897 6 : CATCH_START_SECTION("find_group() with invalid group definitions")
4898 : {
4899 : // define groups without name nor description
4900 : // (later the define_group() will err at compile time on those
4901 : // so we'll have to switch to a "manual" definition instead to
4902 : // verify that this indeed fails as expected.)
4903 : //
4904 1 : advgetopt::group_description const groups[] =
4905 : {
4906 : advgetopt::define_group(
4907 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_COMMANDS)
4908 : ),
4909 : advgetopt::define_group(
4910 : advgetopt::GroupNumber(advgetopt::GETOPT_FLAG_GROUP_OPTIONS)
4911 : ),
4912 : advgetopt::end_groups()
4913 : };
4914 :
4915 1 : advgetopt::options_environment options;
4916 1 : options.f_project_name = "unittest";
4917 1 : options.f_groups = groups;
4918 2 : advgetopt::getopt opt(options);
4919 :
4920 1 : CATCH_REQUIRE_THROWS_MATCHES(
4921 : opt.find_group(advgetopt::GETOPT_FLAG_GROUP_COMMANDS)
4922 : , advgetopt::getopt_logic_error
4923 : , Catch::Matchers::ExceptionMessage(
4924 : "getopt_logic_error: at least one of a group name or description must be defined (a non-empty string)."));
4925 :
4926 1 : CATCH_REQUIRE_THROWS_MATCHES(
4927 : opt.find_group(advgetopt::GETOPT_FLAG_GROUP_OPTIONS)
4928 : , advgetopt::getopt_logic_error
4929 : , Catch::Matchers::ExceptionMessage(
4930 : "getopt_logic_error: at least one of a group name or description must be defined (a non-empty string)."));
4931 : }
4932 : CATCH_END_SECTION()
4933 9 : }
4934 :
4935 :
4936 :
4937 :
4938 :
4939 :
4940 :
4941 :
4942 : // vim: ts=4 sw=4 et
|