summaryrefslogtreecommitdiff
path: root/regress/lib/libc/fnmatch/fnm_test.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2008-10-01 23:04:59 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2008-10-01 23:04:59 +0000
commit061f0bb4fbc24353ff0974a3f0ff2af5b6acabd1 (patch)
tree8a74ea9bda8c587e4d8f9432e281abdd55deeb1e /regress/lib/libc/fnmatch/fnm_test.c
parent442e27cc541945204777251780922d4ee1e46708 (diff)
Regress driver for fnmatch(3). Needs more tests.
Diffstat (limited to 'regress/lib/libc/fnmatch/fnm_test.c')
-rw-r--r--regress/lib/libc/fnmatch/fnm_test.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/regress/lib/libc/fnmatch/fnm_test.c b/regress/lib/libc/fnmatch/fnm_test.c
new file mode 100644
index 00000000000..e9870100951
--- /dev/null
+++ b/regress/lib/libc/fnmatch/fnm_test.c
@@ -0,0 +1,45 @@
+/* $OpenBSD: fnm_test.c,v 1.1 2008/10/01 23:04:58 millert Exp $ */
+
+/*
+ * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com>
+ */
+
+#include <err.h>
+#include <fnmatch.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char **argv)
+{
+ FILE *fp = stdin;
+ char pattern[1024], string[1024];
+ int errors = 0, flags, got, want;
+
+ if (argc > 1) {
+ if ((fp = fopen(argv[1], "r")) == NULL)
+ err(1, "%s", argv[1]);
+ }
+
+ /*
+ * Read in test file, which is formatted thusly:
+ *
+ * pattern string flags expected_result
+ *
+ */
+ for (;;) {
+ got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags,
+ &want);
+ if (got == EOF)
+ break;
+ if (got == 4) {
+ got = fnmatch(pattern, string, flags);
+ if (got != want) {
+ warnx("%s %s %d: want %d, got %d", pattern,
+ string, flags, want, got);
+ errors++;
+ }
+ }
+ }
+ exit(errors);
+}