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;
25 int output_iterations = 0;
27 static struct poptOption long_options[] = {
28 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
29 {"iterations", 'i', POPT_ARG_NONE, &output_iterations, 0, 0, 0},
33 /* match just at the start of string (anchored tests) */
35 run_test(int line, bool matches, bool same_as_fnmatch,
36 const char *text, const char *pattern)
39 #ifdef COMPARE_WITH_FNMATCH
41 int flags = strstr(pattern, "**")? 0 : FNM_PATHNAME;
43 same_as_fnmatch = 0; /* Get rid of unused-variable compiler warning. */
46 matched = wildmatch(pattern, text);
47 #ifdef COMPARE_WITH_FNMATCH
48 fn_matched = !fnmatch(pattern, text, flags);
50 if (matched != matches) {
51 printf("wildmatch failure on line %d:\n %s\n %s\n expected %s match\n",
52 line, text, pattern, matches? "a" : "NO");
55 #ifdef COMPARE_WITH_FNMATCH
56 if (fn_matched != (matches ^ !same_as_fnmatch)) {
57 printf("fnmatch disagreement on line %d:\n %s\n %s\n expected %s match\n",
58 line, text, pattern, matches ^ !same_as_fnmatch? "a" : "NO");
62 if (output_iterations) {
63 printf("%d: \"%s\" iterations = %d\n", line, pattern,
64 wildmatch_iteration_count);
69 main(int argc, char **argv)
71 char buf[2048], *s, *string[2], *end[2];
73 int opt, line, i, flag[2];
74 poptContext pc = poptGetContext("wildtest", argc, (const char**)argv,
77 while ((opt = poptGetNextOpt(pc)) != -1) {
80 fprintf(stderr, "%s: %s\n",
81 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
87 argv = (char**)poptGetArgs(pc);
88 if (!argv || argv[1]) {
89 fprintf(stderr, "Usage: wildtest TESTFILE\n");
93 if ((fp = fopen(*argv, "r")) == NULL) {
94 fprintf(stderr, "Unable to open %s\n", *argv);
99 while (fgets(buf, sizeof buf, fp)) {
101 if (*buf == '#' || *buf == '\n')
103 for (s = buf, i = 0; i <= 1; i++) {
110 if (*++s != ' ' && *s != '\t')
113 fprintf(stderr, "Invalid flag syntax on line %d of %s:\n%s",
117 while (*++s == ' ' || *s == '\t') {}
119 for (i = 0; i <= 1; i++) {
120 if (*s == '\'' || *s == '"' || *s == '`') {
123 while (*s && *s != quote) s++;
125 fprintf(stderr, "Unmatched quote on line %d of %s:\n%s",
132 if (!*s || *s == '\n') {
133 fprintf(stderr, "Not enough strings on line %d of %s:\n%s",
138 while (*++s && *s != ' ' && *s != '\t' && *s != '\n') {}
141 while (*++s == ' ' || *s == '\t') {}
143 *end[0] = *end[1] = '\0';
144 run_test(line, flag[0], flag[1], string[0], string[1]);
147 if (!wildmatch_errors)
150 printf("%d", wildmatch_errors);
151 printf(" wildmatch error%s found.\n", wildmatch_errors == 1? "" : "s");
153 #ifdef COMPARE_WITH_FNMATCH
157 printf("%d", fnmatch_errors);
158 printf(" fnmatch error%s found.\n", fnmatch_errors == 1? "" : "s");