Skip to content
Permalink
Browse files

Fix unit test build on NetBSD

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 c6757a29d1e52354a77e4819900394c6f5453791
Showing with 17 additions and 8 deletions.
  1. +1 −0 config_ast.h.in
  2. +3 −0 features/meson.build
  3. +13 −8 src/lib/libast/tests/misc/optget_long.c
@@ -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
@@ -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>']),
@@ -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 { \
@@ -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};
@@ -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);

0 comments on commit c6757a2

Please sign in to comment.
You can’t perform that action at this time.