summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/fnmatch/fnm_test.c
diff options
context:
space:
mode:
authorstsp <>2011-09-17 15:12:38 +0000
committerstsp <>2011-09-17 15:12:38 +0000
commit265505dce3edc3498d8e14a4d90ec6d1dc49b756 (patch)
treee754aa8c40ab822fc0e2c9250e08654c9f4e6888 /src/regress/lib/libc/fnmatch/fnm_test.c
parent338a262ca79ae9a01c09ccaea32717c943d757bf (diff)
downloadopenbsd-265505dce3edc3498d8e14a4d90ec6d1dc49b756.tar.gz
openbsd-265505dce3edc3498d8e14a4d90ec6d1dc49b756.tar.bz2
openbsd-265505dce3edc3498d8e14a4d90ec6d1dc49b756.zip
Expand fnmatch() regress with patterns obtained from the tests for APR's
new fnmatch implementation. With kind permission from Bill Rowe. Tweak the test code to allow comment lines in the test data file. ok millert@
Diffstat (limited to 'src/regress/lib/libc/fnmatch/fnm_test.c')
-rw-r--r--src/regress/lib/libc/fnmatch/fnm_test.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.c b/src/regress/lib/libc/fnmatch/fnm_test.c
index e987010095..f5958837e2 100644
--- a/src/regress/lib/libc/fnmatch/fnm_test.c
+++ b/src/regress/lib/libc/fnmatch/fnm_test.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: fnm_test.c,v 1.1 2008/10/01 23:04:58 millert Exp $ */ 1/* $OpenBSD: fnm_test.c,v 1.2 2011/09/17 15:12:38 stsp Exp $ */
2 2
3/* 3/*
4 * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> 4 * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com>
@@ -8,12 +8,15 @@
8#include <fnmatch.h> 8#include <fnmatch.h>
9#include <stdio.h> 9#include <stdio.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <util.h>
11 12
12int 13int
13main(int argc, char **argv) 14main(int argc, char **argv)
14{ 15{
15 FILE *fp = stdin; 16 FILE *fp = stdin;
16 char pattern[1024], string[1024]; 17 char pattern[1024], string[1024];
18 char *line;
19 const char delim[3] = {'\0', '\0', '#'};
17 int errors = 0, flags, got, want; 20 int errors = 0, flags, got, want;
18 21
19 if (argc > 1) { 22 if (argc > 1) {
@@ -26,12 +29,22 @@ main(int argc, char **argv)
26 * 29 *
27 * pattern string flags expected_result 30 * pattern string flags expected_result
28 * 31 *
32 * lines starting with '#' are comments
29 */ 33 */
30 for (;;) { 34 for (;;) {
31 got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags, 35 line = fparseln(fp, NULL, NULL, delim, 0);
36 if (!line)
37 break;
38 got = sscanf(line, "%s %s 0x%x %d", pattern, string, &flags,
32 &want); 39 &want);
33 if (got == EOF) 40 if (got == EOF) {
41 free(line);
34 break; 42 break;
43 }
44 if (pattern[0] == '#') {
45 free(line);
46 continue;
47 }
35 if (got == 4) { 48 if (got == 4) {
36 got = fnmatch(pattern, string, flags); 49 got = fnmatch(pattern, string, flags);
37 if (got != want) { 50 if (got != want) {
@@ -39,7 +52,11 @@ main(int argc, char **argv)
39 string, flags, want, got); 52 string, flags, want, got);
40 errors++; 53 errors++;
41 } 54 }
55 } else {
56 warnx("unrecognized line '%s'\n", line);
57 errors++;
42 } 58 }
59 free(line);
43 } 60 }
44 exit(errors); 61 exit(errors);
45} 62}