LCOV - code coverage report
Current view: top level - gltests - test-getopt_long.h (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 1447 1464 98.8 %
Date: 2015-03-02 11:46:03 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Test of command line argument processing.
       2             :    Copyright (C) 2009-2015 Free Software Foundation, Inc.
       3             : 
       4             :    This program is free software: you can redistribute it and/or modify
       5             :    it under the terms of the GNU General Public License as published by
       6             :    the Free Software Foundation; either version 3 of the License, or
       7             :    (at your option) any later version.
       8             : 
       9             :    This program is distributed in the hope that it will be useful,
      10             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :    GNU General Public License for more details.
      13             : 
      14             :    You should have received a copy of the GNU General Public License
      15             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      16             : 
      17             : /* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
      18             : 
      19             : static int a_seen;
      20             : static int b_seen;
      21             : static int q_seen;
      22             : 
      23             : static const struct option long_options_required[] =
      24             :   {
      25             :     { "alpha",    no_argument,       NULL, 'a' },
      26             :     { "beta",     no_argument,       &b_seen, 1 },
      27             :     { "prune",    required_argument, NULL, 'p' },
      28             :     { "quetsche", required_argument, &q_seen, 1 },
      29             :     { "xtremely-",no_argument,       NULL, 1003 },
      30             :     { "xtra",     no_argument,       NULL, 1001 },
      31             :     { "xtreme",   no_argument,       NULL, 1002 },
      32             :     { "xtremely", no_argument,       NULL, 1003 },
      33             :     { NULL,       0,                 NULL, 0 }
      34             :   };
      35             : 
      36             : static const struct option long_options_optional[] =
      37             :   {
      38             :     { "alpha",    no_argument,       NULL, 'a' },
      39             :     { "beta",     no_argument,       &b_seen, 1 },
      40             :     { "prune",    optional_argument, NULL, 'p' },
      41             :     { "quetsche", optional_argument, &q_seen, 1 },
      42             :     { NULL,       0,                 NULL, 0 }
      43             :   };
      44             : 
      45             : static void
      46          94 : getopt_long_loop (int argc, const char **argv,
      47             :                   const char *options, const struct option *long_options,
      48             :                   const char **p_value, const char **q_value,
      49             :                   int *non_options_count, const char **non_options,
      50             :                   int *unrecognized)
      51             : {
      52          94 :   int option_index = -1;
      53             :   int c;
      54             : 
      55          94 :   opterr = 0;
      56          94 :   q_seen = 0;
      57         362 :   while ((c = getopt_long (argc, (char **) argv, options, long_options,
      58             :                            &option_index))
      59             :          != -1)
      60             :     {
      61         174 :       switch (c)
      62             :         {
      63             :         case 0:
      64             :           /* An option with a non-NULL flag pointer was processed.  */
      65          16 :           if (q_seen)
      66           4 :             *q_value = optarg;
      67          16 :           break;
      68             :         case 'a':
      69          56 :           a_seen++;
      70          56 :           break;
      71             :         case 'b':
      72          14 :           b_seen = 1;
      73          14 :           break;
      74             :         case 'p':
      75          64 :           *p_value = optarg;
      76          64 :           break;
      77             :         case 'q':
      78           2 :           *q_value = optarg;
      79           2 :           break;
      80             :         case '\1':
      81             :           /* Must only happen with option '-' at the beginning.  */
      82          12 :           ASSERT (options[0] == '-');
      83          12 :           non_options[(*non_options_count)++] = optarg;
      84          12 :           break;
      85             :         case ':':
      86             :           /* Must only happen with option ':' at the beginning.  */
      87           0 :           ASSERT (options[0] == ':'
      88             :                   || ((options[0] == '-' || options[0] == '+')
      89             :                       && options[1] == ':'));
      90             :           /* fall through */
      91             :         case '?':
      92          10 :           *unrecognized = optopt;
      93          10 :           break;
      94             :         default:
      95           0 :           *unrecognized = c;
      96           0 :           break;
      97             :         }
      98             :     }
      99          94 : }
     100             : 
     101             : /* Reduce casting, so we can use string literals elsewhere.
     102             :    getopt_long takes an array of char*, but luckily does not modify
     103             :    those elements, so we can pass const char*.  */
     104             : static int
     105          13 : do_getopt_long (int argc, const char **argv, const char *shortopts,
     106             :                 const struct option *longopts, int *longind)
     107             : {
     108          13 :   return getopt_long (argc, (char **) argv, shortopts, longopts, longind);
     109             : }
     110             : 
     111             : static void
     112           1 : test_getopt_long (void)
     113             : {
     114             :   int start;
     115             : 
     116             :   /* Test disambiguation of options.  */
     117             :   {
     118           1 :     int argc = 0;
     119             :     const char *argv[10];
     120             :     int option_index;
     121             :     int c;
     122             : 
     123           1 :     argv[argc++] = "program";
     124           1 :     argv[argc++] = "--x";
     125           1 :     argv[argc] = NULL;
     126           1 :     optind = 1;
     127           1 :     opterr = 0;
     128           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     129           1 :     ASSERT (c == '?');
     130           1 :     ASSERT (optopt == 0);
     131             :   }
     132             :   {
     133           1 :     int argc = 0;
     134             :     const char *argv[10];
     135             :     int option_index;
     136             :     int c;
     137             : 
     138           1 :     argv[argc++] = "program";
     139           1 :     argv[argc++] = "--xt";
     140           1 :     argv[argc] = NULL;
     141           1 :     optind = 1;
     142           1 :     opterr = 0;
     143           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     144           1 :     ASSERT (c == '?');
     145           1 :     ASSERT (optopt == 0);
     146             :   }
     147             :   {
     148           1 :     int argc = 0;
     149             :     const char *argv[10];
     150             :     int option_index;
     151             :     int c;
     152             : 
     153           1 :     argv[argc++] = "program";
     154           1 :     argv[argc++] = "--xtr";
     155           1 :     argv[argc] = NULL;
     156           1 :     optind = 1;
     157           1 :     opterr = 0;
     158           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     159           1 :     ASSERT (c == '?');
     160           1 :     ASSERT (optopt == 0);
     161             :   }
     162             :   {
     163           1 :     int argc = 0;
     164             :     const char *argv[10];
     165             :     int option_index;
     166             :     int c;
     167             : 
     168           1 :     argv[argc++] = "program";
     169           1 :     argv[argc++] = "--xtra";
     170           1 :     argv[argc] = NULL;
     171           1 :     optind = 1;
     172           1 :     opterr = 0;
     173           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     174           1 :     ASSERT (c == 1001);
     175             :   }
     176             :   {
     177           1 :     int argc = 0;
     178             :     const char *argv[10];
     179             :     int option_index;
     180             :     int c;
     181             : 
     182           1 :     argv[argc++] = "program";
     183           1 :     argv[argc++] = "--xtre";
     184           1 :     argv[argc] = NULL;
     185           1 :     optind = 1;
     186           1 :     opterr = 0;
     187           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     188           1 :     ASSERT (c == '?');
     189           1 :     ASSERT (optopt == 0);
     190             :   }
     191             :   {
     192           1 :     int argc = 0;
     193             :     const char *argv[10];
     194             :     int option_index;
     195             :     int c;
     196             : 
     197           1 :     argv[argc++] = "program";
     198           1 :     argv[argc++] = "--xtrem";
     199           1 :     argv[argc] = NULL;
     200           1 :     optind = 1;
     201           1 :     opterr = 0;
     202           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     203           1 :     ASSERT (c == '?');
     204           1 :     ASSERT (optopt == 0);
     205             :   }
     206             :   {
     207           1 :     int argc = 0;
     208             :     const char *argv[10];
     209             :     int option_index;
     210             :     int c;
     211             : 
     212           1 :     argv[argc++] = "program";
     213           1 :     argv[argc++] = "--xtreme";
     214           1 :     argv[argc] = NULL;
     215           1 :     optind = 1;
     216           1 :     opterr = 0;
     217           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     218           1 :     ASSERT (c == 1002);
     219             :   }
     220             :   {
     221           1 :     int argc = 0;
     222             :     const char *argv[10];
     223             :     int option_index;
     224             :     int c;
     225             : 
     226           1 :     argv[argc++] = "program";
     227           1 :     argv[argc++] = "--xtremel";
     228           1 :     argv[argc] = NULL;
     229           1 :     optind = 1;
     230           1 :     opterr = 0;
     231           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     232           1 :     ASSERT (c == 1003);
     233             :   }
     234             :   {
     235           1 :     int argc = 0;
     236             :     const char *argv[10];
     237             :     int option_index;
     238             :     int c;
     239             : 
     240           1 :     argv[argc++] = "program";
     241           1 :     argv[argc++] = "--xtremely";
     242           1 :     argv[argc] = NULL;
     243           1 :     optind = 1;
     244           1 :     opterr = 0;
     245           1 :     c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
     246           1 :     ASSERT (c == 1003);
     247             :   }
     248             : 
     249             :   /* Check that -W handles unknown options.  */
     250             :   {
     251           1 :     int argc = 0;
     252             :     const char *argv[10];
     253             :     int option_index;
     254             :     int c;
     255             : 
     256           1 :     argv[argc++] = "program";
     257           1 :     argv[argc++] = "-W";
     258           1 :     argv[argc] = NULL;
     259           1 :     optind = 1;
     260           1 :     opterr = 0;
     261           1 :     c = do_getopt_long (argc, argv, "W;", long_options_required, &option_index);
     262           1 :     ASSERT (c == '?');
     263           1 :     ASSERT (optopt == 'W');
     264             :   }
     265             :   {
     266           1 :     int argc = 0;
     267             :     const char *argv[10];
     268             :     int option_index;
     269             :     int c;
     270             : 
     271           1 :     argv[argc++] = "program";
     272           1 :     argv[argc++] = "-Wunknown";
     273           1 :     argv[argc] = NULL;
     274           1 :     optind = 1;
     275           1 :     opterr = 0;
     276           1 :     c = do_getopt_long (argc, argv, "W;", long_options_required, &option_index);
     277             :     /* glibc and BSD behave differently here, but for now, we allow
     278             :        both behaviors since W support is not frequently used.  */
     279           1 :     if (c == '?')
     280             :       {
     281           0 :         ASSERT (optopt == 0);
     282           0 :         ASSERT (optarg == NULL);
     283             :       }
     284             :     else
     285             :       {
     286           1 :         ASSERT (c == 'W');
     287           1 :         ASSERT (strcmp (optarg, "unknown") == 0);
     288             :       }
     289             :   }
     290             :   {
     291           1 :     int argc = 0;
     292             :     const char *argv[10];
     293             :     int option_index;
     294             :     int c;
     295             : 
     296           1 :     argv[argc++] = "program";
     297           1 :     argv[argc++] = "-W";
     298           1 :     argv[argc++] = "unknown";
     299           1 :     argv[argc] = NULL;
     300           1 :     optind = 1;
     301           1 :     opterr = 0;
     302           1 :     c = do_getopt_long (argc, argv, "W;", long_options_required, &option_index);
     303             :     /* glibc and BSD behave differently here, but for now, we allow
     304             :        both behaviors since W support is not frequently used.  */
     305           1 :     if (c == '?')
     306             :       {
     307           0 :         ASSERT (optopt == 0);
     308           0 :         ASSERT (optarg == NULL);
     309             :       }
     310             :     else
     311             :       {
     312           1 :         ASSERT (c == 'W');
     313           1 :         ASSERT (strcmp (optarg, "unknown") == 0);
     314             :       }
     315             :   }
     316             : 
     317             :   /* Test that 'W' does not dump core:
     318             :      http://sourceware.org/bugzilla/show_bug.cgi?id=12922  */
     319             :   {
     320           1 :     int argc = 0;
     321             :     const char *argv[10];
     322             :     int option_index;
     323             :     int c;
     324             : 
     325           1 :     argv[argc++] = "program";
     326           1 :     argv[argc++] = "-W";
     327           1 :     argv[argc++] = "dummy";
     328           1 :     argv[argc] = NULL;
     329           1 :     optind = 1;
     330           1 :     opterr = 0;
     331           1 :     c = do_getopt_long (argc, argv, "W;", NULL, &option_index);
     332           1 :     ASSERT (c == 'W');
     333           1 :     ASSERT (optind == 2);
     334             :   }
     335             : 
     336             :   /* Test processing of boolean short options.  */
     337           3 :   for (start = 0; start <= 1; start++)
     338             :     {
     339           2 :       const char *p_value = NULL;
     340           2 :       const char *q_value = NULL;
     341           2 :       int non_options_count = 0;
     342             :       const char *non_options[10];
     343           2 :       int unrecognized = 0;
     344           2 :       int argc = 0;
     345             :       const char *argv[10];
     346           2 :       a_seen = 0;
     347           2 :       b_seen = 0;
     348             : 
     349           2 :       argv[argc++] = "program";
     350           2 :       argv[argc++] = "-a";
     351           2 :       argv[argc++] = "foo";
     352           2 :       argv[argc++] = "bar";
     353           2 :       argv[argc] = NULL;
     354           2 :       optind = start;
     355           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     356             :                         &p_value, &q_value,
     357             :                         &non_options_count, non_options, &unrecognized);
     358           2 :       ASSERT (a_seen == 1);
     359           2 :       ASSERT (b_seen == 0);
     360           2 :       ASSERT (p_value == NULL);
     361           2 :       ASSERT (q_value == NULL);
     362           2 :       ASSERT (non_options_count == 0);
     363           2 :       ASSERT (unrecognized == 0);
     364           2 :       ASSERT (optind == 2);
     365             :     }
     366           3 :   for (start = 0; start <= 1; start++)
     367             :     {
     368           2 :       const char *p_value = NULL;
     369           2 :       const char *q_value = NULL;
     370           2 :       int non_options_count = 0;
     371             :       const char *non_options[10];
     372           2 :       int unrecognized = 0;
     373           2 :       int argc = 0;
     374             :       const char *argv[10];
     375           2 :       a_seen = 0;
     376           2 :       b_seen = 0;
     377             : 
     378           2 :       argv[argc++] = "program";
     379           2 :       argv[argc++] = "-b";
     380           2 :       argv[argc++] = "-a";
     381           2 :       argv[argc++] = "foo";
     382           2 :       argv[argc++] = "bar";
     383           2 :       argv[argc] = NULL;
     384           2 :       optind = start;
     385           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     386             :                         &p_value, &q_value,
     387             :                         &non_options_count, non_options, &unrecognized);
     388           2 :       ASSERT (a_seen == 1);
     389           2 :       ASSERT (b_seen == 1);
     390           2 :       ASSERT (p_value == NULL);
     391           2 :       ASSERT (q_value == NULL);
     392           2 :       ASSERT (non_options_count == 0);
     393           2 :       ASSERT (unrecognized == 0);
     394           2 :       ASSERT (optind == 3);
     395             :     }
     396           3 :   for (start = 0; start <= 1; start++)
     397             :     {
     398           2 :       const char *p_value = NULL;
     399           2 :       const char *q_value = NULL;
     400           2 :       int non_options_count = 0;
     401             :       const char *non_options[10];
     402           2 :       int unrecognized = 0;
     403           2 :       int argc = 0;
     404             :       const char *argv[10];
     405           2 :       a_seen = 0;
     406           2 :       b_seen = 0;
     407             : 
     408           2 :       argv[argc++] = "program";
     409           2 :       argv[argc++] = "-ba";
     410           2 :       argv[argc++] = "foo";
     411           2 :       argv[argc++] = "bar";
     412           2 :       argv[argc] = NULL;
     413           2 :       optind = start;
     414           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     415             :                         &p_value, &q_value,
     416             :                         &non_options_count, non_options, &unrecognized);
     417           2 :       ASSERT (a_seen == 1);
     418           2 :       ASSERT (b_seen == 1);
     419           2 :       ASSERT (p_value == NULL);
     420           2 :       ASSERT (q_value == NULL);
     421           2 :       ASSERT (non_options_count == 0);
     422           2 :       ASSERT (unrecognized == 0);
     423           2 :       ASSERT (optind == 2);
     424             :     }
     425           3 :   for (start = 0; start <= 1; start++)
     426             :     {
     427           2 :       const char *p_value = NULL;
     428           2 :       const char *q_value = NULL;
     429           2 :       int non_options_count = 0;
     430             :       const char *non_options[10];
     431           2 :       int unrecognized = 0;
     432           2 :       int argc = 0;
     433             :       const char *argv[10];
     434           2 :       a_seen = 0;
     435           2 :       b_seen = 0;
     436             : 
     437           2 :       argv[argc++] = "program";
     438           2 :       argv[argc++] = "-ab";
     439           2 :       argv[argc++] = "-a";
     440           2 :       argv[argc++] = "foo";
     441           2 :       argv[argc++] = "bar";
     442           2 :       argv[argc] = NULL;
     443           2 :       optind = start;
     444           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     445             :                         &p_value, &q_value,
     446             :                         &non_options_count, non_options, &unrecognized);
     447           2 :       ASSERT (a_seen == 2);
     448           2 :       ASSERT (b_seen == 1);
     449           2 :       ASSERT (p_value == NULL);
     450           2 :       ASSERT (q_value == NULL);
     451           2 :       ASSERT (non_options_count == 0);
     452           2 :       ASSERT (unrecognized == 0);
     453           2 :       ASSERT (optind == 3);
     454             :     }
     455             : 
     456             :   /* Test processing of boolean long options.  */
     457           3 :   for (start = 0; start <= 1; start++)
     458             :     {
     459           2 :       const char *p_value = NULL;
     460           2 :       const char *q_value = NULL;
     461           2 :       int non_options_count = 0;
     462             :       const char *non_options[10];
     463           2 :       int unrecognized = 0;
     464           2 :       int argc = 0;
     465             :       const char *argv[10];
     466           2 :       a_seen = 0;
     467           2 :       b_seen = 0;
     468             : 
     469           2 :       argv[argc++] = "program";
     470           2 :       argv[argc++] = "--alpha";
     471           2 :       argv[argc++] = "foo";
     472           2 :       argv[argc++] = "bar";
     473           2 :       argv[argc] = NULL;
     474           2 :       optind = start;
     475           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     476             :                         &p_value, &q_value,
     477             :                         &non_options_count, non_options, &unrecognized);
     478           2 :       ASSERT (a_seen == 1);
     479           2 :       ASSERT (b_seen == 0);
     480           2 :       ASSERT (p_value == NULL);
     481           2 :       ASSERT (q_value == NULL);
     482           2 :       ASSERT (non_options_count == 0);
     483           2 :       ASSERT (unrecognized == 0);
     484           2 :       ASSERT (optind == 2);
     485             :     }
     486           3 :   for (start = 0; start <= 1; start++)
     487             :     {
     488           2 :       const char *p_value = NULL;
     489           2 :       const char *q_value = NULL;
     490           2 :       int non_options_count = 0;
     491             :       const char *non_options[10];
     492           2 :       int unrecognized = 0;
     493           2 :       int argc = 0;
     494             :       const char *argv[10];
     495           2 :       a_seen = 0;
     496           2 :       b_seen = 0;
     497             : 
     498           2 :       argv[argc++] = "program";
     499           2 :       argv[argc++] = "--beta";
     500           2 :       argv[argc++] = "--alpha";
     501           2 :       argv[argc++] = "foo";
     502           2 :       argv[argc++] = "bar";
     503           2 :       argv[argc] = NULL;
     504           2 :       optind = start;
     505           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     506             :                         &p_value, &q_value,
     507             :                         &non_options_count, non_options, &unrecognized);
     508           2 :       ASSERT (a_seen == 1);
     509           2 :       ASSERT (b_seen == 1);
     510           2 :       ASSERT (p_value == NULL);
     511           2 :       ASSERT (q_value == NULL);
     512           2 :       ASSERT (non_options_count == 0);
     513           2 :       ASSERT (unrecognized == 0);
     514           2 :       ASSERT (optind == 3);
     515             :     }
     516           3 :   for (start = 0; start <= 1; start++)
     517             :     {
     518           2 :       const char *p_value = NULL;
     519           2 :       const char *q_value = NULL;
     520           2 :       int non_options_count = 0;
     521             :       const char *non_options[10];
     522           2 :       int unrecognized = 0;
     523           2 :       int argc = 0;
     524             :       const char *argv[10];
     525           2 :       a_seen = 0;
     526           2 :       b_seen = 0;
     527             : 
     528           2 :       argv[argc++] = "program";
     529           2 :       argv[argc++] = "--alpha";
     530           2 :       argv[argc++] = "--beta";
     531           2 :       argv[argc++] = "--alpha";
     532           2 :       argv[argc++] = "--beta";
     533           2 :       argv[argc++] = "foo";
     534           2 :       argv[argc++] = "bar";
     535           2 :       argv[argc] = NULL;
     536           2 :       optind = start;
     537           2 :       getopt_long_loop (argc, argv, "ab", long_options_required,
     538             :                         &p_value, &q_value,
     539             :                         &non_options_count, non_options, &unrecognized);
     540           2 :       ASSERT (a_seen == 2);
     541           2 :       ASSERT (b_seen == 1);
     542           2 :       ASSERT (p_value == NULL);
     543           2 :       ASSERT (q_value == NULL);
     544           2 :       ASSERT (non_options_count == 0);
     545           2 :       ASSERT (unrecognized == 0);
     546           2 :       ASSERT (optind == 5);
     547             :     }
     548             : 
     549             :   /* Test processing of boolean long options via -W.  */
     550           3 :   for (start = 0; start <= 1; start++)
     551             :     {
     552           2 :       const char *p_value = NULL;
     553           2 :       const char *q_value = NULL;
     554           2 :       int non_options_count = 0;
     555             :       const char *non_options[10];
     556           2 :       int unrecognized = 0;
     557           2 :       int argc = 0;
     558             :       const char *argv[10];
     559           2 :       a_seen = 0;
     560           2 :       b_seen = 0;
     561             : 
     562           2 :       argv[argc++] = "program";
     563           2 :       argv[argc++] = "-Walpha";
     564           2 :       argv[argc++] = "foo";
     565           2 :       argv[argc++] = "bar";
     566           2 :       argv[argc] = NULL;
     567           2 :       optind = start;
     568           2 :       getopt_long_loop (argc, argv, "abW;", long_options_required,
     569             :                         &p_value, &q_value,
     570             :                         &non_options_count, non_options, &unrecognized);
     571           2 :       ASSERT (a_seen == 1);
     572           2 :       ASSERT (b_seen == 0);
     573           2 :       ASSERT (p_value == NULL);
     574           2 :       ASSERT (q_value == NULL);
     575           2 :       ASSERT (non_options_count == 0);
     576           2 :       ASSERT (unrecognized == 0);
     577           2 :       ASSERT (optind == 2);
     578             :     }
     579           3 :   for (start = 0; start <= 1; start++)
     580             :     {
     581           2 :       const char *p_value = NULL;
     582           2 :       const char *q_value = NULL;
     583           2 :       int non_options_count = 0;
     584             :       const char *non_options[10];
     585           2 :       int unrecognized = 0;
     586           2 :       int argc = 0;
     587             :       const char *argv[10];
     588           2 :       a_seen = 0;
     589           2 :       b_seen = 0;
     590             : 
     591           2 :       argv[argc++] = "program";
     592           2 :       argv[argc++] = "-W";
     593           2 :       argv[argc++] = "beta";
     594           2 :       argv[argc++] = "-W";
     595           2 :       argv[argc++] = "alpha";
     596           2 :       argv[argc++] = "foo";
     597           2 :       argv[argc++] = "bar";
     598           2 :       argv[argc] = NULL;
     599           2 :       optind = start;
     600           2 :       getopt_long_loop (argc, argv, "aW;b", long_options_required,
     601             :                         &p_value, &q_value,
     602             :                         &non_options_count, non_options, &unrecognized);
     603           2 :       ASSERT (a_seen == 1);
     604           2 :       ASSERT (b_seen == 1);
     605           2 :       ASSERT (p_value == NULL);
     606           2 :       ASSERT (q_value == NULL);
     607           2 :       ASSERT (non_options_count == 0);
     608           2 :       ASSERT (unrecognized == 0);
     609           2 :       ASSERT (optind == 5);
     610             :     }
     611           3 :   for (start = 0; start <= 1; start++)
     612             :     {
     613           2 :       const char *p_value = NULL;
     614           2 :       const char *q_value = NULL;
     615           2 :       int non_options_count = 0;
     616             :       const char *non_options[10];
     617           2 :       int unrecognized = 0;
     618           2 :       int argc = 0;
     619             :       const char *argv[10];
     620           2 :       a_seen = 0;
     621           2 :       b_seen = 0;
     622             : 
     623           2 :       argv[argc++] = "program";
     624           2 :       argv[argc++] = "-Walpha";
     625           2 :       argv[argc++] = "-Wbeta";
     626           2 :       argv[argc++] = "-Walpha";
     627           2 :       argv[argc++] = "-Wbeta";
     628           2 :       argv[argc++] = "foo";
     629           2 :       argv[argc++] = "bar";
     630           2 :       argv[argc] = NULL;
     631           2 :       optind = start;
     632           2 :       getopt_long_loop (argc, argv, "W;ab", long_options_required,
     633             :                         &p_value, &q_value,
     634             :                         &non_options_count, non_options, &unrecognized);
     635           2 :       ASSERT (a_seen == 2);
     636           2 :       ASSERT (b_seen == 1);
     637           2 :       ASSERT (p_value == NULL);
     638           2 :       ASSERT (q_value == NULL);
     639           2 :       ASSERT (non_options_count == 0);
     640           2 :       ASSERT (unrecognized == 0);
     641           2 :       ASSERT (optind == 5);
     642             :     }
     643             : 
     644             :   /* Test processing of short options with arguments.  */
     645           3 :   for (start = 0; start <= 1; start++)
     646             :     {
     647           2 :       const char *p_value = NULL;
     648           2 :       const char *q_value = NULL;
     649           2 :       int non_options_count = 0;
     650             :       const char *non_options[10];
     651           2 :       int unrecognized = 0;
     652           2 :       int argc = 0;
     653             :       const char *argv[10];
     654           2 :       a_seen = 0;
     655           2 :       b_seen = 0;
     656             : 
     657           2 :       argv[argc++] = "program";
     658           2 :       argv[argc++] = "-pfoo";
     659           2 :       argv[argc++] = "bar";
     660           2 :       argv[argc] = NULL;
     661           2 :       optind = start;
     662           2 :       getopt_long_loop (argc, argv, "p:q:", long_options_required,
     663             :                         &p_value, &q_value,
     664             :                         &non_options_count, non_options, &unrecognized);
     665           2 :       ASSERT (a_seen == 0);
     666           2 :       ASSERT (b_seen == 0);
     667           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     668           2 :       ASSERT (q_value == NULL);
     669           2 :       ASSERT (non_options_count == 0);
     670           2 :       ASSERT (unrecognized == 0);
     671           2 :       ASSERT (optind == 2);
     672             :     }
     673           3 :   for (start = 0; start <= 1; start++)
     674             :     {
     675           2 :       const char *p_value = NULL;
     676           2 :       const char *q_value = NULL;
     677           2 :       int non_options_count = 0;
     678             :       const char *non_options[10];
     679           2 :       int unrecognized = 0;
     680           2 :       int argc = 0;
     681             :       const char *argv[10];
     682           2 :       a_seen = 0;
     683           2 :       b_seen = 0;
     684             : 
     685           2 :       argv[argc++] = "program";
     686           2 :       argv[argc++] = "-p";
     687           2 :       argv[argc++] = "foo";
     688           2 :       argv[argc++] = "bar";
     689           2 :       argv[argc] = NULL;
     690           2 :       optind = start;
     691           2 :       getopt_long_loop (argc, argv, "p:q:", long_options_required,
     692             :                         &p_value, &q_value,
     693             :                         &non_options_count, non_options, &unrecognized);
     694           2 :       ASSERT (a_seen == 0);
     695           2 :       ASSERT (b_seen == 0);
     696           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     697           2 :       ASSERT (q_value == NULL);
     698           2 :       ASSERT (non_options_count == 0);
     699           2 :       ASSERT (unrecognized == 0);
     700           2 :       ASSERT (optind == 3);
     701             :     }
     702           3 :   for (start = 0; start <= 1; start++)
     703             :     {
     704           2 :       const char *p_value = NULL;
     705           2 :       const char *q_value = NULL;
     706           2 :       int non_options_count = 0;
     707             :       const char *non_options[10];
     708           2 :       int unrecognized = 0;
     709           2 :       int argc = 0;
     710             :       const char *argv[10];
     711           2 :       a_seen = 0;
     712           2 :       b_seen = 0;
     713             : 
     714           2 :       argv[argc++] = "program";
     715           2 :       argv[argc++] = "-ab";
     716           2 :       argv[argc++] = "-q";
     717           2 :       argv[argc++] = "baz";
     718           2 :       argv[argc++] = "-pfoo";
     719           2 :       argv[argc++] = "bar";
     720           2 :       argv[argc] = NULL;
     721           2 :       optind = start;
     722           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
     723             :                         &p_value, &q_value,
     724             :                         &non_options_count, non_options, &unrecognized);
     725           2 :       ASSERT (a_seen == 1);
     726           2 :       ASSERT (b_seen == 1);
     727           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     728           2 :       ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
     729           2 :       ASSERT (non_options_count == 0);
     730           2 :       ASSERT (unrecognized == 0);
     731           2 :       ASSERT (optind == 5);
     732             :     }
     733             : 
     734             :   /* Test processing of long options with arguments.  */
     735           3 :   for (start = 0; start <= 1; start++)
     736             :     {
     737           2 :       const char *p_value = NULL;
     738           2 :       const char *q_value = NULL;
     739           2 :       int non_options_count = 0;
     740             :       const char *non_options[10];
     741           2 :       int unrecognized = 0;
     742           2 :       int argc = 0;
     743             :       const char *argv[10];
     744           2 :       a_seen = 0;
     745           2 :       b_seen = 0;
     746             : 
     747           2 :       argv[argc++] = "program";
     748           2 :       argv[argc++] = "--p=foo";
     749           2 :       argv[argc++] = "bar";
     750           2 :       argv[argc] = NULL;
     751           2 :       optind = start;
     752           2 :       getopt_long_loop (argc, argv, "p:q:", long_options_required,
     753             :                         &p_value, &q_value,
     754             :                         &non_options_count, non_options, &unrecognized);
     755           2 :       ASSERT (a_seen == 0);
     756           2 :       ASSERT (b_seen == 0);
     757           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     758           2 :       ASSERT (q_value == NULL);
     759           2 :       ASSERT (non_options_count == 0);
     760           2 :       ASSERT (unrecognized == 0);
     761           2 :       ASSERT (optind == 2);
     762             :     }
     763           3 :   for (start = 0; start <= 1; start++)
     764             :     {
     765           2 :       const char *p_value = NULL;
     766           2 :       const char *q_value = NULL;
     767           2 :       int non_options_count = 0;
     768             :       const char *non_options[10];
     769           2 :       int unrecognized = 0;
     770           2 :       int argc = 0;
     771             :       const char *argv[10];
     772           2 :       a_seen = 0;
     773           2 :       b_seen = 0;
     774             : 
     775           2 :       argv[argc++] = "program";
     776           2 :       argv[argc++] = "--p";
     777           2 :       argv[argc++] = "foo";
     778           2 :       argv[argc++] = "bar";
     779           2 :       argv[argc] = NULL;
     780           2 :       optind = start;
     781           2 :       getopt_long_loop (argc, argv, "p:q:", long_options_required,
     782             :                         &p_value, &q_value,
     783             :                         &non_options_count, non_options, &unrecognized);
     784           2 :       ASSERT (a_seen == 0);
     785           2 :       ASSERT (b_seen == 0);
     786           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     787           2 :       ASSERT (q_value == NULL);
     788           2 :       ASSERT (non_options_count == 0);
     789           2 :       ASSERT (unrecognized == 0);
     790           2 :       ASSERT (optind == 3);
     791             :     }
     792           3 :   for (start = 0; start <= 1; start++)
     793             :     {
     794           2 :       const char *p_value = NULL;
     795           2 :       const char *q_value = NULL;
     796           2 :       int non_options_count = 0;
     797             :       const char *non_options[10];
     798           2 :       int unrecognized = 0;
     799           2 :       int argc = 0;
     800             :       const char *argv[10];
     801           2 :       a_seen = 0;
     802           2 :       b_seen = 0;
     803             : 
     804           2 :       argv[argc++] = "program";
     805           2 :       argv[argc++] = "-ab";
     806           2 :       argv[argc++] = "--q";
     807           2 :       argv[argc++] = "baz";
     808           2 :       argv[argc++] = "--p=foo";
     809           2 :       argv[argc++] = "bar";
     810           2 :       argv[argc] = NULL;
     811           2 :       optind = start;
     812           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
     813             :                         &p_value, &q_value,
     814             :                         &non_options_count, non_options, &unrecognized);
     815           2 :       ASSERT (a_seen == 1);
     816           2 :       ASSERT (b_seen == 1);
     817           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     818           2 :       ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
     819           2 :       ASSERT (non_options_count == 0);
     820           2 :       ASSERT (unrecognized == 0);
     821           2 :       ASSERT (optind == 5);
     822             :     }
     823             : 
     824             :   /* Test processing of long options with arguments via -W.  */
     825           3 :   for (start = 0; start <= 1; start++)
     826             :     {
     827           2 :       const char *p_value = NULL;
     828           2 :       const char *q_value = NULL;
     829           2 :       int non_options_count = 0;
     830             :       const char *non_options[10];
     831           2 :       int unrecognized = 0;
     832           2 :       int argc = 0;
     833             :       const char *argv[10];
     834           2 :       a_seen = 0;
     835           2 :       b_seen = 0;
     836             : 
     837           2 :       argv[argc++] = "program";
     838           2 :       argv[argc++] = "-Wp=foo";
     839           2 :       argv[argc++] = "bar";
     840           2 :       argv[argc] = NULL;
     841           2 :       optind = start;
     842           2 :       getopt_long_loop (argc, argv, "p:q:W;", long_options_required,
     843             :                         &p_value, &q_value,
     844             :                         &non_options_count, non_options, &unrecognized);
     845           2 :       ASSERT (a_seen == 0);
     846           2 :       ASSERT (b_seen == 0);
     847           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     848           2 :       ASSERT (q_value == NULL);
     849           2 :       ASSERT (non_options_count == 0);
     850           2 :       ASSERT (unrecognized == 0);
     851           2 :       ASSERT (optind == 2);
     852             :     }
     853           3 :   for (start = 0; start <= 1; start++)
     854             :     {
     855           2 :       const char *p_value = NULL;
     856           2 :       const char *q_value = NULL;
     857           2 :       int non_options_count = 0;
     858             :       const char *non_options[10];
     859           2 :       int unrecognized = 0;
     860           2 :       int argc = 0;
     861             :       const char *argv[10];
     862           2 :       a_seen = 0;
     863           2 :       b_seen = 0;
     864             : 
     865           2 :       argv[argc++] = "program";
     866           2 :       argv[argc++] = "-W";
     867           2 :       argv[argc++] = "p";
     868           2 :       argv[argc++] = "foo";
     869           2 :       argv[argc++] = "bar";
     870           2 :       argv[argc] = NULL;
     871           2 :       optind = start;
     872           2 :       getopt_long_loop (argc, argv, "p:W;q:", long_options_required,
     873             :                         &p_value, &q_value,
     874             :                         &non_options_count, non_options, &unrecognized);
     875           2 :       ASSERT (a_seen == 0);
     876           2 :       ASSERT (b_seen == 0);
     877           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     878           2 :       ASSERT (q_value == NULL);
     879           2 :       ASSERT (non_options_count == 0);
     880           2 :       ASSERT (unrecognized == 0);
     881           2 :       ASSERT (optind == 4);
     882             :     }
     883           3 :   for (start = 0; start <= 1; start++)
     884             :     {
     885           2 :       const char *p_value = NULL;
     886           2 :       const char *q_value = NULL;
     887           2 :       int non_options_count = 0;
     888             :       const char *non_options[10];
     889           2 :       int unrecognized = 0;
     890           2 :       int argc = 0;
     891             :       const char *argv[10];
     892           2 :       a_seen = 0;
     893           2 :       b_seen = 0;
     894             : 
     895           2 :       argv[argc++] = "program";
     896           2 :       argv[argc++] = "-ab";
     897           2 :       argv[argc++] = "-Wq";
     898           2 :       argv[argc++] = "baz";
     899           2 :       argv[argc++] = "-W";
     900           2 :       argv[argc++] = "p=foo";
     901           2 :       argv[argc++] = "bar";
     902           2 :       argv[argc] = NULL;
     903           2 :       optind = start;
     904           2 :       getopt_long_loop (argc, argv, "W;abp:q:", long_options_required,
     905             :                         &p_value, &q_value,
     906             :                         &non_options_count, non_options, &unrecognized);
     907           2 :       ASSERT (a_seen == 1);
     908           2 :       ASSERT (b_seen == 1);
     909           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     910           2 :       ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
     911           2 :       ASSERT (non_options_count == 0);
     912           2 :       ASSERT (unrecognized == 0);
     913           2 :       ASSERT (optind == 6);
     914             :     }
     915             : 
     916             :   /* Test processing of short options with optional arguments.  */
     917           3 :   for (start = 0; start <= 1; start++)
     918             :     {
     919           2 :       const char *p_value = NULL;
     920           2 :       const char *q_value = NULL;
     921           2 :       int non_options_count = 0;
     922             :       const char *non_options[10];
     923           2 :       int unrecognized = 0;
     924           2 :       int argc = 0;
     925             :       const char *argv[10];
     926           2 :       a_seen = 0;
     927           2 :       b_seen = 0;
     928             : 
     929           2 :       argv[argc++] = "program";
     930           2 :       argv[argc++] = "-pfoo";
     931           2 :       argv[argc++] = "bar";
     932           2 :       argv[argc] = NULL;
     933           2 :       optind = start;
     934           2 :       getopt_long_loop (argc, argv, "p::q::", long_options_optional,
     935             :                         &p_value, &q_value,
     936             :                         &non_options_count, non_options, &unrecognized);
     937           2 :       ASSERT (a_seen == 0);
     938           2 :       ASSERT (b_seen == 0);
     939           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
     940           2 :       ASSERT (q_value == NULL);
     941           2 :       ASSERT (non_options_count == 0);
     942           2 :       ASSERT (unrecognized == 0);
     943           2 :       ASSERT (optind == 2);
     944             :     }
     945           3 :   for (start = 0; start <= 1; start++)
     946             :     {
     947           2 :       const char *p_value = NULL;
     948           2 :       const char *q_value = NULL;
     949           2 :       int non_options_count = 0;
     950             :       const char *non_options[10];
     951           2 :       int unrecognized = 0;
     952           2 :       int argc = 0;
     953             :       const char *argv[10];
     954           2 :       a_seen = 0;
     955           2 :       b_seen = 0;
     956             : 
     957           2 :       argv[argc++] = "program";
     958           2 :       argv[argc++] = "-p";
     959           2 :       argv[argc++] = "foo";
     960           2 :       argv[argc++] = "bar";
     961           2 :       argv[argc] = NULL;
     962           2 :       optind = start;
     963           2 :       getopt_long_loop (argc, argv, "p::q::", long_options_optional,
     964             :                         &p_value, &q_value,
     965             :                         &non_options_count, non_options, &unrecognized);
     966           2 :       ASSERT (a_seen == 0);
     967           2 :       ASSERT (b_seen == 0);
     968           2 :       ASSERT (p_value == NULL);
     969           2 :       ASSERT (q_value == NULL);
     970           2 :       ASSERT (non_options_count == 0);
     971           2 :       ASSERT (unrecognized == 0);
     972           2 :       ASSERT (optind == 2);
     973             :     }
     974           3 :   for (start = 0; start <= 1; start++)
     975             :     {
     976           2 :       const char *p_value = NULL;
     977           2 :       const char *q_value = NULL;
     978           2 :       int non_options_count = 0;
     979             :       const char *non_options[10];
     980           2 :       int unrecognized = 0;
     981           2 :       int argc = 0;
     982             :       const char *argv[10];
     983           2 :       a_seen = 0;
     984           2 :       b_seen = 0;
     985             : 
     986           2 :       argv[argc++] = "program";
     987           2 :       argv[argc++] = "-p";
     988           2 :       argv[argc++] = "-a";
     989           2 :       argv[argc++] = "bar";
     990           2 :       argv[argc] = NULL;
     991           2 :       optind = start;
     992           2 :       getopt_long_loop (argc, argv, "abp::q::", long_options_optional,
     993             :                         &p_value, &q_value,
     994             :                         &non_options_count, non_options, &unrecognized);
     995           2 :       ASSERT (a_seen == 1);
     996           2 :       ASSERT (b_seen == 0);
     997           2 :       ASSERT (p_value == NULL);
     998           2 :       ASSERT (q_value == NULL);
     999           2 :       ASSERT (non_options_count == 0);
    1000           2 :       ASSERT (unrecognized == 0);
    1001           2 :       ASSERT (optind == 3);
    1002             :     }
    1003             : 
    1004             :   /* Test processing of long options with optional arguments.  */
    1005           3 :   for (start = 0; start <= 1; start++)
    1006             :     {
    1007           2 :       const char *p_value = NULL;
    1008           2 :       const char *q_value = NULL;
    1009           2 :       int non_options_count = 0;
    1010             :       const char *non_options[10];
    1011           2 :       int unrecognized = 0;
    1012           2 :       int argc = 0;
    1013             :       const char *argv[10];
    1014           2 :       a_seen = 0;
    1015           2 :       b_seen = 0;
    1016             : 
    1017           2 :       argv[argc++] = "program";
    1018           2 :       argv[argc++] = "--p=foo";
    1019           2 :       argv[argc++] = "bar";
    1020           2 :       argv[argc] = NULL;
    1021           2 :       optind = start;
    1022           2 :       getopt_long_loop (argc, argv, "p::q::", long_options_optional,
    1023             :                         &p_value, &q_value,
    1024             :                         &non_options_count, non_options, &unrecognized);
    1025           2 :       ASSERT (a_seen == 0);
    1026           2 :       ASSERT (b_seen == 0);
    1027           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
    1028           2 :       ASSERT (q_value == NULL);
    1029           2 :       ASSERT (non_options_count == 0);
    1030           2 :       ASSERT (unrecognized == 0);
    1031           2 :       ASSERT (optind == 2);
    1032             :     }
    1033           3 :   for (start = 0; start <= 1; start++)
    1034             :     {
    1035           2 :       const char *p_value = NULL;
    1036           2 :       const char *q_value = NULL;
    1037           2 :       int non_options_count = 0;
    1038             :       const char *non_options[10];
    1039           2 :       int unrecognized = 0;
    1040           2 :       int argc = 0;
    1041             :       const char *argv[10];
    1042           2 :       a_seen = 0;
    1043           2 :       b_seen = 0;
    1044             : 
    1045           2 :       argv[argc++] = "program";
    1046           2 :       argv[argc++] = "--p";
    1047           2 :       argv[argc++] = "foo";
    1048           2 :       argv[argc++] = "bar";
    1049           2 :       argv[argc] = NULL;
    1050           2 :       optind = start;
    1051           2 :       getopt_long_loop (argc, argv, "p::q::", long_options_optional,
    1052             :                         &p_value, &q_value,
    1053             :                         &non_options_count, non_options, &unrecognized);
    1054           2 :       ASSERT (a_seen == 0);
    1055           2 :       ASSERT (b_seen == 0);
    1056           2 :       ASSERT (p_value == NULL);
    1057           2 :       ASSERT (q_value == NULL);
    1058           2 :       ASSERT (non_options_count == 0);
    1059           2 :       ASSERT (unrecognized == 0);
    1060           2 :       ASSERT (optind == 2);
    1061             :     }
    1062           3 :   for (start = 0; start <= 1; start++)
    1063             :     {
    1064           2 :       const char *p_value = NULL;
    1065           2 :       const char *q_value = NULL;
    1066           2 :       int non_options_count = 0;
    1067             :       const char *non_options[10];
    1068           2 :       int unrecognized = 0;
    1069           2 :       int argc = 0;
    1070             :       const char *argv[10];
    1071           2 :       a_seen = 0;
    1072           2 :       b_seen = 0;
    1073             : 
    1074           2 :       argv[argc++] = "program";
    1075           2 :       argv[argc++] = "--p=";
    1076           2 :       argv[argc++] = "foo";
    1077           2 :       argv[argc++] = "bar";
    1078           2 :       argv[argc] = NULL;
    1079           2 :       optind = start;
    1080           2 :       getopt_long_loop (argc, argv, "p::q::", long_options_optional,
    1081             :                         &p_value, &q_value,
    1082             :                         &non_options_count, non_options, &unrecognized);
    1083           2 :       ASSERT (a_seen == 0);
    1084           2 :       ASSERT (b_seen == 0);
    1085           2 :       ASSERT (p_value != NULL && *p_value == '\0');
    1086           2 :       ASSERT (q_value == NULL);
    1087           2 :       ASSERT (non_options_count == 0);
    1088           2 :       ASSERT (unrecognized == 0);
    1089           2 :       ASSERT (optind == 2);
    1090             :     }
    1091           3 :   for (start = 0; start <= 1; start++)
    1092             :     {
    1093           2 :       const char *p_value = NULL;
    1094           2 :       const char *q_value = NULL;
    1095           2 :       int non_options_count = 0;
    1096             :       const char *non_options[10];
    1097           2 :       int unrecognized = 0;
    1098           2 :       int argc = 0;
    1099             :       const char *argv[10];
    1100           2 :       a_seen = 0;
    1101           2 :       b_seen = 0;
    1102             : 
    1103           2 :       argv[argc++] = "program";
    1104           2 :       argv[argc++] = "--p";
    1105           2 :       argv[argc++] = "-a";
    1106           2 :       argv[argc++] = "bar";
    1107           2 :       argv[argc] = NULL;
    1108           2 :       optind = start;
    1109           2 :       getopt_long_loop (argc, argv, "abp::q::", long_options_optional,
    1110             :                         &p_value, &q_value,
    1111             :                         &non_options_count, non_options, &unrecognized);
    1112           2 :       ASSERT (a_seen == 1);
    1113           2 :       ASSERT (b_seen == 0);
    1114           2 :       ASSERT (p_value == NULL);
    1115           2 :       ASSERT (q_value == NULL);
    1116           2 :       ASSERT (non_options_count == 0);
    1117           2 :       ASSERT (unrecognized == 0);
    1118           2 :       ASSERT (optind == 3);
    1119             :     }
    1120             : 
    1121             :   /* Test processing of long options with optional arguments via -W.  */
    1122           3 :   for (start = 0; start <= 1; start++)
    1123             :     {
    1124           2 :       const char *p_value = NULL;
    1125           2 :       const char *q_value = NULL;
    1126           2 :       int non_options_count = 0;
    1127             :       const char *non_options[10];
    1128           2 :       int unrecognized = 0;
    1129           2 :       int argc = 0;
    1130             :       const char *argv[10];
    1131           2 :       a_seen = 0;
    1132           2 :       b_seen = 0;
    1133             : 
    1134           2 :       argv[argc++] = "program";
    1135           2 :       argv[argc++] = "-Wp=foo";
    1136           2 :       argv[argc++] = "bar";
    1137           2 :       argv[argc] = NULL;
    1138           2 :       optind = start;
    1139           2 :       getopt_long_loop (argc, argv, "p::q::W;", long_options_optional,
    1140             :                         &p_value, &q_value,
    1141             :                         &non_options_count, non_options, &unrecognized);
    1142           2 :       ASSERT (a_seen == 0);
    1143           2 :       ASSERT (b_seen == 0);
    1144           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
    1145           2 :       ASSERT (q_value == NULL);
    1146           2 :       ASSERT (non_options_count == 0);
    1147           2 :       ASSERT (unrecognized == 0);
    1148           2 :       ASSERT (optind == 2);
    1149             :     }
    1150           3 :   for (start = 0; start <= 1; start++)
    1151             :     {
    1152           2 :       const char *p_value = NULL;
    1153           2 :       const char *q_value = NULL;
    1154           2 :       int non_options_count = 0;
    1155             :       const char *non_options[10];
    1156           2 :       int unrecognized = 0;
    1157           2 :       int argc = 0;
    1158             :       const char *argv[10];
    1159           2 :       a_seen = 0;
    1160           2 :       b_seen = 0;
    1161             : 
    1162           2 :       argv[argc++] = "program";
    1163           2 :       argv[argc++] = "-Wp";
    1164           2 :       argv[argc++] = "foo";
    1165           2 :       argv[argc++] = "bar";
    1166           2 :       argv[argc] = NULL;
    1167           2 :       optind = start;
    1168           2 :       getopt_long_loop (argc, argv, "p::q::W;", long_options_optional,
    1169             :                         &p_value, &q_value,
    1170             :                         &non_options_count, non_options, &unrecognized);
    1171           2 :       ASSERT (a_seen == 0);
    1172           2 :       ASSERT (b_seen == 0);
    1173           2 :       ASSERT (p_value == NULL);
    1174           2 :       ASSERT (q_value == NULL);
    1175           2 :       ASSERT (non_options_count == 0);
    1176           2 :       ASSERT (unrecognized == 0);
    1177           2 :       ASSERT (optind == 2);
    1178             :     }
    1179           3 :   for (start = 0; start <= 1; start++)
    1180             :     {
    1181           2 :       const char *p_value = NULL;
    1182           2 :       const char *q_value = NULL;
    1183           2 :       int non_options_count = 0;
    1184             :       const char *non_options[10];
    1185           2 :       int unrecognized = 0;
    1186           2 :       int argc = 0;
    1187             :       const char *argv[10];
    1188           2 :       a_seen = 0;
    1189           2 :       b_seen = 0;
    1190             : 
    1191           2 :       argv[argc++] = "program";
    1192           2 :       argv[argc++] = "-Wp=";
    1193           2 :       argv[argc++] = "foo";
    1194           2 :       argv[argc++] = "bar";
    1195           2 :       argv[argc] = NULL;
    1196           2 :       optind = start;
    1197           2 :       getopt_long_loop (argc, argv, "W;p::q::", long_options_optional,
    1198             :                         &p_value, &q_value,
    1199             :                         &non_options_count, non_options, &unrecognized);
    1200           2 :       ASSERT (a_seen == 0);
    1201           2 :       ASSERT (b_seen == 0);
    1202           2 :       ASSERT (p_value != NULL && *p_value == '\0');
    1203           2 :       ASSERT (q_value == NULL);
    1204           2 :       ASSERT (non_options_count == 0);
    1205           2 :       ASSERT (unrecognized == 0);
    1206           2 :       ASSERT (optind == 2);
    1207             :     }
    1208           3 :   for (start = 0; start <= 1; start++)
    1209             :     {
    1210           2 :       const char *p_value = NULL;
    1211           2 :       const char *q_value = NULL;
    1212           2 :       int non_options_count = 0;
    1213             :       const char *non_options[10];
    1214           2 :       int unrecognized = 0;
    1215           2 :       int argc = 0;
    1216             :       const char *argv[10];
    1217           2 :       a_seen = 0;
    1218           2 :       b_seen = 0;
    1219             : 
    1220           2 :       argv[argc++] = "program";
    1221           2 :       argv[argc++] = "-W";
    1222           2 :       argv[argc++] = "p=";
    1223           2 :       argv[argc++] = "foo";
    1224           2 :       argv[argc++] = "bar";
    1225           2 :       argv[argc] = NULL;
    1226           2 :       optind = start;
    1227           2 :       getopt_long_loop (argc, argv, "W;p::q::", long_options_optional,
    1228             :                         &p_value, &q_value,
    1229             :                         &non_options_count, non_options, &unrecognized);
    1230           2 :       ASSERT (a_seen == 0);
    1231           2 :       ASSERT (b_seen == 0);
    1232           2 :       ASSERT (p_value != NULL && *p_value == '\0');
    1233           2 :       ASSERT (q_value == NULL);
    1234           2 :       ASSERT (non_options_count == 0);
    1235           2 :       ASSERT (unrecognized == 0);
    1236           2 :       ASSERT (optind == 3);
    1237             :     }
    1238           3 :   for (start = 0; start <= 1; start++)
    1239             :     {
    1240           2 :       const char *p_value = NULL;
    1241           2 :       const char *q_value = NULL;
    1242           2 :       int non_options_count = 0;
    1243             :       const char *non_options[10];
    1244           2 :       int unrecognized = 0;
    1245           2 :       int argc = 0;
    1246             :       const char *argv[10];
    1247           2 :       a_seen = 0;
    1248           2 :       b_seen = 0;
    1249             : 
    1250           2 :       argv[argc++] = "program";
    1251           2 :       argv[argc++] = "-W";
    1252           2 :       argv[argc++] = "p";
    1253           2 :       argv[argc++] = "-a";
    1254           2 :       argv[argc++] = "bar";
    1255           2 :       argv[argc] = NULL;
    1256           2 :       optind = start;
    1257           2 :       getopt_long_loop (argc, argv, "W;abp::q::", long_options_optional,
    1258             :                         &p_value, &q_value,
    1259             :                         &non_options_count, non_options, &unrecognized);
    1260           2 :       ASSERT (a_seen == 1);
    1261           2 :       ASSERT (b_seen == 0);
    1262             :       /* ASSERT (p_value == NULL); */
    1263           2 :       ASSERT (q_value == NULL);
    1264           2 :       ASSERT (non_options_count == 0);
    1265           2 :       ASSERT (unrecognized == 0);
    1266           2 :       ASSERT (optind == 4);
    1267             :     }
    1268             : 
    1269             :   /* Check that invalid options are recognized.  */
    1270           3 :   for (start = 0; start <= 1; start++)
    1271             :     {
    1272           2 :       const char *p_value = NULL;
    1273           2 :       const char *q_value = NULL;
    1274           2 :       int non_options_count = 0;
    1275             :       const char *non_options[10];
    1276           2 :       int unrecognized = 0;
    1277           2 :       int argc = 0;
    1278             :       const char *argv[10];
    1279           2 :       a_seen = 0;
    1280           2 :       b_seen = 0;
    1281             : 
    1282           2 :       argv[argc++] = "program";
    1283           2 :       argv[argc++] = "-p";
    1284           2 :       argv[argc++] = "foo";
    1285           2 :       argv[argc++] = "-x";
    1286           2 :       argv[argc++] = "-a";
    1287           2 :       argv[argc++] = "bar";
    1288           2 :       argv[argc] = NULL;
    1289           2 :       optind = start;
    1290           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1291             :                         &p_value, &q_value,
    1292             :                         &non_options_count, non_options, &unrecognized);
    1293           2 :       ASSERT (a_seen == 1);
    1294           2 :       ASSERT (b_seen == 0);
    1295           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
    1296           2 :       ASSERT (q_value == NULL);
    1297           2 :       ASSERT (non_options_count == 0);
    1298           2 :       ASSERT (unrecognized == 'x');
    1299           2 :       ASSERT (optind == 5);
    1300             :     }
    1301           3 :   for (start = 0; start <= 1; start++)
    1302             :     {
    1303           2 :       const char *p_value = NULL;
    1304           2 :       const char *q_value = NULL;
    1305           2 :       int non_options_count = 0;
    1306             :       const char *non_options[10];
    1307           2 :       int unrecognized = 0;
    1308           2 :       int argc = 0;
    1309             :       const char *argv[10];
    1310           2 :       a_seen = 0;
    1311           2 :       b_seen = 0;
    1312             : 
    1313           2 :       argv[argc++] = "program";
    1314           2 :       argv[argc++] = "-p";
    1315           2 :       argv[argc++] = "foo";
    1316           2 :       argv[argc++] = "-:";
    1317           2 :       argv[argc++] = "-a";
    1318           2 :       argv[argc++] = "bar";
    1319           2 :       argv[argc] = NULL;
    1320           2 :       optind = start;
    1321           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1322             :                         &p_value, &q_value,
    1323             :                         &non_options_count, non_options, &unrecognized);
    1324           2 :       ASSERT (a_seen == 1);
    1325           2 :       ASSERT (b_seen == 0);
    1326           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
    1327           2 :       ASSERT (q_value == NULL);
    1328           2 :       ASSERT (non_options_count == 0);
    1329           2 :       ASSERT (unrecognized == ':');
    1330           2 :       ASSERT (optind == 5);
    1331             :     }
    1332             : 
    1333             :   /* Check that unexpected arguments are recognized.  */
    1334           3 :   for (start = 0; start <= 1; start++)
    1335             :     {
    1336           2 :       const char *p_value = NULL;
    1337           2 :       const char *q_value = NULL;
    1338           2 :       int non_options_count = 0;
    1339             :       const char *non_options[10];
    1340           2 :       int unrecognized = 0;
    1341           2 :       int argc = 0;
    1342             :       const char *argv[10];
    1343           2 :       a_seen = 0;
    1344           2 :       b_seen = 0;
    1345             : 
    1346           2 :       argv[argc++] = "program";
    1347           2 :       argv[argc++] = "-p";
    1348           2 :       argv[argc++] = "foo";
    1349           2 :       argv[argc++] = "--a=";
    1350           2 :       argv[argc++] = "bar";
    1351           2 :       argv[argc] = NULL;
    1352           2 :       optind = start;
    1353           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1354             :                         &p_value, &q_value,
    1355             :                         &non_options_count, non_options, &unrecognized);
    1356           2 :       ASSERT (a_seen == 0);
    1357           2 :       ASSERT (b_seen == 0);
    1358           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
    1359           2 :       ASSERT (q_value == NULL);
    1360           2 :       ASSERT (non_options_count == 0);
    1361           2 :       ASSERT (unrecognized == 'a');
    1362           2 :       ASSERT (optind == 4);
    1363             :     }
    1364           3 :   for (start = 0; start <= 1; start++)
    1365             :     {
    1366           2 :       const char *p_value = NULL;
    1367           2 :       const char *q_value = NULL;
    1368           2 :       int non_options_count = 0;
    1369             :       const char *non_options[10];
    1370           2 :       int unrecognized = 0;
    1371           2 :       int argc = 0;
    1372             :       const char *argv[10];
    1373           2 :       a_seen = 0;
    1374           2 :       b_seen = 0;
    1375             : 
    1376           2 :       argv[argc++] = "program";
    1377           2 :       argv[argc++] = "-p";
    1378           2 :       argv[argc++] = "foo";
    1379           2 :       argv[argc++] = "--b=";
    1380           2 :       argv[argc++] = "bar";
    1381           2 :       argv[argc] = NULL;
    1382           2 :       optind = start;
    1383           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1384             :                         &p_value, &q_value,
    1385             :                         &non_options_count, non_options, &unrecognized);
    1386           2 :       ASSERT (a_seen == 0);
    1387           2 :       ASSERT (b_seen == 0);
    1388           2 :       ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
    1389           2 :       ASSERT (q_value == NULL);
    1390           2 :       ASSERT (non_options_count == 0);
    1391             :       /* When flag is non-zero, glibc sets optopt anyway, but BSD
    1392             :          leaves optopt unchanged.  */
    1393           2 :       ASSERT (unrecognized == 1 || unrecognized == 0);
    1394           2 :       ASSERT (optind == 4);
    1395             :     }
    1396             : 
    1397             :   /* Check that by default, non-options arguments are moved to the end.  */
    1398           3 :   for (start = 0; start <= 1; start++)
    1399             :     {
    1400           2 :       const char *p_value = NULL;
    1401           2 :       const char *q_value = NULL;
    1402           2 :       int non_options_count = 0;
    1403             :       const char *non_options[10];
    1404           2 :       int unrecognized = 0;
    1405           2 :       int argc = 0;
    1406             :       const char *argv[10];
    1407           2 :       a_seen = 0;
    1408           2 :       b_seen = 0;
    1409             : 
    1410           2 :       argv[argc++] = "program";
    1411           2 :       argv[argc++] = "donald";
    1412           2 :       argv[argc++] = "-p";
    1413           2 :       argv[argc++] = "billy";
    1414           2 :       argv[argc++] = "duck";
    1415           2 :       argv[argc++] = "-a";
    1416           2 :       argv[argc++] = "bar";
    1417           2 :       argv[argc] = NULL;
    1418           2 :       optind = start;
    1419           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1420             :                         &p_value, &q_value,
    1421             :                         &non_options_count, non_options, &unrecognized);
    1422           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1423           2 :       ASSERT (strcmp (argv[1], "-p") == 0);
    1424           2 :       ASSERT (strcmp (argv[2], "billy") == 0);
    1425           2 :       ASSERT (strcmp (argv[3], "-a") == 0);
    1426           2 :       ASSERT (strcmp (argv[4], "donald") == 0);
    1427           2 :       ASSERT (strcmp (argv[5], "duck") == 0);
    1428           2 :       ASSERT (strcmp (argv[6], "bar") == 0);
    1429           2 :       ASSERT (argv[7] == NULL);
    1430           2 :       ASSERT (a_seen == 1);
    1431           2 :       ASSERT (b_seen == 0);
    1432           2 :       ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
    1433           2 :       ASSERT (q_value == NULL);
    1434           2 :       ASSERT (non_options_count == 0);
    1435           2 :       ASSERT (unrecognized == 0);
    1436           2 :       ASSERT (optind == 4);
    1437             :     }
    1438             : 
    1439             :   /* Check that '--' ends the argument processing.  */
    1440           3 :   for (start = 0; start <= 1; start++)
    1441             :     {
    1442           2 :       const char *p_value = NULL;
    1443           2 :       const char *q_value = NULL;
    1444           2 :       int non_options_count = 0;
    1445             :       const char *non_options[10];
    1446           2 :       int unrecognized = 0;
    1447           2 :       int argc = 0;
    1448             :       const char *argv[20];
    1449           2 :       a_seen = 0;
    1450           2 :       b_seen = 0;
    1451             : 
    1452           2 :       argv[argc++] = "program";
    1453           2 :       argv[argc++] = "donald";
    1454           2 :       argv[argc++] = "-p";
    1455           2 :       argv[argc++] = "billy";
    1456           2 :       argv[argc++] = "duck";
    1457           2 :       argv[argc++] = "-a";
    1458           2 :       argv[argc++] = "--";
    1459           2 :       argv[argc++] = "-b";
    1460           2 :       argv[argc++] = "foo";
    1461           2 :       argv[argc++] = "-q";
    1462           2 :       argv[argc++] = "johnny";
    1463           2 :       argv[argc++] = "bar";
    1464           2 :       argv[argc] = NULL;
    1465           2 :       optind = start;
    1466           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1467             :                         &p_value, &q_value,
    1468             :                         &non_options_count, non_options, &unrecognized);
    1469           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1470           2 :       ASSERT (strcmp (argv[1], "-p") == 0);
    1471           2 :       ASSERT (strcmp (argv[2], "billy") == 0);
    1472           2 :       ASSERT (strcmp (argv[3], "-a") == 0);
    1473           2 :       ASSERT (strcmp (argv[4], "--") == 0);
    1474           2 :       ASSERT (strcmp (argv[5], "donald") == 0);
    1475           2 :       ASSERT (strcmp (argv[6], "duck") == 0);
    1476           2 :       ASSERT (strcmp (argv[7], "-b") == 0);
    1477           2 :       ASSERT (strcmp (argv[8], "foo") == 0);
    1478           2 :       ASSERT (strcmp (argv[9], "-q") == 0);
    1479           2 :       ASSERT (strcmp (argv[10], "johnny") == 0);
    1480           2 :       ASSERT (strcmp (argv[11], "bar") == 0);
    1481           2 :       ASSERT (argv[12] == NULL);
    1482           2 :       ASSERT (a_seen == 1);
    1483           2 :       ASSERT (b_seen == 0);
    1484           2 :       ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
    1485           2 :       ASSERT (q_value == NULL);
    1486           2 :       ASSERT (non_options_count == 0);
    1487           2 :       ASSERT (unrecognized == 0);
    1488           2 :       ASSERT (optind == 5);
    1489             :     }
    1490             : 
    1491             :   /* Check that the '-' flag causes non-options to be returned in order.  */
    1492           3 :   for (start = 0; start <= 1; start++)
    1493             :     {
    1494           2 :       const char *p_value = NULL;
    1495           2 :       const char *q_value = NULL;
    1496           2 :       int non_options_count = 0;
    1497             :       const char *non_options[10];
    1498           2 :       int unrecognized = 0;
    1499           2 :       int argc = 0;
    1500             :       const char *argv[10];
    1501           2 :       a_seen = 0;
    1502           2 :       b_seen = 0;
    1503             : 
    1504           2 :       argv[argc++] = "program";
    1505           2 :       argv[argc++] = "donald";
    1506           2 :       argv[argc++] = "-p";
    1507           2 :       argv[argc++] = "billy";
    1508           2 :       argv[argc++] = "duck";
    1509           2 :       argv[argc++] = "-a";
    1510           2 :       argv[argc++] = "bar";
    1511           2 :       argv[argc] = NULL;
    1512           2 :       optind = start;
    1513           2 :       getopt_long_loop (argc, argv, "-abp:q:", long_options_required,
    1514             :                         &p_value, &q_value,
    1515             :                         &non_options_count, non_options, &unrecognized);
    1516           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1517           2 :       ASSERT (strcmp (argv[1], "donald") == 0);
    1518           2 :       ASSERT (strcmp (argv[2], "-p") == 0);
    1519           2 :       ASSERT (strcmp (argv[3], "billy") == 0);
    1520           2 :       ASSERT (strcmp (argv[4], "duck") == 0);
    1521           2 :       ASSERT (strcmp (argv[5], "-a") == 0);
    1522           2 :       ASSERT (strcmp (argv[6], "bar") == 0);
    1523           2 :       ASSERT (argv[7] == NULL);
    1524           2 :       ASSERT (a_seen == 1);
    1525           2 :       ASSERT (b_seen == 0);
    1526           2 :       ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
    1527           2 :       ASSERT (q_value == NULL);
    1528           2 :       ASSERT (non_options_count == 3);
    1529           2 :       ASSERT (strcmp (non_options[0], "donald") == 0);
    1530           2 :       ASSERT (strcmp (non_options[1], "duck") == 0);
    1531           2 :       ASSERT (strcmp (non_options[2], "bar") == 0);
    1532           2 :       ASSERT (unrecognized == 0);
    1533           2 :       ASSERT (optind == 7);
    1534             :     }
    1535             : 
    1536             :   /* Check that '--' ends the argument processing.  */
    1537           3 :   for (start = 0; start <= 1; start++)
    1538             :     {
    1539           2 :       const char *p_value = NULL;
    1540           2 :       const char *q_value = NULL;
    1541           2 :       int non_options_count = 0;
    1542             :       const char *non_options[10];
    1543           2 :       int unrecognized = 0;
    1544           2 :       int argc = 0;
    1545             :       const char *argv[20];
    1546           2 :       a_seen = 0;
    1547           2 :       b_seen = 0;
    1548             : 
    1549           2 :       argv[argc++] = "program";
    1550           2 :       argv[argc++] = "donald";
    1551           2 :       argv[argc++] = "-p";
    1552           2 :       argv[argc++] = "billy";
    1553           2 :       argv[argc++] = "duck";
    1554           2 :       argv[argc++] = "-a";
    1555           2 :       argv[argc++] = "--";
    1556           2 :       argv[argc++] = "-b";
    1557           2 :       argv[argc++] = "foo";
    1558           2 :       argv[argc++] = "-q";
    1559           2 :       argv[argc++] = "johnny";
    1560           2 :       argv[argc++] = "bar";
    1561           2 :       argv[argc] = NULL;
    1562           2 :       optind = start;
    1563           2 :       getopt_long_loop (argc, argv, "-abp:q:", long_options_required,
    1564             :                         &p_value, &q_value,
    1565             :                         &non_options_count, non_options, &unrecognized);
    1566           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1567           2 :       ASSERT (strcmp (argv[1], "donald") == 0);
    1568           2 :       ASSERT (strcmp (argv[2], "-p") == 0);
    1569           2 :       ASSERT (strcmp (argv[3], "billy") == 0);
    1570           2 :       ASSERT (strcmp (argv[4], "duck") == 0);
    1571           2 :       ASSERT (strcmp (argv[5], "-a") == 0);
    1572           2 :       ASSERT (strcmp (argv[6], "--") == 0);
    1573           2 :       ASSERT (strcmp (argv[7], "-b") == 0);
    1574           2 :       ASSERT (strcmp (argv[8], "foo") == 0);
    1575           2 :       ASSERT (strcmp (argv[9], "-q") == 0);
    1576           2 :       ASSERT (strcmp (argv[10], "johnny") == 0);
    1577           2 :       ASSERT (strcmp (argv[11], "bar") == 0);
    1578           2 :       ASSERT (argv[12] == NULL);
    1579           2 :       ASSERT (a_seen == 1);
    1580           2 :       ASSERT (b_seen == 0);
    1581           2 :       ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
    1582           2 :       ASSERT (q_value == NULL);
    1583           2 :       if (non_options_count == 2)
    1584             :       {
    1585             :         /* glibc behaviour.  */
    1586           2 :         ASSERT (non_options_count == 2);
    1587           2 :         ASSERT (strcmp (non_options[0], "donald") == 0);
    1588           2 :         ASSERT (strcmp (non_options[1], "duck") == 0);
    1589           2 :         ASSERT (unrecognized == 0);
    1590           2 :         ASSERT (optind == 7);
    1591             :       }
    1592             :       else
    1593             :       {
    1594             :         /* Another valid behaviour.  */
    1595           0 :         ASSERT (non_options_count == 7);
    1596           0 :         ASSERT (strcmp (non_options[0], "donald") == 0);
    1597           0 :         ASSERT (strcmp (non_options[1], "duck") == 0);
    1598           0 :         ASSERT (strcmp (non_options[2], "-b") == 0);
    1599           0 :         ASSERT (strcmp (non_options[3], "foo") == 0);
    1600           0 :         ASSERT (strcmp (non_options[4], "-q") == 0);
    1601           0 :         ASSERT (strcmp (non_options[5], "johnny") == 0);
    1602           0 :         ASSERT (strcmp (non_options[6], "bar") == 0);
    1603           0 :         ASSERT (unrecognized == 0);
    1604           0 :         ASSERT (optind == 12);
    1605             :       }
    1606             :     }
    1607             : 
    1608             :   /* Check that the '-' flag has to come first.  */
    1609           3 :   for (start = 0; start <= 1; start++)
    1610             :     {
    1611           2 :       const char *p_value = NULL;
    1612           2 :       const char *q_value = NULL;
    1613           2 :       int non_options_count = 0;
    1614             :       const char *non_options[10];
    1615           2 :       int unrecognized = 0;
    1616           2 :       int argc = 0;
    1617             :       const char *argv[10];
    1618           2 :       a_seen = 0;
    1619           2 :       b_seen = 0;
    1620             : 
    1621           2 :       argv[argc++] = "program";
    1622           2 :       argv[argc++] = "donald";
    1623           2 :       argv[argc++] = "-p";
    1624           2 :       argv[argc++] = "billy";
    1625           2 :       argv[argc++] = "duck";
    1626           2 :       argv[argc++] = "-a";
    1627           2 :       argv[argc++] = "bar";
    1628           2 :       argv[argc] = NULL;
    1629           2 :       optind = start;
    1630           2 :       getopt_long_loop (argc, argv, "abp:q:-", long_options_required,
    1631             :                         &p_value, &q_value,
    1632             :                         &non_options_count, non_options, &unrecognized);
    1633           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1634           2 :       ASSERT (strcmp (argv[1], "-p") == 0);
    1635           2 :       ASSERT (strcmp (argv[2], "billy") == 0);
    1636           2 :       ASSERT (strcmp (argv[3], "-a") == 0);
    1637           2 :       ASSERT (strcmp (argv[4], "donald") == 0);
    1638           2 :       ASSERT (strcmp (argv[5], "duck") == 0);
    1639           2 :       ASSERT (strcmp (argv[6], "bar") == 0);
    1640           2 :       ASSERT (argv[7] == NULL);
    1641           2 :       ASSERT (a_seen == 1);
    1642           2 :       ASSERT (b_seen == 0);
    1643           2 :       ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
    1644           2 :       ASSERT (q_value == NULL);
    1645           2 :       ASSERT (non_options_count == 0);
    1646           2 :       ASSERT (unrecognized == 0);
    1647           2 :       ASSERT (optind == 4);
    1648             :     }
    1649             : 
    1650             :   /* Check that the '+' flag causes the first non-option to terminate the
    1651             :      loop.  */
    1652           3 :   for (start = 0; start <= 1; start++)
    1653             :     {
    1654           2 :       const char *p_value = NULL;
    1655           2 :       const char *q_value = NULL;
    1656           2 :       int non_options_count = 0;
    1657             :       const char *non_options[10];
    1658           2 :       int unrecognized = 0;
    1659           2 :       int argc = 0;
    1660             :       const char *argv[10];
    1661           2 :       a_seen = 0;
    1662           2 :       b_seen = 0;
    1663             : 
    1664           2 :       argv[argc++] = "program";
    1665           2 :       argv[argc++] = "donald";
    1666           2 :       argv[argc++] = "-p";
    1667           2 :       argv[argc++] = "billy";
    1668           2 :       argv[argc++] = "duck";
    1669           2 :       argv[argc++] = "-a";
    1670           2 :       argv[argc++] = "bar";
    1671           2 :       argv[argc] = NULL;
    1672           2 :       optind = start;
    1673           2 :       getopt_long_loop (argc, argv, "+abp:q:", long_options_required,
    1674             :                         &p_value, &q_value,
    1675             :                         &non_options_count, non_options, &unrecognized);
    1676           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1677           2 :       ASSERT (strcmp (argv[1], "donald") == 0);
    1678           2 :       ASSERT (strcmp (argv[2], "-p") == 0);
    1679           2 :       ASSERT (strcmp (argv[3], "billy") == 0);
    1680           2 :       ASSERT (strcmp (argv[4], "duck") == 0);
    1681           2 :       ASSERT (strcmp (argv[5], "-a") == 0);
    1682           2 :       ASSERT (strcmp (argv[6], "bar") == 0);
    1683           2 :       ASSERT (argv[7] == NULL);
    1684           2 :       ASSERT (a_seen == 0);
    1685           2 :       ASSERT (b_seen == 0);
    1686           2 :       ASSERT (p_value == NULL);
    1687           2 :       ASSERT (q_value == NULL);
    1688           2 :       ASSERT (non_options_count == 0);
    1689           2 :       ASSERT (unrecognized == 0);
    1690           2 :       ASSERT (optind == 1);
    1691             :     }
    1692           3 :   for (start = 0; start <= 1; start++)
    1693             :     {
    1694           2 :       const char *p_value = NULL;
    1695           2 :       const char *q_value = NULL;
    1696           2 :       int non_options_count = 0;
    1697             :       const char *non_options[10];
    1698           2 :       int unrecognized = 0;
    1699           2 :       int argc = 0;
    1700             :       const char *argv[10];
    1701           2 :       a_seen = 0;
    1702           2 :       b_seen = 0;
    1703             : 
    1704           2 :       argv[argc++] = "program";
    1705           2 :       argv[argc++] = "-+";
    1706           2 :       argv[argc] = NULL;
    1707           2 :       optind = start;
    1708           2 :       getopt_long_loop (argc, argv, "+abp:q:", long_options_required,
    1709             :                         &p_value, &q_value,
    1710             :                         &non_options_count, non_options, &unrecognized);
    1711           2 :       ASSERT (a_seen == 0);
    1712           2 :       ASSERT (b_seen == 0);
    1713           2 :       ASSERT (p_value == NULL);
    1714           2 :       ASSERT (q_value == NULL);
    1715           2 :       ASSERT (non_options_count == 0);
    1716           2 :       ASSERT (unrecognized == '+');
    1717           2 :       ASSERT (optind == 2);
    1718             :     }
    1719             : 
    1720             :   /* Check that '--' ends the argument processing.  */
    1721           3 :   for (start = 0; start <= 1; start++)
    1722             :     {
    1723           2 :       const char *p_value = NULL;
    1724           2 :       const char *q_value = NULL;
    1725           2 :       int non_options_count = 0;
    1726             :       const char *non_options[10];
    1727           2 :       int unrecognized = 0;
    1728           2 :       int argc = 0;
    1729             :       const char *argv[20];
    1730           2 :       a_seen = 0;
    1731           2 :       b_seen = 0;
    1732             : 
    1733           2 :       argv[argc++] = "program";
    1734           2 :       argv[argc++] = "donald";
    1735           2 :       argv[argc++] = "-p";
    1736           2 :       argv[argc++] = "billy";
    1737           2 :       argv[argc++] = "duck";
    1738           2 :       argv[argc++] = "-a";
    1739           2 :       argv[argc++] = "--";
    1740           2 :       argv[argc++] = "-b";
    1741           2 :       argv[argc++] = "foo";
    1742           2 :       argv[argc++] = "-q";
    1743           2 :       argv[argc++] = "johnny";
    1744           2 :       argv[argc++] = "bar";
    1745           2 :       argv[argc] = NULL;
    1746           2 :       optind = start;
    1747           2 :       getopt_long_loop (argc, argv, "+abp:q:", long_options_required,
    1748             :                         &p_value, &q_value,
    1749             :                         &non_options_count, non_options, &unrecognized);
    1750           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1751           2 :       ASSERT (strcmp (argv[1], "donald") == 0);
    1752           2 :       ASSERT (strcmp (argv[2], "-p") == 0);
    1753           2 :       ASSERT (strcmp (argv[3], "billy") == 0);
    1754           2 :       ASSERT (strcmp (argv[4], "duck") == 0);
    1755           2 :       ASSERT (strcmp (argv[5], "-a") == 0);
    1756           2 :       ASSERT (strcmp (argv[6], "--") == 0);
    1757           2 :       ASSERT (strcmp (argv[7], "-b") == 0);
    1758           2 :       ASSERT (strcmp (argv[8], "foo") == 0);
    1759           2 :       ASSERT (strcmp (argv[9], "-q") == 0);
    1760           2 :       ASSERT (strcmp (argv[10], "johnny") == 0);
    1761           2 :       ASSERT (strcmp (argv[11], "bar") == 0);
    1762           2 :       ASSERT (argv[12] == NULL);
    1763           2 :       ASSERT (a_seen == 0);
    1764           2 :       ASSERT (b_seen == 0);
    1765           2 :       ASSERT (p_value == NULL);
    1766           2 :       ASSERT (q_value == NULL);
    1767           2 :       ASSERT (non_options_count == 0);
    1768           2 :       ASSERT (unrecognized == 0);
    1769           2 :       ASSERT (optind == 1);
    1770             :     }
    1771             : 
    1772             :   /* Check that the '+' flag has to come first.  */
    1773           3 :   for (start = 0; start <= 1; start++)
    1774             :     {
    1775           2 :       const char *p_value = NULL;
    1776           2 :       const char *q_value = NULL;
    1777           2 :       int non_options_count = 0;
    1778             :       const char *non_options[10];
    1779           2 :       int unrecognized = 0;
    1780           2 :       int argc = 0;
    1781             :       const char *argv[10];
    1782           2 :       a_seen = 0;
    1783           2 :       b_seen = 0;
    1784             : 
    1785           2 :       argv[argc++] = "program";
    1786           2 :       argv[argc++] = "donald";
    1787           2 :       argv[argc++] = "-p";
    1788           2 :       argv[argc++] = "billy";
    1789           2 :       argv[argc++] = "duck";
    1790           2 :       argv[argc++] = "-a";
    1791           2 :       argv[argc++] = "bar";
    1792           2 :       argv[argc] = NULL;
    1793           2 :       optind = start;
    1794           2 :       getopt_long_loop (argc, argv, "abp:q:+", long_options_required,
    1795             :                         &p_value, &q_value,
    1796             :                         &non_options_count, non_options, &unrecognized);
    1797           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1798           2 :       ASSERT (strcmp (argv[1], "-p") == 0);
    1799           2 :       ASSERT (strcmp (argv[2], "billy") == 0);
    1800           2 :       ASSERT (strcmp (argv[3], "-a") == 0);
    1801           2 :       ASSERT (strcmp (argv[4], "donald") == 0);
    1802           2 :       ASSERT (strcmp (argv[5], "duck") == 0);
    1803           2 :       ASSERT (strcmp (argv[6], "bar") == 0);
    1804           2 :       ASSERT (argv[7] == NULL);
    1805           2 :       ASSERT (a_seen == 1);
    1806           2 :       ASSERT (b_seen == 0);
    1807           2 :       ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
    1808           2 :       ASSERT (q_value == NULL);
    1809           2 :       ASSERT (non_options_count == 0);
    1810           2 :       ASSERT (unrecognized == 0);
    1811           2 :       ASSERT (optind == 4);
    1812             :     }
    1813           1 : }
    1814             : 
    1815             : /* Test behavior of getopt_long when POSIXLY_CORRECT is set in the
    1816             :    environment.  Options with optional arguments should not change
    1817             :    behavior just because of an environment variable.
    1818             :    http://lists.gnu.org/archive/html/bug-m4/2006-09/msg00028.html  */
    1819             : static void
    1820           1 : test_getopt_long_posix (void)
    1821             : {
    1822             :   int start;
    1823             : 
    1824             :   /* Check that POSIXLY_CORRECT stops parsing the same as leading '+'.  */
    1825           3 :   for (start = 0; start <= 1; start++)
    1826             :     {
    1827           2 :       const char *p_value = NULL;
    1828           2 :       const char *q_value = NULL;
    1829           2 :       int non_options_count = 0;
    1830             :       const char *non_options[10];
    1831           2 :       int unrecognized = 0;
    1832           2 :       int argc = 0;
    1833             :       const char *argv[10];
    1834           2 :       a_seen = 0;
    1835           2 :       b_seen = 0;
    1836             : 
    1837           2 :       argv[argc++] = "program";
    1838           2 :       argv[argc++] = "donald";
    1839           2 :       argv[argc++] = "-p";
    1840           2 :       argv[argc++] = "billy";
    1841           2 :       argv[argc++] = "duck";
    1842           2 :       argv[argc++] = "-a";
    1843           2 :       argv[argc++] = "bar";
    1844           2 :       argv[argc] = NULL;
    1845           2 :       optind = start;
    1846           2 :       getopt_long_loop (argc, argv, "abp:q:", long_options_required,
    1847             :                         &p_value, &q_value,
    1848             :                         &non_options_count, non_options, &unrecognized);
    1849           2 :       ASSERT (strcmp (argv[0], "program") == 0);
    1850           2 :       ASSERT (strcmp (argv[1], "donald") == 0);
    1851           2 :       ASSERT (strcmp (argv[2], "-p") == 0);
    1852           2 :       ASSERT (strcmp (argv[3], "billy") == 0);
    1853           2 :       ASSERT (strcmp (argv[4], "duck") == 0);
    1854           2 :       ASSERT (strcmp (argv[5], "-a") == 0);
    1855           2 :       ASSERT (strcmp (argv[6], "bar") == 0);
    1856           2 :       ASSERT (argv[7] == NULL);
    1857           2 :       ASSERT (a_seen == 0);
    1858           2 :       ASSERT (b_seen == 0);
    1859           2 :       ASSERT (p_value == NULL);
    1860           2 :       ASSERT (q_value == NULL);
    1861           2 :       ASSERT (non_options_count == 0);
    1862           2 :       ASSERT (unrecognized == 0);
    1863           2 :       ASSERT (optind == 1);
    1864             :     }
    1865             : 
    1866             :   /* Check that POSIXLY_CORRECT doesn't change optional arguments.  */
    1867           3 :   for (start = 0; start <= 1; start++)
    1868             :     {
    1869           2 :       const char *p_value = NULL;
    1870           2 :       const char *q_value = NULL;
    1871           2 :       int non_options_count = 0;
    1872             :       const char *non_options[10];
    1873           2 :       int unrecognized = 0;
    1874           2 :       int argc = 0;
    1875             :       const char *argv[10];
    1876           2 :       a_seen = 0;
    1877           2 :       b_seen = 0;
    1878             : 
    1879           2 :       argv[argc++] = "program";
    1880           2 :       argv[argc++] = "-p";
    1881           2 :       argv[argc++] = "billy";
    1882           2 :       argv[argc] = NULL;
    1883           2 :       optind = start;
    1884           2 :       getopt_long_loop (argc, argv, "p::", long_options_required,
    1885             :                         &p_value, &q_value,
    1886             :                         &non_options_count, non_options, &unrecognized);
    1887           2 :       ASSERT (a_seen == 0);
    1888           2 :       ASSERT (b_seen == 0);
    1889           2 :       ASSERT (p_value == NULL);
    1890           2 :       ASSERT (q_value == NULL);
    1891           2 :       ASSERT (non_options_count == 0);
    1892           2 :       ASSERT (unrecognized == 0);
    1893           2 :       ASSERT (optind == 2);
    1894             :     }
    1895             : 
    1896             :   /* Check that leading - still sees options after non-options.  */
    1897           3 :   for (start = 0; start <= 1; start++)
    1898             :     {
    1899           2 :       const char *p_value = NULL;
    1900           2 :       const char *q_value = NULL;
    1901           2 :       int non_options_count = 0;
    1902             :       const char *non_options[10];
    1903           2 :       int unrecognized = 0;
    1904           2 :       int argc = 0;
    1905             :       const char *argv[10];
    1906           2 :       a_seen = 0;
    1907           2 :       b_seen = 0;
    1908             : 
    1909           2 :       argv[argc++] = "program";
    1910           2 :       argv[argc++] = "-a";
    1911           2 :       argv[argc++] = "billy";
    1912           2 :       argv[argc++] = "-b";
    1913           2 :       argv[argc] = NULL;
    1914           2 :       optind = start;
    1915           2 :       getopt_long_loop (argc, argv, "-ab", long_options_required,
    1916             :                         &p_value, &q_value,
    1917             :                         &non_options_count, non_options, &unrecognized);
    1918           2 :       ASSERT (a_seen == 1);
    1919           2 :       ASSERT (b_seen == 1);
    1920           2 :       ASSERT (p_value == NULL);
    1921           2 :       ASSERT (q_value == NULL);
    1922           2 :       ASSERT (non_options_count == 1);
    1923           2 :       ASSERT (strcmp (non_options[0], "billy") == 0);
    1924           2 :       ASSERT (unrecognized == 0);
    1925           2 :       ASSERT (optind == 4);
    1926             :     }
    1927           1 : }
    1928             : 
    1929             : /* Reduce casting, so we can use string literals elsewhere.
    1930             :    getopt_long_only takes an array of char*, but luckily does not
    1931             :    modify those elements, so we can pass const char*.  */
    1932             : static int
    1933          12 : do_getopt_long_only (int argc, const char **argv, const char *shortopts,
    1934             :                      const struct option *longopts, int *longind)
    1935             : {
    1936          12 :   return getopt_long_only (argc, (char **) argv, shortopts, longopts, longind);
    1937             : }
    1938             : 
    1939             : static void
    1940           1 : test_getopt_long_only (void)
    1941             : {
    1942             :   /* Test disambiguation of options.  */
    1943             :   {
    1944           1 :     int argc = 0;
    1945             :     const char *argv[10];
    1946             :     int option_index;
    1947             :     int c;
    1948             : 
    1949           1 :     argv[argc++] = "program";
    1950           1 :     argv[argc++] = "-x";
    1951           1 :     argv[argc] = NULL;
    1952           1 :     optind = 1;
    1953           1 :     opterr = 0;
    1954           1 :     c = do_getopt_long_only (argc, argv, "ab", long_options_required,
    1955             :                              &option_index);
    1956           1 :     ASSERT (c == '?');
    1957           1 :     ASSERT (optopt == 0);
    1958             :   }
    1959             :   {
    1960           1 :     int argc = 0;
    1961             :     const char *argv[10];
    1962             :     int option_index;
    1963             :     int c;
    1964             : 
    1965           1 :     argv[argc++] = "program";
    1966           1 :     argv[argc++] = "-x";
    1967           1 :     argv[argc] = NULL;
    1968           1 :     optind = 1;
    1969           1 :     opterr = 0;
    1970           1 :     c = do_getopt_long_only (argc, argv, "abx", long_options_required,
    1971             :                              &option_index);
    1972           1 :     ASSERT (c == 'x');
    1973           1 :     ASSERT (optopt == 0);
    1974             :   }
    1975             :   {
    1976           1 :     int argc = 0;
    1977             :     const char *argv[10];
    1978             :     int option_index;
    1979             :     int c;
    1980             : 
    1981           1 :     argv[argc++] = "program";
    1982           1 :     argv[argc++] = "--x";
    1983           1 :     argv[argc] = NULL;
    1984           1 :     optind = 1;
    1985           1 :     opterr = 0;
    1986           1 :     c = do_getopt_long_only (argc, argv, "abx", long_options_required,
    1987             :                              &option_index);
    1988           1 :     ASSERT (c == '?');
    1989           1 :     ASSERT (optopt == 0);
    1990             :   }
    1991             :   {
    1992           1 :     int argc = 0;
    1993             :     const char *argv[10];
    1994             :     int option_index;
    1995             :     int c;
    1996             : 
    1997           1 :     argv[argc++] = "program";
    1998           1 :     argv[argc++] = "-b";
    1999           1 :     argv[argc] = NULL;
    2000           1 :     optind = 1;
    2001           1 :     opterr = 0;
    2002           1 :     b_seen = 0;
    2003           1 :     c = do_getopt_long_only (argc, argv, "abx", long_options_required,
    2004             :                              &option_index);
    2005           1 :     ASSERT (c == 'b');
    2006           1 :     ASSERT (b_seen == 0);
    2007             :   }
    2008             :   {
    2009           1 :     int argc = 0;
    2010             :     const char *argv[10];
    2011             :     int option_index;
    2012             :     int c;
    2013             : 
    2014           1 :     argv[argc++] = "program";
    2015           1 :     argv[argc++] = "--b";
    2016           1 :     argv[argc] = NULL;
    2017           1 :     optind = 1;
    2018           1 :     opterr = 0;
    2019           1 :     b_seen = 0;
    2020           1 :     c = do_getopt_long_only (argc, argv, "abx", long_options_required,
    2021             :                              &option_index);
    2022           1 :     ASSERT (c == 0);
    2023           1 :     ASSERT (b_seen == 1);
    2024             :   }
    2025             :   {
    2026           1 :     int argc = 0;
    2027             :     const char *argv[10];
    2028             :     int option_index;
    2029             :     int c;
    2030             : 
    2031           1 :     argv[argc++] = "program";
    2032           1 :     argv[argc++] = "-xt";
    2033           1 :     argv[argc] = NULL;
    2034           1 :     optind = 1;
    2035           1 :     opterr = 0;
    2036           1 :     c = do_getopt_long_only (argc, argv, "ab", long_options_required,
    2037             :                              &option_index);
    2038           1 :     ASSERT (c == '?');
    2039           1 :     ASSERT (optopt == 0);
    2040             :   }
    2041             :   {
    2042           1 :     int argc = 0;
    2043             :     const char *argv[10];
    2044             :     int option_index;
    2045             :     int c;
    2046             : 
    2047           1 :     argv[argc++] = "program";
    2048           1 :     argv[argc++] = "-xt";
    2049           1 :     argv[argc] = NULL;
    2050           1 :     optind = 1;
    2051           1 :     opterr = 0;
    2052           1 :     c = do_getopt_long_only (argc, argv, "abx", long_options_required,
    2053             :                              &option_index);
    2054           1 :     ASSERT (c == '?');
    2055           1 :     ASSERT (optopt == 0);
    2056             :   }
    2057             :   {
    2058           1 :     int argc = 0;
    2059             :     const char *argv[10];
    2060             :     int option_index;
    2061             :     int c;
    2062             : 
    2063           1 :     argv[argc++] = "program";
    2064           1 :     argv[argc++] = "-xtra";
    2065           1 :     argv[argc] = NULL;
    2066           1 :     optind = 1;
    2067           1 :     opterr = 0;
    2068           1 :     c = do_getopt_long_only (argc, argv, "ab", long_options_required,
    2069             :                              &option_index);
    2070           1 :     ASSERT (c == 1001);
    2071             :   }
    2072             :   {
    2073           1 :     int argc = 0;
    2074             :     const char *argv[10];
    2075             :     int option_index;
    2076             :     int c;
    2077             : 
    2078           1 :     argv[argc++] = "program";
    2079           1 :     argv[argc++] = "-xtreme";
    2080           1 :     argv[argc] = NULL;
    2081           1 :     optind = 1;
    2082           1 :     opterr = 0;
    2083           1 :     c = do_getopt_long_only (argc, argv, "abx:", long_options_required,
    2084             :                              &option_index);
    2085           1 :     ASSERT (c == 1002);
    2086             :   }
    2087             :   {
    2088           1 :     int argc = 0;
    2089             :     const char *argv[10];
    2090             :     int option_index;
    2091             :     int c;
    2092             : 
    2093           1 :     argv[argc++] = "program";
    2094           1 :     argv[argc++] = "-xtremel";
    2095           1 :     argv[argc] = NULL;
    2096           1 :     optind = 1;
    2097           1 :     opterr = 0;
    2098           1 :     c = do_getopt_long_only (argc, argv, "ab", long_options_required,
    2099             :                              &option_index);
    2100             :     /* glibc getopt_long_only is intentionally different from
    2101             :        getopt_long when handling a prefix that is common to two
    2102             :        spellings, when both spellings have the same option directives.
    2103             :        BSD getopt_long_only treats both cases the same.  */
    2104           1 :     ASSERT (c == 1003 || c == '?');
    2105           1 :     ASSERT (optind == 2);
    2106             :   }
    2107             :   {
    2108           1 :     int argc = 0;
    2109             :     const char *argv[10];
    2110             :     int option_index;
    2111             :     int c;
    2112             : 
    2113           1 :     argv[argc++] = "program";
    2114           1 :     argv[argc++] = "-xtremel";
    2115           1 :     argv[argc] = NULL;
    2116           1 :     optind = 1;
    2117           1 :     opterr = 0;
    2118           1 :     c = do_getopt_long_only (argc, argv, "abx::", long_options_required,
    2119             :                              &option_index);
    2120             :     /* glibc getopt_long_only is intentionally different from
    2121             :        getopt_long when handling a prefix that is common to two
    2122             :        spellings, when both spellings have the same option directives.
    2123             :        BSD getopt_long_only treats both cases the same.  */
    2124           1 :     ASSERT (c == 1003 || c == '?');
    2125           1 :     ASSERT (optind == 2);
    2126           1 :     ASSERT (optarg == NULL);
    2127             :   }
    2128             :   {
    2129           1 :     int argc = 0;
    2130             :     const char *argv[10];
    2131             :     int option_index;
    2132             :     int c;
    2133             : 
    2134           1 :     argv[argc++] = "program";
    2135           1 :     argv[argc++] = "-xtras";
    2136           1 :     argv[argc] = NULL;
    2137           1 :     optind = 1;
    2138           1 :     opterr = 0;
    2139           1 :     c = do_getopt_long_only (argc, argv, "abx::", long_options_required,
    2140             :                              &option_index);
    2141           1 :     ASSERT (c == 'x');
    2142           1 :     ASSERT (strcmp (optarg, "tras") == 0);
    2143             :   }
    2144           1 : }

Generated by: LCOV version 1.11