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