diff options
author | millert <> | 2008-10-01 23:04:58 +0000 |
---|---|---|
committer | millert <> | 2008-10-01 23:04:58 +0000 |
commit | 3c3a40014682057cec32fdb3d8131abde149c68a (patch) | |
tree | bd23c16aa9562a4c08096f113a441cf101b83303 /src | |
parent | 691bfd499fc285155869cabf20c6eb1d1c0f8ae8 (diff) | |
download | openbsd-3c3a40014682057cec32fdb3d8131abde149c68a.tar.gz openbsd-3c3a40014682057cec32fdb3d8131abde149c68a.tar.bz2 openbsd-3c3a40014682057cec32fdb3d8131abde149c68a.zip |
Regress driver for fnmatch(3). Needs more tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/fnmatch/Makefile | 8 | ||||
-rw-r--r-- | src/regress/lib/libc/fnmatch/fnm_test.c | 45 | ||||
-rw-r--r-- | src/regress/lib/libc/fnmatch/fnm_test.in | 5 |
3 files changed, 58 insertions, 0 deletions
diff --git a/src/regress/lib/libc/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile new file mode 100644 index 0000000000..b2f357105f --- /dev/null +++ b/src/regress/lib/libc/fnmatch/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2008/10/01 23:04:58 millert Exp $ | ||
2 | |||
3 | PROG= fnm_test | ||
4 | |||
5 | run-regress-${PROG}: | ||
6 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
7 | |||
8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.c b/src/regress/lib/libc/fnmatch/fnm_test.c new file mode 100644 index 0000000000..e987010095 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* $OpenBSD: fnm_test.c,v 1.1 2008/10/01 23:04:58 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <fnmatch.h> | ||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | int | ||
13 | main(int argc, char **argv) | ||
14 | { | ||
15 | FILE *fp = stdin; | ||
16 | char pattern[1024], string[1024]; | ||
17 | int errors = 0, flags, got, want; | ||
18 | |||
19 | if (argc > 1) { | ||
20 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
21 | err(1, "%s", argv[1]); | ||
22 | } | ||
23 | |||
24 | /* | ||
25 | * Read in test file, which is formatted thusly: | ||
26 | * | ||
27 | * pattern string flags expected_result | ||
28 | * | ||
29 | */ | ||
30 | for (;;) { | ||
31 | got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags, | ||
32 | &want); | ||
33 | if (got == EOF) | ||
34 | break; | ||
35 | if (got == 4) { | ||
36 | got = fnmatch(pattern, string, flags); | ||
37 | if (got != want) { | ||
38 | warnx("%s %s %d: want %d, got %d", pattern, | ||
39 | string, flags, want, got); | ||
40 | errors++; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | exit(errors); | ||
45 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.in b/src/regress/lib/libc/fnmatch/fnm_test.in new file mode 100644 index 0000000000..3c707f8a19 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.in | |||
@@ -0,0 +1,5 @@ | |||
1 | /bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 | ||
2 | /bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 | ||
3 | /bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 | ||
4 | [[:alpha:][:alnum:]]*.c foo1.c 0x4 0 | ||
5 | [[:upper:]]* FOO 0x0 0 | ||