From f949dbcc584f9f1687828e4920f72e042f0b1fd8 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 6 Apr 2011 10:57:39 -0400 Subject: [PATCH] Fix fnmatch and glob tests to not use hard-coded flag values in the input file. Link test programs with libreplace so we get our replacement verions as needed. --- compat/Makefile.in | 14 +++++++--- compat/regress/fnmatch/fnm_test.c | 21 +++++++++++++-- compat/regress/fnmatch/fnm_test.in | 10 +++---- compat/regress/glob/globtest.c | 43 +++++++++++++++++++++++++----- compat/regress/glob/globtest.in | 10 +++---- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/compat/Makefile.in b/compat/Makefile.in index 150e65982..0e5d17189 100644 --- a/compat/Makefile.in +++ b/compat/Makefile.in @@ -65,11 +65,17 @@ libreplace.la: $(LTLIBOBJS) ./mksiglist: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(incdir)/missing.h $(top_builddir)/config.h $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/mksiglist.c -o $@ -fnm_test: $(srcdir)/regress/fnmatch/fnm_test.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c -o $@ +fnm_test.o: $(srcdir)/regress/fnmatch/fnm_test.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c -globtest: $(srcdir)/regress/glob/globtest.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/glob/globtest.c -o $@ +fnm_test: fnm_test.o libreplace.la + $(LIBTOOL) --mode=link $(CC) -o $@ fnm_test.o libreplace.la + +globtest.o: $(srcdir)/regress/glob/globtest.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/glob/globtest.c + +globtest: globtest.o libreplace.la + $(LIBTOOL) --mode=link $(CC) -o $@ globtest.o libreplace.la @DEV@$(srcdir)/mksiglist.h: $(srcdir)/siglist.in @DEV@ awk 'BEGIN {print "/* public domain */\n"} /^ [A-Z]/ {printf("#ifdef SIG%s\n if (my_sys_siglist[SIG%s] == NULL)\n\tmy_sys_siglist[SIG%s] = \"%s\";\n#endif\n", $$1, $$1, $$1, substr($$0, 13))}' < $(srcdir)/siglist.in > $@ diff --git a/compat/regress/fnmatch/fnm_test.c b/compat/regress/fnmatch/fnm_test.c index 3846ec9ec..2079e3b4a 100644 --- a/compat/regress/fnmatch/fnm_test.c +++ b/compat/regress/fnmatch/fnm_test.c @@ -8,6 +8,12 @@ #include #include +#ifdef HAVE_STRING_H +# include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ #ifdef HAVE_FNMATCH # include #else @@ -18,7 +24,7 @@ int main(int argc, char *argv[]) { FILE *fp = stdin; - char pattern[1024], string[1024]; + char pattern[1024], string[1024], flagstr[1024]; int errors = 0, tests = 0, flags, got, want; if (argc > 1) { @@ -35,11 +41,22 @@ main(int argc, char *argv[]) * */ for (;;) { - got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags, + got = fscanf(fp, "%s %s %s %d\n", pattern, string, flagstr, &want); if (got == EOF) break; if (got == 4) { + flags = 0; + if (strcmp(flagstr, "FNM_NOESCAPE") == 0) + flags |= FNM_NOESCAPE; + else if (strcmp(flagstr, "FNM_PATHNAME") == 0) + flags |= FNM_PATHNAME; + else if (strcmp(flagstr, "FNM_PERIOD") == 0) + flags |= FNM_PERIOD; + else if (strcmp(flagstr, "FNM_LEADING_DIR") == 0) + flags |= FNM_LEADING_DIR; + else if (strcmp(flagstr, "FNM_CASEFOLD") == 0) + flags |= FNM_CASEFOLD; got = fnmatch(pattern, string, flags); if (got != want) { fprintf(stderr, diff --git a/compat/regress/fnmatch/fnm_test.in b/compat/regress/fnmatch/fnm_test.in index 3c707f8a1..e19ec7df2 100644 --- a/compat/regress/fnmatch/fnm_test.in +++ b/compat/regress/fnmatch/fnm_test.in @@ -1,5 +1,5 @@ -/bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 -/bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 -/bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 -[[:alpha:][:alnum:]]*.c foo1.c 0x4 0 -[[:upper:]]* FOO 0x0 0 +/bin/[[:alpha:][:alnum:]]* /bin/ls FNM_PATHNAME 0 +/bin/[[:upper:]][[:alnum:]] /bin/ls FNM_CASEFOLD 0 +/bin/[[:opper:][:alnum:]]* /bin/ls NONE 1 +[[:alpha:][:alnum:]]*.c foo1.c FNM_PERIOD 0 +[[:upper:]]* FOO NONE 0 diff --git a/compat/regress/glob/globtest.c b/compat/regress/glob/globtest.c index f454a1dec..a9be5e266 100644 --- a/compat/regress/glob/globtest.c +++ b/compat/regress/glob/globtest.c @@ -19,9 +19,14 @@ #else # include "compat/glob.h" #endif +#include #define MAX_RESULTS 256 +#ifndef errno +extern int errno; +#endif + struct gl_entry { int flags; int nresults; @@ -104,17 +109,40 @@ main(int argc, char **argv) lineno); exit(1); } - entry.flags = (int)strtol(cp, &ep, 0); - if (*ep != '>') { + ep = strchr(cp, '>'); + if (ep == NULL) { fprintf(stderr, "globtest: invalid entry on line %d\n", lineno); exit(1); } - if (entry.flags < 0 || entry.flags > 0x2000) { - fprintf(stderr, - "globtest: invalid flags: %s\n", cp); - exit(1); + *ep = '\0'; + entry.flags = 0; + for ((cp = strtok(cp, "|")); cp != NULL; (cp = strtok(NULL, "|"))) { + if (strcmp(cp, "GLOB_APPEND") == 0) + entry.flags |= GLOB_APPEND; + else if (strcmp(cp, "GLOB_DOOFFS") == 0) + entry.flags |= GLOB_DOOFFS; + else if (strcmp(cp, "GLOB_ERR") == 0) + entry.flags |= GLOB_ERR; + else if (strcmp(cp, "GLOB_MARK") == 0) + entry.flags |= GLOB_MARK; + else if (strcmp(cp, "GLOB_NOCHECK") == 0) + entry.flags |= GLOB_NOCHECK; + else if (strcmp(cp, "GLOB_NOSORT") == 0) + entry.flags |= GLOB_NOSORT; + else if (strcmp(cp, "GLOB_NOESCAPE") == 0) + entry.flags |= GLOB_NOESCAPE; + else if (strcmp(cp, "GLOB_BRACE") == 0) + entry.flags |= GLOB_BRACE; + else if (strcmp(cp, "GLOB_TILDE") == 0) + entry.flags |= GLOB_TILDE; + else if (strcmp(cp, "NONE") != 0) { + fprintf(stderr, + "globtest: invalid flags on line %d\n", + lineno); + exit(1); + } } entry.nresults = 0; continue; @@ -151,7 +179,8 @@ int test_glob(struct gl_entry *entry) int i = 0; if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) { - fprintf(stderr, "glob failed: %s", entry->pattern); + fprintf(stderr, "glob failed: %s: %s\n", entry->pattern, + strerror(errno)); exit(1); } diff --git a/compat/regress/glob/globtest.in b/compat/regress/glob/globtest.in index 5995fa4b3..20a86c1ed 100644 --- a/compat/regress/glob/globtest.in +++ b/compat/regress/glob/globtest.in @@ -1,4 +1,4 @@ -[fake/bin/[[:alpha:]]*] <0x0> +[fake/bin/[[:alpha:]]*] fake/bin/cat fake/bin/chgrp fake/bin/chio @@ -46,19 +46,19 @@ fake/bin/systrace fake/bin/tar fake/bin/test -[fake/bin/rm{,dir,ail}] <0x80> +[fake/bin/rm{,dir,ail}] fake/bin/rm fake/bin/rmdir fake/bin/rmail -[fake/bin/sha[[:digit:]]] <0x0> +[fake/bin/sha[[:digit:]]] fake/bin/sha1 -[fake/bin/sha[[:digit:]]*] <0x0> +[fake/bin/sha[[:digit:]]*] fake/bin/sha1 fake/bin/sha256 fake/bin/sha384 fake/bin/sha512 -[fake/bin/ca[a-z]] <0x0> +[fake/bin/ca[a-z]] fake/bin/cat -- 2.40.0