summary refs log tree commit diff
path: root/posix/testfnm.c
diff options
context:
space:
mode:
Diffstat (limited to 'posix/testfnm.c')
-rw-r--r--posix/testfnm.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/posix/testfnm.c b/posix/testfnm.c
index 3b3aa9730f..5ab761b8b2 100644
--- a/posix/testfnm.c
+++ b/posix/testfnm.c
@@ -1,10 +1,39 @@
+#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 },
+};
+
 int
-main (int c, char *v[])
+main (void)
 {
-  printf ("%d\n", fnmatch (v[1], v[2], FNM_PERIOD));
-  printf ("%d\n", fnmatch (v[1], v[2], FNM_CASEFOLD|FNM_PERIOD));
-  exit (0);
+  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);
 }