2 ** wildmatch test suite.
5 /*#define COMPARE_WITH_FNMATCH*/
7 #define WILD_TEST_ITERATIONS
8 #include "lib/wildmatch.c"
12 #ifdef COMPARE_WITH_FNMATCH
15 int fnmatch_errors
= 0;
18 int wildmatch_errors
= 0;
22 int output_iterations
= 0;
24 static struct poptOption long_options
[] = {
25 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
26 {"iterations", 'i', POPT_ARG_NONE
, &output_iterations
, 0, 0, 0},
30 /* match just at the start of string (anchored tests) */
32 run_test(int line
, bool matches
, bool same_as_fnmatch
,
33 const char *text
, const char *pattern
)
36 #ifdef COMPARE_WITH_FNMATCH
38 int flags
= strstr(pattern
, "**")? 0 : FNM_PATHNAME
;
40 same_as_fnmatch
= 0; /* Get rid of unused-variable compiler warning. */
43 matched
= wildmatch(pattern
, text
);
44 #ifdef COMPARE_WITH_FNMATCH
45 fn_matched
= !fnmatch(pattern
, text
, flags
);
47 if (matched
!= matches
) {
48 printf("wildmatch failure on line %d:\n %s\n %s\n expected %s match\n",
49 line
, text
, pattern
, matches
? "a" : "NO");
52 #ifdef COMPARE_WITH_FNMATCH
53 if (fn_matched
!= (matches
^ !same_as_fnmatch
)) {
54 printf("fnmatch disagreement on line %d:\n %s\n %s\n expected %s match\n",
55 line
, text
, pattern
, matches
^ !same_as_fnmatch
? "a" : "NO");
59 if (output_iterations
) {
60 printf("%d: \"%s\" iterations = %d\n", line
, pattern
,
61 wildmatch_iteration_count
);
66 main(int argc
, char **argv
)
68 char buf
[2048], *s
, *string
[2], *end
[2];
70 int opt
, line
, i
, flag
[2];
71 poptContext pc
= poptGetContext("wildtest", argc
, (const char**)argv
,
74 while ((opt
= poptGetNextOpt(pc
)) != -1) {
77 fprintf(stderr
, "%s: %s\n",
78 poptBadOption(pc
, POPT_BADOPTION_NOALIAS
),
84 argv
= (char**)poptGetArgs(pc
);
85 if (!argv
|| argv
[1]) {
86 fprintf(stderr
, "Usage: wildtest TESTFILE\n");
90 if ((fp
= fopen(*argv
, "r")) == NULL
) {
91 fprintf(stderr
, "Unable to open %s\n", *argv
);
96 while (fgets(buf
, sizeof buf
, fp
)) {
98 if (*buf
== '#' || *buf
== '\n')
100 for (s
= buf
, i
= 0; i
<= 1; i
++) {
107 if (*++s
!= ' ' && *s
!= '\t')
110 fprintf(stderr
, "Invalid flag syntax on line %d of %s:\n%s",
114 while (*++s
== ' ' || *s
== '\t') {}
116 for (i
= 0; i
<= 1; i
++) {
117 if (*s
== '\'' || *s
== '"' || *s
== '`') {
120 while (*s
&& *s
!= quote
) s
++;
122 fprintf(stderr
, "Unmatched quote on line %d of %s:\n%s",
129 if (!*s
|| *s
== '\n') {
130 fprintf(stderr
, "Not enough strings on line %d of %s:\n%s",
135 while (*++s
&& *s
!= ' ' && *s
!= '\t' && *s
!= '\n') {}
138 while (*++s
== ' ' || *s
== '\t') {}
140 *end
[0] = *end
[1] = '\0';
141 run_test(line
, flag
[0], flag
[1], string
[0], string
[1]);
144 if (!wildmatch_errors
)
147 printf("%d", wildmatch_errors
);
148 printf(" wildmatch error%s found.\n", wildmatch_errors
== 1? "" : "s");
150 #ifdef COMPARE_WITH_FNMATCH
154 printf("%d", fnmatch_errors
);
155 printf(" fnmatch error%s found.\n", fnmatch_errors
== 1? "" : "s");