Mercurial > gnulib
annotate tests/test-getopt-main.h @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
18605
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of command line argument processing. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
18605
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
18605
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009. */ |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include "signature.h" |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *)); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #include <stdio.h> |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <stdlib.h> |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <string.h> |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <unistd.h> |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 /* This test intentionally remaps stderr. So, we arrange to have fd 10 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 (outside the range of interesting fd's during the test) set up to |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 duplicate the original stderr. */ |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 #define BACKUP_STDERR_FILENO 10 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 #define ASSERT_STREAM myerr |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 #include "macros.h" |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 static FILE *myerr; |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 #include "test-getopt.h" |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 #if TEST_GETOPT_GNU |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 # include "test-getopt_long.h" |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 #endif |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 int |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 main (void) |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 { |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 /* This test validates that stderr is used correctly, so move the |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 original into fd 10. */ |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL) |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 return 2; |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 |
18615
947216b8fda6
getopt: fix parallel test failure
Eric Blake <eblake@redhat.com>
parents:
18605
diff
changeset
|
51 ASSERT (freopen (TEST_GETOPT_TMP_NAME, "w", stderr) == stderr); |
18605
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 /* These default values are required by POSIX. */ |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 ASSERT (optind == 1); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 ASSERT (opterr != 0); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 setenv ("POSIXLY_CORRECT", "1", 1); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 test_getopt (); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 #if TEST_GETOPT_GNU |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 test_getopt_long_posix (); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 #endif |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 unsetenv ("POSIXLY_CORRECT"); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 test_getopt (); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 #if TEST_GETOPT_GNU |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 test_getopt_long (); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 test_getopt_long_only (); |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 #endif |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 ASSERT (fclose (stderr) == 0); |
18615
947216b8fda6
getopt: fix parallel test failure
Eric Blake <eblake@redhat.com>
parents:
18605
diff
changeset
|
73 ASSERT (remove (TEST_GETOPT_TMP_NAME) == 0); |
18605
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 return 0; |
33b898f9e587
Split tests for getopt-posix and getopt-gnu.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 } |