1 /* Test of command line argument processing.
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009. */
19 #include "signature.h"
20 SIGNATURE_CHECK (getopt
, int, (int, char * const[], char const *));
27 /* This test intentionally remaps stderr. So, we arrange to have fd 10
28 (outside the range of interesting fd's during the test) set up to
29 duplicate the original stderr. */
31 #define BACKUP_STDERR_FILENO 10
32 #define ASSERT_STREAM myerr
37 #include "test-getopt.h"
39 # include "test-getopt_long.h"
45 /* This test validates that stderr is used correctly, so move the
46 original into fd 10. */
47 if (dup2 (STDERR_FILENO
, BACKUP_STDERR_FILENO
) != BACKUP_STDERR_FILENO
48 || (myerr
= fdopen (BACKUP_STDERR_FILENO
, "w")) == NULL
)
51 ASSERT (freopen (TEST_GETOPT_TMP_NAME
, "w", stderr
) == stderr
);
53 /* These default values are required by POSIX. */
57 setenv ("POSIXLY_CORRECT", "1", 1);
61 test_getopt_long_posix ();
64 unsetenv ("POSIXLY_CORRECT");
69 test_getopt_long_only ();
72 ASSERT (fclose (stderr
) == 0);
73 ASSERT (remove (TEST_GETOPT_TMP_NAME
) == 0);