tests: Add getopt test

This commit is contained in:
Alexander van der Grinten 2020-12-29 20:51:10 +01:00
parent 03228332b7
commit 02fca52daa
2 changed files with 44 additions and 0 deletions

27
tests/glibc/getopt.c Normal file
View file

@ -0,0 +1,27 @@
#include <assert.h>
#include <getopt.h>
#include <stddef.h>
#include <stdio.h>
int main() {
const char *shortopts = "f:";
const struct option longopts[] = {
{"foo", required_argument, NULL, 'f'},
{NULL, no_argument, NULL, 0}
};
int test_argc = 2;
char *test_argv[] = {
"dummy",
"--foo",
"abc"
};
int c;
c = getopt_long(test_argc, test_argv, shortopts, longopts, NULL);
assert(c == 'f');
c = getopt_long(test_argc, test_argv, shortopts, longopts, NULL);
assert(c == -1);
}

View file

@ -10,6 +10,10 @@ posix_test_cases = [
'pthread_rwlock'
]
glibc_test_cases = [
'getopt'
]
test_sources = [
crt
]
@ -42,3 +46,16 @@ if not disable_posix_option
test('posix/' + f, exec)
endforeach
endif
# We never disable the posix option so glibc is gated behind the posix option here.
if not disable_posix_option
foreach f : glibc_test_cases
exec = executable('glibc-' + f, ['glibc/' + f + '.c', test_sources],
link_with: libc, include_directories: libc_include_dirs,
build_rpath: meson.build_root(),
c_args: '-no-pie',
link_args: ['-Wl,--dynamic-linker=' + meson.build_root() + '/ld.so',
'-no-pie'])
test('glibc/' + f, exec)
endforeach
endif