X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-getopt.h;h=f7b39113095ed18ace52550e3848752fcfb2f77a;hb=645581732c2d8066282b32d686edd67e18c52ee2;hp=8baa39d0254bf924e4d04c1c19a92f23a09ff01e;hpb=61c96af09d3d2c917c69b17cc827e28a280db66c;p=gnulib.git diff --git a/tests/test-getopt.h b/tests/test-getopt.h index 8baa39d02..f7b391130 100644 --- a/tests/test-getopt.h +++ b/tests/test-getopt.h @@ -1,5 +1,5 @@ /* Test of command line argument processing. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ /* The glibc/gnulib implementation of getopt supports setting optind = 0, but not all other implementations do. This matters for getopt. But for getopt_long, we require GNU compatibility. */ -#if defined __GETOPT_PREFIX || (__GLIBC__ >= 2) +#if defined __GETOPT_PREFIX || (__GLIBC__ >= 2 && !defined __UCLIBC__) # define OPTIND_MIN 0 #elif HAVE_DECL_OPTRESET # define OPTIND_MIN (optreset = 1) @@ -1187,7 +1187,7 @@ test_getopt (void) ASSERT (q_value == NULL); ASSERT (non_options_count == 0); ASSERT (unrecognized == 0); - ASSERT (optind = 1); + ASSERT (optind == 1); ASSERT (!output); } #endif /* GNULIB_TEST_GETOPT_GNU */ @@ -1365,5 +1365,27 @@ test_getopt (void) ASSERT (optind == 3); ASSERT (!output); } + + /* Check that 'W' does not dump core: + http://sourceware.org/bugzilla/show_bug.cgi?id=12922 + Technically, POSIX says the presence of ';' in the opt-string + gives unspecified behavior, so we only test this when GNU compliance + is desired. */ + for (start = OPTIND_MIN; start <= 1; start++) + { + int argc = 0; + const char *argv[10]; + int pos = ftell (stderr); + + argv[argc++] = "program"; + argv[argc++] = "-W"; + argv[argc++] = "dummy"; + argv[argc] = NULL; + optind = start; + opterr = 1; + ASSERT (getopt (argc, (char **) argv, "W;") == 'W'); + ASSERT (ftell (stderr) == pos); + ASSERT (optind == 2); + } #endif /* GNULIB_TEST_GETOPT_GNU */ }