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