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

Generated by: LCOV version 1.13