summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-12-01 17:21:34 -0700
committerEric Blake <ebb9@byu.net>2009-12-22 06:42:33 -0700
commita8ec28b6975fc065b84c511b8108dc3658d2ccd4 (patch)
tree0ad3e9a11b9a04b5c5294f811c6160993e65f5dc /m4
parent2c77d283b12521cd05a63a4188f68cd595b0a8f9 (diff)
downloadgnulib-a8ec28b6975fc065b84c511b8108dc3658d2ccd4.tar.gz
test-getopt: enhance test
Add coverage of optind==0 for getopt_long, since coreutils depends on it. Also test an optstring containing "W;", since that tends to expose corner-case bugs (even in glibc, so the test is weaker than it could be). * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Require that getopt_long supports optind=0. * tests/test-getopt.c (OPTIND_MIN): Move... * tests/test-getopt.h (OPTIND_MIN): ...here. * tests/test-getopt_long.h (test_getopt_long): Add more coverage. Require that optind=0 works, since modern BSD supports it in addition to optreset, and since coreutils expects it. (test_getopt_long_only): New test. * doc/glibc-functions/getopt_long.texi (getopt_long): Document glibc shortcomings with 'W;', and enforcement of optind=0. * doc/glibc-functions/getopt_long_only.texi (getopt_long_only): Likewise.
Diffstat (limited to 'm4')
-rw-r--r--m4/getopt.m49
1 files changed, 3 insertions, 6 deletions
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index 58098160cc..8b1bb8fbf2 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -88,6 +88,7 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
dnl strings starts with '+' and it's not the first call. Some internal state
dnl is left over from earlier calls, and neither setting optind = 0 nor
dnl setting optreset = 1 get rid of this internal state.
+ dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
if test -z "$gl_replace_getopt"; then
AC_CACHE_CHECK([whether getopt is POSIX compatible],
[gl_cv_func_getopt_posix],
@@ -187,6 +188,7 @@ main ()
[# Even with POSIXLY_CORRECT, the GNU extension of leading '-' in the
# optstring is necessary for programs like m4 that have POSIX-mandated
# semantics for supporting options interspersed with files.
+ # Also, since getopt_long is a GNU extension, we require optind=0.
gl_had_POSIXLY_CORRECT=${POSIXLY_CORRECT:+yes}
POSIXLY_CORRECT=1
export POSIXLY_CORRECT
@@ -194,11 +196,6 @@ main ()
[AC_LANG_PROGRAM([[#include <getopt.h>
#include <stddef.h>
#include <string.h>
-#if !HAVE_DECL_OPTRESET
-# define OPTIND_MIN 0
-#else
-# define OPTIND_MIN (optreset = 1)
-#endif
]], [[
/* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw,
and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
@@ -231,7 +228,7 @@ main ()
/* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0. */
{
char *argv[] = { "program", "foo", "-p", NULL };
- optind = OPTIND_MIN;
+ optind = 0;
if (getopt (3, argv, "-p") != 1)
return 6;
if (getopt (3, argv, "-p") != 'p')