Skip to content

Commit

Permalink
Fix unit test build on NetBSD
Browse files Browse the repository at this point in the history
The previous fix overlooked that symbol `getopt_long_only` was still
used even though it wouldn't be called. Fix that oversight and replace
the `__NetBSD__` symbol test with a proper feature test for whether the
platform provides `getopt_long_only()`.

Fixes #1451
  • Loading branch information
krader1961 committed Dec 20, 2019
1 parent c007254 commit c6757a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions config_ast.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
#mesondefine _lib_ftruncate
#mesondefine _lib_ftruncate64
#mesondefine _lib_getexecname
#mesondefine _lib_getopt_long_only
#mesondefine _lib_getrusage
#mesondefine _lib_gettimeofday
#mesondefine _lib_lchmod
Expand Down
3 changes: 3 additions & 0 deletions features/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ if feature_data.get('_lib_lchmod', 0) == 0
endif
endif

feature_data.set10('_lib_getopt_long_only',
cc.has_function('getopt_long_only', prefix: '#include <getopt.h>',
args: feature_test_args))
feature_data.set10('_lib_getrusage',
cc.has_function('getrusage',
prefix: '\n'.join(['#include <sys/resource.h>', '#include <sys/time.h>']),
Expand Down
21 changes: 13 additions & 8 deletions src/lib/libast/tests/misc/optget_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ struct optget_test {

// Old GNU `getopt_long_only()` implementations have a bug. See `check_for_getopt_long_only_bug()`.
static bool getopt_long_only_works = true;
#if !_lib_getopt_long_only
// This won't actually be used. It's just the simplest way to silence build errors if the symbol
// doesn't exist.
#define getopt_long_only getopt_long
#endif // !_lib_getopt_long_only

#define TERROR(line, ...) \
do { \
Expand Down Expand Up @@ -465,13 +470,7 @@ static void test_options_with_values() {

// Old GNU `getopt_long_only()` implementations, such as found in Fedora 28, have a bug which makes
// them unsuitable for verifying the correctness of our tests. On some platforms it may not exist.
#if defined(__NetBSD__)

void check_for_getopt_long_only_bug() {
getopt_long_only_works = false; // it doesn't exist which is why it doesn't work
}

#else // defined(__NetBSD__)
#if _lib_getopt_long_only

void check_for_getopt_long_only_bug() {
char *const argv[] = {"cmd", "-vHUP", "arg1", NULL};
Expand All @@ -493,7 +492,13 @@ void check_for_getopt_long_only_bug() {
getopt_long_only_works = false;
}

#endif // defined(__NetBSD__)
#else // _lib_getopt_long_only

void check_for_getopt_long_only_bug() {
getopt_long_only_works = false; // it doesn't exist which is why it doesn't work
}

#endif // _lib_getopt_long_only

tmain() {
UNUSED(argc);
Expand Down

0 comments on commit c6757a2

Please sign in to comment.