annotate tests/test-getopt.c @ 17363:5a51fb7777a9

sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin Problem reported by Marco Atzeri in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>. * lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]: Simply delegate to the system <sys/select.h> in this case too. Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to be needed on Solaris either. * lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]: Simply delgate to the system <sys/time.h> in this case.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:08:47 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of command line argument processing.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2009-2013 Free Software Foundation, Inc.
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009. */
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
12474
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
21 /* None of the files accessed by this test are large, so disable the
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
22 ftell link warning if we are not using the gnulib ftell module. */
12724
bc2866336bbb stdio: warn on suspicious uses
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
23 #define _GL_NO_LARGE_FILES
12474
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
24
13073
03de1efbfdd3 Resolve conflict between the two kinds of module indicators.
Bruno Haible <bruno@clisp.org>
parents: 12724
diff changeset
25 #if GNULIB_TEST_GETOPT_GNU
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 # include <getopt.h>
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
27
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
28 # ifndef __getopt_argv_const
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
29 # define __getopt_argv_const const
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
30 # endif
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
31 # include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
32 SIGNATURE_CHECK (getopt_long, int, (int, char *__getopt_argv_const *,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
33 char const *, struct option const *,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
34 int *));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
35 SIGNATURE_CHECK (getopt_long_only, int, (int, char *__getopt_argv_const *,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
36 char const *, struct option const *,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
37 int *));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
38
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 #endif
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
40
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #include <unistd.h>
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
43 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
44 SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12474
diff changeset
45
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #include <stdio.h>
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #include <stdlib.h>
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 #include <string.h>
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
12474
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
50 /* This test intentionally remaps stderr. So, we arrange to have fd 10
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
51 (outside the range of interesting fd's during the test) set up to
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
52 duplicate the original stderr. */
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
53
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
54 #define BACKUP_STDERR_FILENO 10
12510
618282a72d9b tests: use macros.h in more places
Eric Blake <ebb9@byu.net>
parents: 12489
diff changeset
55 #define ASSERT_STREAM myerr
618282a72d9b tests: use macros.h in more places
Eric Blake <ebb9@byu.net>
parents: 12489
diff changeset
56 #include "macros.h"
12474
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
57
12510
618282a72d9b tests: use macros.h in more places
Eric Blake <ebb9@byu.net>
parents: 12489
diff changeset
58 static FILE *myerr;
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 #include "test-getopt.h"
13073
03de1efbfdd3 Resolve conflict between the two kinds of module indicators.
Bruno Haible <bruno@clisp.org>
parents: 12724
diff changeset
61 #if GNULIB_TEST_GETOPT_GNU
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 # include "test-getopt_long.h"
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 #endif
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 int
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 12124
diff changeset
66 main (void)
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 {
12474
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
68 /* This test validates that stderr is used correctly, so move the
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
69 original into fd 10. */
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
70 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
71 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
72 return 2;
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
73
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
74 ASSERT (freopen ("test-getopt.tmp", "w", stderr) == stderr);
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
75
12473
81590e0c5feb test-getopt: enhance test
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
76 /* These default values are required by POSIX. */
81590e0c5feb test-getopt: enhance test
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
77 ASSERT (optind == 1);
81590e0c5feb test-getopt: enhance test
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
78 ASSERT (opterr != 0);
81590e0c5feb test-getopt: enhance test
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
79
12371
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
80 setenv ("POSIXLY_CORRECT", "1", 1);
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
81 test_getopt ();
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
13073
03de1efbfdd3 Resolve conflict between the two kinds of module indicators.
Bruno Haible <bruno@clisp.org>
parents: 12724
diff changeset
83 #if GNULIB_TEST_GETOPT_GNU
12371
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
84 test_getopt_long_posix ();
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
85 #endif
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
86
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
87 unsetenv ("POSIXLY_CORRECT");
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 test_getopt ();
12371
9f4c9181d1d6 getopt-gnu: flush out another BSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
89
13073
03de1efbfdd3 Resolve conflict between the two kinds of module indicators.
Bruno Haible <bruno@clisp.org>
parents: 12724
diff changeset
90 #if GNULIB_TEST_GETOPT_GNU
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 test_getopt_long ();
12473
81590e0c5feb test-getopt: enhance test
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
92 test_getopt_long_only ();
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 #endif
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94
12474
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
95 ASSERT (fclose (stderr) == 0);
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
96 ASSERT (remove ("test-getopt.tmp") == 0);
266f24fed73e test-getopt: test stderr behavior
Eric Blake <ebb9@byu.net>
parents: 12473
diff changeset
97
11820
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 return 0;
48b5d5434e51 Tests for modules 'getopt-posix', 'getopt-gnu'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 }