glibc/posix/testfnm.c
Ulrich Drepper 45a89cc6c6 Update.
1999-04-26  Ulrich Drepper  <drepper@cygnus.com>

	* posix/fnmatch.c: Include string.h also for glibc.
	(fnmatch, case '?'): Optimize if cascades a bit.
	(fnmatch, case '*'): Correct handling if FNM_PATHNAME is set.

	* posix/testfnm.c: Add test cases for * with FNM_PATHNAME errors.
1999-04-26 07:50:45 +00:00

43 lines
913 B
C

#include <stdlib.h>
#include <stdio.h>
#include "fnmatch.h"
struct {
const char *name;
const char *pattern;
int flags;
int expected;
} tests[] = {
{ "lib", "*LIB*", FNM_PERIOD, FNM_NOMATCH },
{ "lib", "*LIB*", FNM_CASEFOLD|FNM_PERIOD, 0 },
{ "a/b", "a[/]b", 0, 0 },
{ "a/b", "a[/]b", FNM_PATHNAME, FNM_NOMATCH },
{ "a/b", "[a-z]/[a-z]", 0, 0 },
{ "a/b", "*", FNM_FILE_NAME, FNM_NOMATCH },
{ "a/b", "*[/]b", FNM_FILE_NAME, FNM_NOMATCH },
{ "a/b", "*[b]", FNM_FILE_NAME, FNM_NOMATCH }
};
int
main (void)
{
size_t i;
int errors = 0;
for (i = 0; i < sizeof (tests) / sizeof (*tests); i++)
{
int match;
match = fnmatch (tests[i].pattern, tests[i].name, tests[i].flags);
if (match != tests[i].expected)
{
printf ("%s %s %s\n", tests[i].pattern,
match == 0 ? "matches" : "does not match",
tests[i].name);
errors++;
}
}
exit (errors != 0);
}