LCOV - code coverage report
Current view: top level - tests - usage.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1772 1772 100.0 %
Date: 2019-08-10 16:09:07 Functions: 19 19 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.12