gen-options.awk: Avoid translation context for help strings.
[dxcommon.git] / t / gnugetopt.c
blob93b75d648eaa2954f7bbd17f4a3ff61adbf78532
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 /**/
48 #define ASSERT(x) tap_result(x, "%s:%d: %s", __FILE__, __LINE__, #x);
50 #include "gnugetopt_test.h"
52 static void check_mode(int posix_mode, int posixly_correct)
54 if (posix_mode == posixly_correct)
55 return;
57 if (!posix_mode)
58 tap_diag("Please remove POSIXLY_CORRECT from the environment");
59 else
60 tap_diag("Please set POSIXLY_CORRECT in the environment");
62 tap_skip_all("POSIXLY_CORRECT environment mismatch");
65 static void usage(void)
67 tap_bail_out("Usage: t/gnu_getopt [posix|gnu]");
70 int main(int argc, char **argv)
72 int posixly_correct = !!getenv("POSIXLY_CORRECT");
74 if (argc == 2) {
75 if (!strcmp(argv[1], "posix"))
76 check_mode(1, posixly_correct);
77 else if (!strcmp(argv[1], "gnu"))
78 check_mode(0, posixly_correct);
79 else
80 usage();
81 } else if (argc > 2) {
82 usage();
83 } else {
84 check_mode(0, posixly_correct);
87 if (getenv("POSIXLY_CORRECT"))
88 test_getopt_long_posix();
89 else
90 test_getopt_long();
92 test_getopt_long_only();
94 tap_done();