-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Bruno Haible on 8/12/2009 5:24 PM: > To make all this clearer, I'm introducing 'getopt-posix' and 'getopt-gnu' > modules, in the same way as we did for 'fnmatch'. Ultimately 'getopt-posix' > should be renamed to 'getopt', but this cannot be done after a sufficiently > long time of deprecation of the 'getopt' module.
In the process of doing this, you weakened the .m4 test to no longer exclude BSD getopt merely based on the existence of optreset. There is at least one more bug in older BSD getopt implementations, previously mentioned on this list as affecting m4's usage pattern of getopt_long, but that I didn't see any coverage of. The old test of the presence of optreset was enough to always use GNU getopt and not worry about whether BSD fixed their bug. But since m4 doesn't use optreset or optind=0, I'm okay with weakening the getopt.m4 test, as long as the testsuite proves that the BSD implementation obeys the GNU behavior of optional arguments under POSIXLY_CORRECT. So I'm committing this to enhance the testsuite, as well as to document that cygwin 1.7 (and probably some of the newer BSD distros) now pass even this test in the testsuite. If this starts failing on any systems that I don't have access to, then we can strengthen the getopt.m4 macro to once again select the GNU implementation. - -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrMD8EACgkQ84KuGfSFAYDDFACfdEC8X/tJrL85gFwWoowg4Nw+ mQkAn1NzW+/2a5r+topSYy96sn4ewTho =t2dJ -----END PGP SIGNATURE-----
>From 497ec25b4164fcf4b8a68a41f28e27cb1030c441 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Tue, 6 Oct 2009 14:29:13 -0600 Subject: [PATCH 1/2] getopt-gnu: add another test Ensure that POSIXLY_CORRECT does not interfere with optional argument behavior; older BSD implementations botched this. * tests/test-getopt_long.h (test_getopt_long_posix): New test, to guarantee behavior relied on by m4. * tests/test-getopt.c (main): Use it. * modules/getopt-posix-tests (Depends-on): Add setenv. See http://lists.gnu.org/archive/html/bug-m4/2006-09/msg00028.html. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 7 +++++++ modules/getopt-posix-tests | 1 + tests/test-getopt.c | 3 +++ tests/test-getopt_long.h | 21 +++++++++++++++++++++ 4 files changed, 32 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78b3386..1ce9fc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-10-06 Eric Blake <e...@byu.net> + getopt-gnu: add another test + * tests/test-getopt_long.h (test_getopt_long_posix): New test, to + guarantee behavior relied on by m4. + * tests/test-getopt.c (main): Use it. + * modules/getopt-posix-tests (Depends-on): Add setenv. + See http://lists.gnu.org/archive/html/bug-m4/2006-09/msg00028.html. + getopt: fix compilation on darwin * lib/getopt.in.h (includes): Leave breadcrumbs during system include. diff --git a/modules/getopt-posix-tests b/modules/getopt-posix-tests index ac4b965..3499b5a 100644 --- a/modules/getopt-posix-tests +++ b/modules/getopt-posix-tests @@ -4,6 +4,7 @@ tests/test-getopt.h tests/test-getopt_long.h Depends-on: +setenv unistd unsetenv diff --git a/tests/test-getopt.c b/tests/test-getopt.c index b3dd60b..12d8d92 100644 --- a/tests/test-getopt.c +++ b/tests/test-getopt.c @@ -60,6 +60,9 @@ main () test_getopt (); #if GNULIB_GETOPT_GNU test_getopt_long (); + + setenv ("POSIXLY_CORRECT", "1", 0); + test_getopt_long_posix (); #endif return 0; diff --git a/tests/test-getopt_long.h b/tests/test-getopt_long.h index 0017f19..fb505b2 100644 --- a/tests/test-getopt_long.h +++ b/tests/test-getopt_long.h @@ -935,3 +935,24 @@ test_getopt_long (void) ASSERT (optind == 4); } } + +/* Test behavior of getopt_long when POSIXLY_CORRECT is set in the + environment. Options with optional arguments should not change + behavior just because of an environment variable. + http://lists.gnu.org/archive/html/bug-m4/2006-09/msg00028.html */ +static void +test_getopt_long_posix (void) +{ + int c = 3; + char *v[4] = {"test", "-r", "foo", NULL}; + struct option l[] = {{NULL}}; + int start; + int result; + for (start = OPTIND_MIN; start <= 1; start++) + { + optind = start; + result = getopt_long (c, v, "r::", l, NULL); + } + ASSERT (result == 'r'); + ASSERT (optarg == NULL); +} -- 1.6.5.rc1 >From b46dd7ed26e21d922bc7265387fc9739d1243580 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Tue, 6 Oct 2009 13:58:06 -0600 Subject: [PATCH 2/2] doc: tweak more cygwin information * doc/glibc-headers/getopt.texi (getopt.h): Cygwin 1.7 getopt is now compatible with glibc. * doc/posix-functions/getopt.texi (getopt): Likewise. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 5 +++++ doc/glibc-headers/getopt.texi | 2 +- doc/posix-functions/getopt.texi | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ce9fc9..c2ed577 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-10-06 Eric Blake <e...@byu.net> + doc: tweak more cygwin information + * doc/glibc-headers/getopt.texi (getopt.h): Cygwin 1.7 getopt is + now compatible with glibc. + * doc/posix-functions/getopt.texi (getopt): Likewise. + getopt-gnu: add another test * tests/test-getopt_long.h (test_getopt_long_posix): New test, to guarantee behavior relied on by m4. diff --git a/doc/glibc-headers/getopt.texi b/doc/glibc-headers/getopt.texi index 199c449..eb14f8b 100644 --- a/doc/glibc-headers/getopt.texi +++ b/doc/glibc-headers/getopt.texi @@ -33,7 +33,7 @@ getopt.h MacOS X 10.3, FreeBSD 5.2.1, NetBSD 3.0, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw. @item The method to reset options is incompatible on some platforms: -FreeBSD 6.0, NetBSD 3.0(?), OpenBSD 3.8, Cygwin(?), mingw. +FreeBSD 6.0, NetBSD 3.0(?), OpenBSD 3.8, Cygwin 1.5.x, mingw. @item The function @code{getopt} does not handle a leading @samp{+} character in the options string on some platforms: diff --git a/doc/posix-functions/getopt.texi b/doc/posix-functions/getopt.texi index 778e3b4..004b6e8 100644 --- a/doc/posix-functions/getopt.texi +++ b/doc/posix-functions/getopt.texi @@ -27,7 +27,8 @@ getopt @item The function @code{getopt} does not support options with optional arguments on some platforms: -MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin. +MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, +Solaris 10, Cygwin 1.5.x. @item The function @code{getopt_long} is missing on some platforms: AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Interix 3.5. -- 1.6.5.rc1