Blame gnulib-tests/test-getopt.h

Packit Service fdd496
/* Test of command line argument processing.
Packit Service fdd496
   Copyright (C) 2009-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
Packit Service fdd496
Packit Service fdd496
#include <stdbool.h>
Packit Service fdd496
#include "macros.h"
Packit Service fdd496
Packit Service fdd496
/* The glibc/gnulib implementation of getopt supports setting optind =
Packit Service fdd496
   0, but not all other implementations do.  This matters for getopt.
Packit Service fdd496
   But for getopt_long, we require GNU compatibility.  */
Packit Service fdd496
#if defined __GETOPT_PREFIX || (__GLIBC__ >= 2 && !defined __UCLIBC__)
Packit Service fdd496
# define OPTIND_MIN 0
Packit Service fdd496
#elif HAVE_DECL_OPTRESET
Packit Service fdd496
# define OPTIND_MIN (optreset = 1)
Packit Service fdd496
#else
Packit Service fdd496
# define OPTIND_MIN 1
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
static void
Packit Service fdd496
getopt_loop (int argc, const char **argv,
Packit Service fdd496
             const char *options,
Packit Service fdd496
             int *a_seen, int *b_seen,
Packit Service fdd496
             const char **p_value, const char **q_value,
Packit Service fdd496
             int *non_options_count, const char **non_options,
Packit Service fdd496
             int *unrecognized, bool *message_issued)
