gen-strtab.awk: Work around IRIX 6.2 nawk bug.
[dxcommon.git] / t / gnugetopt.c
blob0c3b1d5705a16ca825baab77e2f93fdb514d3e0d
1 /*
2 * Wrapper to run the getopt_long tests from Gnulib.
4 * Copyright © 2024 Nick Bowler
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * Can be run with an optional "posix" or "gnu" argument to select between
22 * different test modes.
24 * If run in the default gnu mode, POSIXLY_CORRECT must be unset in the
25 * environment. Otherwise, in posix mode, POSIXLY_CORRECT must be set.
29 #undef HAVE_GETOPT_LONG
30 #undef HAVE_GETOPT_LONG_ONLY
32 #include "gnu_getopt.h"
34 #include <stdlib.h>
35 #include <string.h>
36 #include "tap.h"
38 #undef no_argument
39 #define no_argument 0
41 #undef required_argument
42 #define required_argument 1
44 #undef optional_argument
45 #define optional_argument 2
47 #define FALLTHROUGH /**/
49 #if HAVE_STRINGIZE
50 # define ASSERT(x) tap_result(x, "%s:%d: %s", __FILE__, __LINE__, #x);
51 #else
52 # define ASSERT(x) tap_result(x, "%s:%d", __FILE__, __LINE__);
53 #endif
55 #include "gnugetopt_test.h"
57 static void check_mode(int posix_mode, int posixly_correct)
59 if (posix_mode == posixly_correct)
60 return;
62 if (!posix_mode)
63 tap_diag("Please remove POSIXLY_CORRECT from the environment");
64 else
65 tap_diag("Please set POSIXLY_CORRECT in the environment");
67 tap_skip_all("POSIXLY_CORRECT environment mismatch");
70 static void usage(void)
72 tap_bail_out("Usage: t/gnu_getopt [posix|gnu]");
75 int main(int argc, char **argv)
77 int posixly_correct = !!getenv("POSIXLY_CORRECT");
79 if (argc == 2) {
80 if (!strcmp(argv[1], "posix"))
81 check_mode(1, posixly_correct);
82 else if (!strcmp(argv[1], "gnu"))
83 check_mode(0, posixly_correct);
84 else
85 usage();
86 } else if (argc > 2) {
87 usage();
88 } else {
89 check_mode(0, posixly_correct);
92 if (getenv("POSIXLY_CORRECT"))
93 test_getopt_long_posix();
94 else
95 test_getopt_long();
97 test_getopt_long_only();
99 tap_done();