summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/regress/lib/libc/fnmatch/Makefile4
-rw-r--r--src/regress/lib/libc/fnmatch/fnm_test.c23
-rw-r--r--src/regress/lib/libc/fnmatch/fnm_test.in254
3 files changed, 277 insertions, 4 deletions
diff --git a/src/regress/lib/libc/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile
index b2f357105f..4acdd351bc 100644
--- a/src/regress/lib/libc/fnmatch/Makefile
+++ b/src/regress/lib/libc/fnmatch/Makefile
@@ -1,6 +1,8 @@
1# $OpenBSD: Makefile,v 1.1 2008/10/01 23:04:58 millert Exp $ 1# $OpenBSD: Makefile,v 1.2 2011/09/17 15:12:38 stsp Exp $
2 2
3PROG= fnm_test 3PROG= fnm_test
4LDADD+= -lutil
5DPADD+= ${LIBUTIL}
4 6
5run-regress-${PROG}: 7run-regress-${PROG}:
6 ./${PROG} ${.CURDIR}/${PROG}.in 8 ./${PROG} ${.CURDIR}/${PROG}.in
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}
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.in b/src/regress/lib/libc/fnmatch/fnm_test.in
index 3c707f8a19..c20077966d 100644
--- a/src/regress/lib/libc/fnmatch/fnm_test.in
+++ b/src/regress/lib/libc/fnmatch/fnm_test.in
@@ -3,3 +3,257 @@
3/bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 3/bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1
4[[:alpha:][:alnum:]]*.c foo1.c 0x4 0 4[[:alpha:][:alnum:]]*.c foo1.c 0x4 0
5[[:upper:]]* FOO 0x0 0 5[[:upper:]]* FOO 0x0 0
6# 'te\st' 'test'; no match if FNM_NOESCAPE
7te\st test 0x0 0
8te\st test 0x1 1
9te\st test 0x1e 0
10# 'te\\st' 'te\st'; no match if FNM_NOESCAPE
11te\\st te\st 0x0 0
12te\\st te\st 0x1 1
13te\\st te\st 0x1e 0
14# 'te\*t' 'te*t'; no match if FNM_NOESCAPE
15te\*t te*t 0x0 0
16te\*t te*t 0x1 1
17te\*t te*t 0x1e 0
18# 'te\*t' 'test'; no match
19te\*t test 0x0 1
20te\*t test 0x1f 1
21# 'te\?t' 'te?t'; no match if FNM_NOESCAPE
22te\?t te?t 0x0 0
23te\?t te?t 0x1 1
24te\?t te?t 0x1e 0
25# 'te\?t' 'test'; no match
26te\?t test 0x0 1
27te\?t test 0x1f 1
28# 'tesT' 'test'; match if FNM_CASEFOLD
29tesT test 0x0 1
30tesT test 0xf 1
31tesT test 0x10 0
32# 'test' 'Test'; match if FNM_CASEFOLD
33test Test 0x0 1
34test Test 0xf 1
35test Test 0x10 0
36# 'tEst' 'teSt'; match if FNM_CASEFOLD
37tEst teSt 0x0 1
38tEst teSt 0xf 1
39tEst teSt 0x10 0
40# '?est' 'test'; match always
41?est test 0x0 0
42?est test 0x1f 0
43# 'te?t' 'test'; match always
44te?t test 0x0 0
45te?t test 0x1f 0
46# 'tes?' 'test'; match always
47tes? test 0x0 0
48tes? test 0x1f 0
49# 'test?' 'test'; no match
50test? test 0x0 1
51test? test 0x1f 1
52# '*' always matches anything
53* test 0x0 0
54* test 0x1f 0
55# '*test' 'test'; match always
56*test test 0x0 0
57*test test 0x1f 0
58# '*est' 'test'; match always
59*est test 0x0 0
60*est test 0x1f 0
61# '*st' 'test'; match always
62*st test 0x0 0
63*st test 0x1f 0
64# 't*t' 'test'; match always
65t*t test 0x0 0
66t*t test 0x1f 0
67# 'te*t' 'test'; match always
68te*t test 0x0 0
69te*t test 0x1f 0
70# 'te*st' 'test'; match always
71te*st test 0x0 0
72te*st test 0x1f 0
73# 'te*' 'test'; match always
74te* test 0x0 0
75te* test 0x1f 0
76# 'tes*' 'test'; match always
77tes* test 0x0 0
78tes* test 0x1f 0
79# 'test*' 'test'; match always
80test* test 0x0 0
81test* test 0x1f 0
82# '.[\-\t]' '.t'; match always
83.[\-\t] .t 0x0 0
84.[\-\t] .t 0x1f 0
85# 'test*?*[a-z]*' 'testgoop'; match always
86test*?*[a-z]* testgoop 0x0 0
87test*?*[a-z]* testgoop 0x1f 0
88# 'te[^abc]t' 'test'; match always
89te[^abc]t test 0x0 0
90te[^abc]t test 0x1f 0
91# 'te[^x]t' 'test'; match always
92te[^x]t test 0x0 0
93te[^x]t test 0x1f 0
94# 'te[!x]t' 'test'; match always
95te[!x]t test 0x0 0
96te[^x]t test 0x1f 0
97# 'te[^x]t' 'text'; no match
98te[^x]t text 0x0 1
99te[^x]t text 0x1f 1
100# 'te[^\x]t' 'text'; no match
101te[^\x]t text 0x0 1
102te[^\x]t text 0x1f 1
103# 'te[^\x' 'text'; no match
104te[^\x text 0x0 1
105te[^\x text 0x1f 1
106# 'te[/]t' 'text'; no match
107te[/]t text 0x0 1
108te[/]t text 0x1f 1
109# 'te[S]t' 'test'; match if FNM_CASEFOLD
110te[S]t test 0x0 1
111te[S]t test 0xf 1
112te[S]t test 0x10 0
113# 'te[r-t]t' 'test'; match always
114te[r-t]t test 0x0 0
115te[r-t]t test 0x1f 0
116# 'te[r-t]t' 'teSt'; match if FNM_CASEFOLD
117te[r-t]t teSt 0x0 1
118te[r-t]t teSt 0xf 1
119te[r-t]t teSt 0x10 0
120# 'te[r-T]t' 'test'; match if FNM_CASEFOLD
121te[r-T]t test 0x0 1
122te[r-T]t test 0xf 1
123te[r-T]t test 0x10 0
124# 'te[R-T]t' 'test'; match if FNM_CASEFOLD
125te[R-T]t test 0x0 1
126te[R-T]t test 0xf 1
127te[R-T]t test 0x10 0
128# 'te[r-Tz]t' 'tezt'; match always
129te[r-Tz]t tezt 0x0 0
130te[r-Tz]t tezt 0x1f 0
131# 'te[R-T]t' 'tent'; no match
132te[R-T]t tent 0x0 1
133te[R-T]t tent 0x1f 1
134# 'tes[]t]' 'test'; match always
135tes[]t] test 0x0 0
136tes[]t] test 0x1f 0
137# 'tes[t-]' 'test'; match always
138tes[t-] test 0x0 0
139tes[t-] test 0x1f 0
140# 'tes[t-]]' 'test]'; match always
141tes[t-]] test] 0x0 0
142tes[t-]] test] 0x1f 0
143# 'tes[t-]]' 'test'; no match
144tes[t-]] test 0x0 1
145tes[t-]] test 0x1f 1
146# 'tes[u-]' 'test'; no match
147tes[u-] test 0x0 1
148tes[u-] test 0x1f 1
149# 'tes[t-]' 'tes[t-]'; no match
150tes[t-] test[t-] 0x0 1
151tes[t-] test[t-] 0x1f 1
152# 'test[/-/]' 'test[/-/]'; no match
153test[/-/] test/-/ 0x0 1
154test[/-/] test/-/ 0x1f 1
155# 'test[\/-/]' 'test[/-/]'; no match
156test[\/-/] test/-/ 0x0 1
157test[\/-/] test/-/ 0x1f 1
158# 'test[/-\/]' 'test[/-/]'; no match
159test[/-\/] test/-/ 0x0 1
160test[/-\/] test/-/ 0x1f 1
161# 'test[/-/]' 'test/'; no match if APR_FNM_PATHNAME
162test[/-/] test/ 0x0 0
163test[/-/] test/ 0x2 1
164test[/-/] test/ 0x1d 0
165# 'test[\/-/]' 'test/'; no match if APR_FNM_PATHNAME
166test[\/-/] test/ 0x0 0
167test[\/-/] test/ 0x2 1
168test[\/-/] test/ 0x1d 0
169# 'test[/-\/]' 'test/'; no match if APR_FNM_PATHNAME
170test[/-\/] test/ 0x0 0
171test[/-\/] test/ 0x2 1
172test[/-\/] test/ 0x1d 0
173# '/test' 'test'; no match
174/test test 0x0 1
175/test test 0x1f 1
176# 'test' '/test'; no match
177test /test 0x0 1
178test /test 0x1f 1
179# 'test/' 'test'; no match
180test/ test 0x0 1
181test/ test 0x1f 1
182# 'test' 'test/'; match if FNM_LEADING_DIR
183test test/ 0x0 1
184test test/ 0x17 1
185test test/ 0x8 0
186# '\/test' '/test'; match unless FNM_NOESCAPE
187\/test /test 0x0 0
188\/test /test 0x1 1
189\/test /test 0x1e 0
190# '*test' '/test'; match unless FNM_PATHNAME
191*test /test 0x0 0
192*test /test 0x2 1
193*test /test 0x1d 0
194# '/*/test' '/test'; no match
195/*/test /test 0x0 1
196/*/test /test 0x1f 1
197# '/*/test' '/test/test'; match always
198/*/test /test/test 0x0 0
199/*/test /test/test 0x1f 0
200# 'test/this' 'test/'; match never
201test/this test/ 0x0 1
202test/this test/ 0x1f 1
203# 'test/' 'test/this'; match never
204test/ test/this 0x0 1
205test/ test/this 0x1f 1
206# 'test*/this' 'test/this'; match always
207test*/this test/this 0x0 0
208test*/this test/this 0x1f 0
209# 'test*/this' 'test/that'; match never
210test*/this test/that 0x0 1
211test*/this test/that 0x1f 1
212# 'test/*this' 'test/this'; match always
213test/*this test/this 0x0 0
214test/*this test/this 0x1f 0
215# '.*' '.this'; match always
216.* .this 0x0 0
217.* .this 0x1f 0
218# '*' '.this'; fails if FNM_PERIOD
219* .this 0x0 0
220* .this 0x4 1
221* .this 0x1b 0
222# '?this' '.this'; fails if FNM_PERIOD
223?this .this 0x0 0
224?this .this 0x4 1
225?this .this 0x1b 0
226# '[.]this' '.this'; fails if FNM_PERIOD
227[.]this .this 0x0 0
228[.]this .this 0x4 1
229[.]this .this 0x1b 0
230# 'test/this' 'test/this'; match always
231test/this test/this 0x0 0
232test/this test/this 0x1f 0
233# 'test?this' 'test/this'; fails if FNM_PATHNAME
234test?this test/this 0x0 0
235test?this test/this 0x2 1
236test?this test/this 0x1d 0
237# 'test*this' 'test/this'; fails if FNM_PATHNAME
238test*this test/this 0x0 0
239test*this test/this 0x2 1
240test*this test/this 0x1d 0
241# 'test[/]this' 'test/this'; fails if FNM_PATHNAME
242test[/]this test/this 0x0 0
243test[/]this test/this 0x2 1
244test[/]this test/this 0x1d 0
245# 'test/.*' 'test/.this'; match always
246test/.* test/.this 0x0 0
247test/.* test/.this 0x1f 0
248# 'test/*' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME
249test/* test/.this 0x0 0
250test/* test/.this 0x6 1
251test/* test/.this 0x19 0
252# 'test/?' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME
253test/?this test/.this 0x0 0
254test/?this test/.this 0x6 1
255test/?this test/.this 0x19 0
256# 'test/[.]this' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME
257test/[.]this test/.this 0x0 0
258test/[.]this test/.this 0x6 1
259test/[.]this test/.this 0x19 0