Packit Service fdd496
{
Packit Service fdd496
  int c;
Packit Service fdd496
  int pos = ftell (stderr);
Packit Service fdd496
Packit Service fdd496
  while ((c = getopt (argc, (char **) argv, options)) != -1)
Packit Service fdd496
    {
Packit Service fdd496
      switch (c)
Packit Service fdd496
        {
Packit Service fdd496
        case 'a':
Packit Service fdd496
          (*a_seen)++;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'b':
Packit Service fdd496
          (*b_seen)++;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'p':
Packit Service fdd496
          *p_value = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'q':
Packit Service fdd496
          *q_value = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case '\1':
Packit Service fdd496
          /* Must only happen with option '-' at the beginning.  */
Packit Service fdd496
          ASSERT (options[0] == '-');
Packit Service fdd496
          non_options[(*non_options_count)++] = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case ':':
Packit Service fdd496
          /* Must only happen with option ':' at the beginning.  */
Packit Service fdd496
          ASSERT (options[0] == ':'
Packit Service fdd496
                  || ((options[0] == '-' || options[0] == '+')
Packit Service fdd496
                      && options[1] == ':'));
Packit Service fdd496
          FALLTHROUGH;
Packit Service fdd496
        case '?':
Packit Service fdd496
          *unrecognized = optopt;
Packit Service fdd496
          break;
Packit Service fdd496
        default:
Packit Service fdd496
          *unrecognized = c;
Packit Service fdd496
          break;
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  *message_issued = pos < ftell (stderr);
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
static void
Packit Service fdd496
test_getopt (void)
Packit Service fdd496
{
Packit Service fdd496
  int start;
Packit Service fdd496
  bool posixly = !!getenv ("POSIXLY_CORRECT");
Packit Service fdd496
  /* See comment in getopt.c:
Packit Service fdd496
     glibc gets a LSB-compliant getopt.
Packit Service fdd496
     Standalone applications get a POSIX-compliant getopt.  */
Packit Service fdd496
#if defined __GETOPT_PREFIX || !(__GLIBC__ >= 2 || defined __MINGW32__)
Packit Service fdd496
  /* Using getopt from gnulib or from a non-glibc system.  */
Packit Service fdd496
  posixly = true;
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
  /* Test processing of boolean options.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "ab",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "ab",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ba";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "ab",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ab";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "ab",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 2);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of options with arguments.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-pfoo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "p:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "p:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ab";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "baz";
Packit Service fdd496
      argv[argc++] = "-pfoo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
#if GNULIB_TEST_GETOPT_GNU
Packit Service fdd496
  /* Test processing of options with optional arguments.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-pfoo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "p::q::",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "p::q::",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp::q::",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
#endif /* GNULIB_TEST_GETOPT_GNU */
Packit Service fdd496
Packit Service fdd496
  /* Check that invalid options are recognized; and that both opterr
Packit Service fdd496
     and leading ':' can silence output.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-x";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 42;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'x');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-x";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 0;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'x');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-x";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, ":abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'x');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-:";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 42;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == ':');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-:";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 0;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == ':');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-:";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, ":abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == ':');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check for missing argument behavior.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ap";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'p');
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ap";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 0;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'p');
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ap";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, ":abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'p');
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that by default, non-options arguments are moved to the end.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      if (posixly)
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[7] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 0);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value == NULL);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 1);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
      else
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[7] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 1);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 4);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that '--' ends the argument processing.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[20];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "--";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "johnny";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      if (posixly)
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "--") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[12] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 0);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value == NULL);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 1);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
      else
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "--") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[12] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 1);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 5);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
#if GNULIB_TEST_GETOPT_GNU
Packit Service fdd496
  /* Check that the '-' flag causes non-options to be returned in order.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "-abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 3);
Packit Service fdd496
      ASSERT (strcmp (non_options[0], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (non_options[1], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (non_options[2], "bar") == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 7);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that '--' ends the argument processing.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[20];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "--";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "johnny";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "-abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "--") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[12] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
      if (non_options_count == 2)
Packit Service fdd496
        {
Packit Service fdd496
          /* glibc behaviour.  */
Packit Service fdd496
          ASSERT (non_options_count == 2);
Packit Service fdd496
          ASSERT (strcmp (non_options[0], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[1], "duck") == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 7);
Packit Service fdd496
        }
Packit Service fdd496
      else
Packit Service fdd496
        {
Packit Service fdd496
          /* Another valid behaviour.  */
Packit Service fdd496
          ASSERT (non_options_count == 7);
Packit Service fdd496
          ASSERT (strcmp (non_options[0], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[1], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[2], "-b") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[3], "foo") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[4], "-q") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[5], "johnny") == 0);
Packit Service fdd496
          ASSERT (strcmp (non_options[6], "bar") == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 12);
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that the '-' flag has to come first.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:-",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      if (posixly)
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[7] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 0);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value == NULL);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 1);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
      else
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[7] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 1);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 4);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that the '+' flag causes the first non-option to terminate the
Packit Service fdd496
     loop.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "+abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 1);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-+";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_loop (argc, argv, "+abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == '+');
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that '--' ends the argument processing.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[20];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "--";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "johnny";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "+abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "--") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[12] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 1);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
#endif /* GNULIB_TEST_GETOPT_GNU */
Packit Service fdd496
Packit Service fdd496
  /* Check that the '+' flag has to come first.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "abp:q:+",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      if (posixly)
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[7] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 0);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value == NULL);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 1);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
      else
Packit Service fdd496
        {
Packit Service fdd496
          ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[4], "donald") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[5], "duck") == 0);
Packit Service fdd496
          ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
          ASSERT (argv[7] == NULL);
Packit Service fdd496
          ASSERT (a_seen == 1);
Packit Service fdd496
          ASSERT (b_seen == 0);
Packit Service fdd496
          ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
          ASSERT (q_value == NULL);
Packit Service fdd496
          ASSERT (non_options_count == 0);
Packit Service fdd496
          ASSERT (unrecognized == 0);
Packit Service fdd496
          ASSERT (optind == 4);
Packit Service fdd496
          ASSERT (!output);
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
#if GNULIB_TEST_GETOPT_GNU
Packit Service fdd496
  /* If GNU extensions are supported, require compliance with POSIX
Packit Service fdd496
     interpretation on leading '+' behavior.
Packit Service fdd496
     http://austingroupbugs.net/view.php?id=191  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      getopt_loop (argc, argv, "+:abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 1);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_loop (argc, argv, "+:abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'p');
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int a_seen = 0;
Packit Service fdd496
      int b_seen = 0;
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      bool output;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_loop (argc, argv, "+:abp:q:",
Packit Service fdd496
                   &a_seen, &b_seen, &p_value, &q_value,
Packit Service fdd496
                   &non_options_count, non_options, &unrecognized, &output);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'p');
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
      ASSERT (!output);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that 'W' does not dump core:
Packit Service fdd496
     http://sourceware.org/bugzilla/show_bug.cgi?id=12922
Packit Service fdd496
     Technically, POSIX says the presence of ';' in the opt-string
Packit Service fdd496
     gives unspecified behavior, so we only test this when GNU compliance
Packit Service fdd496
     is desired.  */
Packit Service fdd496
  for (start = OPTIND_MIN; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      int pos = ftell (stderr);
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "dummy";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      opterr = 1;
Packit Service fdd496
      ASSERT (getopt (argc, (char **) argv, "W;") == 'W');
Packit Service fdd496
      ASSERT (ftell (stderr) == pos);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
#endif /* GNULIB_TEST_GETOPT_GNU */
Packit Service fdd496
}