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"
41 #undef required_argument
42 #define required_argument 1
44 #undef optional_argument
45 #define optional_argument 2
47 #define FALLTHROUGH /**/
50 # define ASSERT(x) tap_result(x, "%s:%d: %s", __FILE__, __LINE__, #x);
52 # define ASSERT(x) tap_result(x, "%s:%d", __FILE__, __LINE__);
55 #include "gnugetopt_test.h"
57 static void check_mode(int posix_mode
, int posixly_correct
)
59 if (posix_mode
== posixly_correct
)
63 tap_diag("Please remove POSIXLY_CORRECT from the environment");
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");
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
);
86 } else if (argc
> 2) {
89 check_mode(0, posixly_correct
);
92 if (getenv("POSIXLY_CORRECT"))
93 test_getopt_long_posix();
97 test_getopt_long_only();