diff options
author | Assaf Gordon <assafgordon@gmail.com> | 2017-10-05 23:03:04 -0600 |
---|---|---|
committer | Assaf Gordon <assafgordon@gmail.com> | 2017-10-05 23:07:19 -0600 |
commit | 97478b089c93994efa663aa0102ed0e8150a2099 (patch) | |
tree | 0b85bd941cfed785506a5db0f6bd9cbaf76080b7 /testsuite | |
parent | a59fb8826abafb03a94fd1d4cc612e2433445e96 (diff) | |
download | sed-97478b089c93994efa663aa0102ed0e8150a2099.tar.gz |
tests: remove non-functional regex C tests
These C-based tests were not updated since 2004, and were not included
by default. Enabling them with "./configure --enable-regex-tests"
resulted in false positives:
https://bugs.gnu.org/28665 , https://bugs.gnu.org/25381 .
This patch removes them completely.
* configure.ac: Remove "--with-regex-tests" option.
* local.mk (check_PROGRAMS): Remove tests.
* bug-regex10.c,
bug-regex11.c,
bug-regex12.c,
bug-regex13.c,
bug-regex14.c,
bug-regex15.c,
bug-regex16.c,
bug-regex21.c,
bug-regex27.c,
bug-regex28.c,
bug-regex7.c,
bug-regex8.c,
bug-regex9.c,
runptests.c,
runtests.c,
tst-boost.c,
tst-pcre.c,
tst-regex.c,
tst-regex2.c,
tst-rxspencer.c: Remove files.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/bug-regex10.c | 63 | ||||
-rw-r--r-- | testsuite/bug-regex11.c | 141 | ||||
-rw-r--r-- | testsuite/bug-regex12.c | 79 | ||||
-rw-r--r-- | testsuite/bug-regex13.c | 109 | ||||
-rw-r--r-- | testsuite/bug-regex14.c | 60 | ||||
-rw-r--r-- | testsuite/bug-regex15.c | 49 | ||||
-rw-r--r-- | testsuite/bug-regex16.c | 37 | ||||
-rw-r--r-- | testsuite/bug-regex21.c | 51 | ||||
-rw-r--r-- | testsuite/bug-regex27.c | 65 | ||||
-rw-r--r-- | testsuite/bug-regex28.c | 76 | ||||
-rw-r--r-- | testsuite/bug-regex7.c | 94 | ||||
-rw-r--r-- | testsuite/bug-regex8.c | 86 | ||||
-rw-r--r-- | testsuite/bug-regex9.c | 73 | ||||
-rw-r--r-- | testsuite/local.mk | 10 | ||||
-rw-r--r-- | testsuite/runptests.c | 125 | ||||
-rw-r--r-- | testsuite/runtests.c | 140 | ||||
-rw-r--r-- | testsuite/tst-boost.c | 233 | ||||
-rw-r--r-- | testsuite/tst-pcre.c | 247 | ||||
-rw-r--r-- | testsuite/tst-regex.c | 269 | ||||
-rw-r--r-- | testsuite/tst-regex2.c | 207 | ||||
-rw-r--r-- | testsuite/tst-rxspencer.c | 558 |
21 files changed, 0 insertions, 2772 deletions
diff --git a/testsuite/bug-regex10.c b/testsuite/bug-regex10.c deleted file mode 100644 index d7b765a..0000000 --- a/testsuite/bug-regex10.c +++ /dev/null @@ -1,63 +0,0 @@ -/* Test for re_match with non-zero start. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <locale.h> -#include <stdio.h> -#include <string.h> -#include <regex.h> - -int -main (void) -{ - struct re_pattern_buffer regex; - struct re_registers regs; - const char *s; - int match; - int result = 0; - - regs.num_regs = 1; - memset (®ex, '\0', sizeof (regex)); - s = re_compile_pattern ("[abc]*d", 7, ®ex); - if (s != NULL) - { - puts ("re_compile_pattern return non-NULL value"); - result = 1; - } - else - { - match = re_match (®ex, "foacabdxy", 9, 2, ®s); - if (match != 5) - { - printf ("re_match returned %d, expected 5\n", match); - result = 1; - } - else if (regs.start[0] != 2 || regs.end[0] != 7) - { - printf ("re_match returned %d..%d, expected 2..7\n", - regs.start[0], regs.end[0]); - result = 1; - } - puts (" -> OK"); - } - - return result; -} diff --git a/testsuite/bug-regex11.c b/testsuite/bug-regex11.c deleted file mode 100644 index e02c982..0000000 --- a/testsuite/bug-regex11.c +++ /dev/null @@ -1,141 +0,0 @@ -/* Regular expression tests. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> - -/* Tests supposed to match. */ -struct -{ - const char *pattern; - const char *string; - int flags, nmatch; - regmatch_t rm[5]; -} tests[] = { - /* Test for newline handling in regex. */ - { "[^~]*~", "\nx~y", 0, 2, { { 0, 3 }, { -1, -1 } } }, - /* Other tests. */ - { "a(.*)b", "a b", REG_EXTENDED, 2, { { 0, 3 }, { 1, 2 } } }, - { ".*|\\([KIO]\\)\\([^|]*\\).*|?[KIO]", "10~.~|P|K0|I10|O16|?KSb", 0, 3, - { { 0, 21 }, { 15, 16 }, { 16, 18 } } }, - { ".*|\\([KIO]\\)\\([^|]*\\).*|?\\1", "10~.~|P|K0|I10|O16|?KSb", 0, 3, - { { 0, 21 }, { 8, 9 }, { 9, 10 } } }, - { "^\\(a*\\)\\1\\{9\\}\\(a\\{0,9\\}\\)\\([0-9]*;.*[^a]\\2\\([0-9]\\)\\)", - "a1;;0a1aa2aaa3aaaa4aaaaa5aaaaaa6aaaaaaa7aaaaaaaa8aaaaaaaaa9aa2aa1a0", 0, - 5, { { 0, 67 }, { 0, 0 }, { 0, 1 }, { 1, 67 }, { 66, 67 } } }, - /* Test for BRE expression anchoring. POSIX says just that this may match; - in glibc regex it always matched, so avoid changing it. */ - { "\\(^\\|foo\\)bar", "bar", 0, 2, { { 0, 3 }, { -1, -1 } } }, - { "\\(foo\\|^\\)bar", "bar", 0, 2, { { 0, 3 }, { -1, -1 } } }, - /* In ERE this must be treated as an anchor. */ - { "(^|foo)bar", "bar", REG_EXTENDED, 2, { { 0, 3 }, { -1, -1 } } }, - { "(foo|^)bar", "bar", REG_EXTENDED, 2, { { 0, 3 }, { -1, -1 } } }, - /* Here ^ cannot be treated as an anchor according to POSIX. */ - { "(^|foo)bar", "(^|foo)bar", 0, 2, { { 0, 10 }, { -1, -1 } } }, - { "(foo|^)bar", "(foo|^)bar", 0, 2, { { 0, 10 }, { -1, -1 } } }, - /* More tests on backreferences. */ - { "()\\1", "x", REG_EXTENDED, 2, { { 0, 0 }, { 0, 0 } } }, - { "()x\\1", "x", REG_EXTENDED, 2, { { 0, 1 }, { 0, 0 } } }, - { "()\\1*\\1*", "", REG_EXTENDED, 2, { { 0, 0 }, { 0, 0 } } }, - { "([0-9]).*\\1(a*)", "7;7a6", REG_EXTENDED, 3, { { 0, 4 }, { 0, 1 }, { 3, 4 } } }, - { "([0-9]).*\\1(a*)", "7;7a", REG_EXTENDED, 3, { { 0, 4 }, { 0, 1 }, { 3, 4 } } }, - { "(b)()c\\1", "bcb", REG_EXTENDED, 3, { { 0, 3 }, { 0, 1 }, { 1, 1 } } }, - { "()(b)c\\2", "bcb", REG_EXTENDED, 3, { { 0, 3 }, { 0, 0 }, { 0, 1 } } }, - { "a(b)()c\\1", "abcb", REG_EXTENDED, 3, { { 0, 4 }, { 1, 2 }, { 2, 2 } } }, - { "a()(b)c\\2", "abcb", REG_EXTENDED, 3, { { 0, 4 }, { 1, 1 }, { 1, 2 } } }, - { "()(b)\\1c\\2", "bcb", REG_EXTENDED, 3, { { 0, 3 }, { 0, 0 }, { 0, 1 } } }, - { "(b())\\2\\1", "bbbb", REG_EXTENDED, 3, { { 0, 2 }, { 0, 1 }, { 1, 1 } } }, - { "a()(b)\\1c\\2", "abcb", REG_EXTENDED, 3, { { 0, 4 }, { 1, 1 }, { 1, 2 } } }, - { "a()d(b)\\1c\\2", "adbcb", REG_EXTENDED, 3, { { 0, 5 }, { 1, 1 }, { 2, 3 } } }, - { "a(b())\\2\\1", "abbbb", REG_EXTENDED, 3, { { 0, 3 }, { 1, 2 }, { 2, 2 } } }, - { "(bb())\\2\\1", "bbbb", REG_EXTENDED, 3, { { 0, 4 }, { 0, 2 }, { 2, 2 } } }, - { "^(.?)(.?)(.?)(.?)(.?).?\\5\\4\\3\\2\\1$", - "level", REG_NOSUB | REG_EXTENDED, 0, { { -1, -1 } } }, - { "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$|^.?$", - "level", REG_NOSUB | REG_EXTENDED, 0, { { -1, -1 } } }, - { "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$|^.?$", - "abcdedcba", REG_EXTENDED, 1, { { 0, 9 } } }, -#if 0 - /* XXX Not used since they fail so far. */ - { "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$|^.?$", - "ababababa", REG_EXTENDED, 1, { { 0, 9 } } }, - { "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$", - "level", REG_NOSUB | REG_EXTENDED, 0, { { -1, -1 } } }, - { "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$", - "ababababa", REG_EXTENDED, 1, { { 0, 9 } } }, -#endif -}; - -int -main (void) -{ - regex_t re; - regmatch_t rm[5]; - size_t i; - int n, ret = 0; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) - { - n = regcomp (&re, tests[i].pattern, tests[i].flags); - if (n != 0) - { - char buf[500]; - regerror (n, &re, buf, sizeof (buf)); - printf ("%s: regcomp %lu failed: %s\n", tests[i].pattern, i, buf); - ret = 1; - continue; - } - - if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0)) - { - printf ("%s: regexec %lu failed\n", tests[i].pattern, i); - ret = 1; - regfree (&re); - continue; - } - - for (n = 0; n < tests[i].nmatch; ++n) - if (rm[n].rm_so != tests[i].rm[n].rm_so - || rm[n].rm_eo != tests[i].rm[n].rm_eo) - { - if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1) - break; - printf ("%s: regexec %lu match failure rm[%d] %d..%d\n", - tests[i].pattern, i, n, rm[n].rm_so, rm[n].rm_eo); - ret = 1; - break; - } - - regfree (&re); - } - - return ret; -} diff --git a/testsuite/bug-regex12.c b/testsuite/bug-regex12.c deleted file mode 100644 index 72e302c..0000000 --- a/testsuite/bug-regex12.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Regular expression tests. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> - -/* Tests supposed to not match. */ -struct -{ - const char *pattern; - const char *string; - int flags, nmatch; -} tests[] = { - { "^<\\([^~]*\\)\\([^~]\\)[^~]*~\\1\\(.\\).*|=.*\\3.*\\2", - "<,.8~2,~so-|=-~.0,123456789<><", REG_NOSUB, 0 }, - /* In ERE, all carets must be treated as anchors. */ - { "a^b", "a^b", REG_EXTENDED, 0 } -}; - -int -main (void) -{ - regex_t re; - regmatch_t rm[4]; - size_t i; - int n, ret = 0; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) - { - n = regcomp (&re, tests[i].pattern, tests[i].flags); - if (n != 0) - { - char buf[500]; - regerror (n, &re, buf, sizeof (buf)); - printf ("regcomp %lu failed: %s\n", i, buf); - ret = 1; - continue; - } - - if (! regexec (&re, tests[i].string, tests[i].nmatch, - tests[i].nmatch ? rm : NULL, 0)) - { - printf ("regexec %lu incorrectly matched\n", i); - ret = 1; - } - - regfree (&re); - } - - return ret; -} diff --git a/testsuite/bug-regex13.c b/testsuite/bug-regex13.c deleted file mode 100644 index 9a14b66..0000000 --- a/testsuite/bug-regex13.c +++ /dev/null @@ -1,109 +0,0 @@ -/* Regular expression tests. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static struct -{ - int syntax; - const char *pattern; - const char *string; - int start; -} tests[] = { - {RE_BACKSLASH_ESCAPE_IN_LISTS, "[0\\-9]", "1", -1}, /* It should not match. */ - {RE_BACKSLASH_ESCAPE_IN_LISTS, "[0\\-9]", "-", 0}, /* It should match. */ - {RE_SYNTAX_POSIX_BASIC, "s1\n.*\ns3", "s1\ns2\ns3", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}c", "ac", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}c", "abc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}c", "abbc", -1}, - /* Nested duplication. */ - {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{1}c", "ac", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{1}c", "abc", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{1}c", "abbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "ac", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "abbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "abbbbc", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "abbbbbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}{1}c", "ac", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}{1}c", "abc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}{1}c", "abbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{0}c", "ac", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{0}c", "abc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{0}c", "abbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}*c", "ac", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}*c", "abc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}*c", "abbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}?c", "ac", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}?c", "abc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}?c", "abbc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}+c", "ac", 0}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}+c", "abc", -1}, - {RE_SYNTAX_POSIX_EXTENDED, "ab{0}+c", "abbc", -1}, -}; - -int -main (void) -{ - struct re_pattern_buffer regbuf; - const char *err; - size_t i; - int ret = 0; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) - { - int start; - re_set_syntax (tests[i].syntax); - memset (®buf, '\0', sizeof (regbuf)); - err = re_compile_pattern (tests[i].pattern, strlen (tests[i].pattern), - ®buf); - if (err != NULL) - { - printf ("re_compile_pattern failed: %s\n", err); - ret = 1; - continue; - } - - start = re_search (®buf, tests[i].string, strlen (tests[i].string), - 0, strlen (tests[i].string), NULL); - if (start != tests[i].start) - { - printf ("re_search failed %d\n", start); - ret = 1; - regfree (®buf); - continue; - } - regfree (®buf); - } - - return ret; -} diff --git a/testsuite/bug-regex14.c b/testsuite/bug-regex14.c deleted file mode 100644 index e304fbc..0000000 --- a/testsuite/bug-regex14.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Tests re_comp and re_exec. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#define _REGEX_RE_COMP -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> - -int -main (void) -{ - const char *err; - size_t i; - int ret = 0; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - for (i = 0; i < 100; ++i) - { - err = re_comp ("a t.st"); - if (err) - { - printf ("re_comp failed: %s\n", err); - ret = 1; - } - - if (! re_exec ("This is a test.")) - { - printf ("re_exec failed\n"); - ret = 1; - } - } - - return ret; -} diff --git a/testsuite/bug-regex15.c b/testsuite/bug-regex15.c deleted file mode 100644 index 4d348a4..0000000 --- a/testsuite/bug-regex15.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Test for memory/CPU leak in regcomp. */ - -#include <config.h> - -#include <sys/types.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> - -#define TEST_DATA_LIMIT (32 << 20) - -int -main () -{ -#ifdef RLIMIT_DATA - regex_t re; - int reerr; - - /* Try to avoid eating all memory if a test leaks. */ - struct rlimit data_limit; - if (getrlimit (RLIMIT_DATA, &data_limit) == 0) - { - if ((rlim_t) TEST_DATA_LIMIT > data_limit.rlim_max) - data_limit.rlim_cur = data_limit.rlim_max; - else if (data_limit.rlim_cur > (rlim_t) TEST_DATA_LIMIT) - data_limit.rlim_cur = (rlim_t) TEST_DATA_LIMIT; - if (setrlimit (RLIMIT_DATA, &data_limit) < 0) - perror ("setrlimit: RLIMIT_DATA"); - } - else - perror ("getrlimit: RLIMIT_DATA"); - - reerr = regcomp (&re, "^6?3?[25]?5?[14]*[25]*[69]*+[58]*87?4?$", - REG_EXTENDED | REG_NOSUB); - if (reerr != 0) - { - char buf[100]; - regerror (reerr, &re, buf, sizeof buf); - printf ("regerror %s\n", buf); - return 1; - } - - return 0; -#else - return 77; -#endif -} diff --git a/testsuite/bug-regex16.c b/testsuite/bug-regex16.c deleted file mode 100644 index c767f42..0000000 --- a/testsuite/bug-regex16.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Test re_compile_pattern error messages. */ - -#include <config.h> - -#include <stdio.h> -#include <string.h> -#include <regex.h> - -int -main (void) -{ - struct re_pattern_buffer re; - const char *s; - int ret = 0; - - re_set_syntax (RE_SYNTAX_POSIX_EGREP); - memset (&re, 0, sizeof (re)); - s = re_compile_pattern ("[[.invalid_collating_symbol.]]", 30, &re); - if (s == NULL || strcmp (s, "Invalid collation character")) - { - printf ("re_compile_pattern returned %s\n", s); - ret = 1; - } - s = re_compile_pattern ("[[=invalid_equivalence_class=]]", 31, &re); - if (s == NULL || strcmp (s, "Invalid collation character")) - { - printf ("re_compile_pattern returned %s\n", s); - ret = 1; - } - s = re_compile_pattern ("[[:invalid_character_class:]]", 29, &re); - if (s == NULL || strcmp (s, "Invalid character class name")) - { - printf ("re_compile_pattern returned %s\n", s); - ret = 1; - } - return ret; -} diff --git a/testsuite/bug-regex21.c b/testsuite/bug-regex21.c deleted file mode 100644 index eaff92b..0000000 --- a/testsuite/bug-regex21.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Test for memory leaks in regcomp. - Copyright (C) 2003-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> - -int main (void) -{ - regex_t re; - int i; - int ret = 0; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - for (i = 0; i < 32; ++i) - { - if (regcomp (&re, "X-.+:.+Y=\".*\\.(A|B|C|D|E|F|G|H|I", - REG_EXTENDED | REG_ICASE) == 0) - { - puts ("regcomp unexpectedly succeeded"); - ret = 1; - } - else - regfree (&re); - } - return ret; -} diff --git a/testsuite/bug-regex27.c b/testsuite/bug-regex27.c deleted file mode 100644 index d6f6059..0000000 --- a/testsuite/bug-regex27.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Test REG_NEWLINE. - Copyright (C) 2007-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2007. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <config.h> -#include <regex.h> -#include <stdio.h> -#include <string.h> - -struct tests -{ - const char *regex; - const char *string; - int cflags; - int retval; -} tests[] = { - { "a.b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH }, - { "a.b", "a\nb", REG_EXTENDED, 0 }, - { "a[^x]b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH }, - { "a[^x]b", "a\nb", REG_EXTENDED, 0 } -}; - -int -main (void) -{ - regex_t r; - size_t i; - int ret = 0; - - for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i) - { - memset (&r, 0, sizeof (r)); - if (regcomp (&r, tests[i].regex, tests[i].cflags)) - { - printf ("regcomp %lu failed\n", i); - ret = 1; - continue; - } - int rv = regexec (&r, tests[i].string, 0, NULL, 0); - if (rv != tests[i].retval) - { - printf ("regexec %lu unexpected value %d != %d\n", - i, rv, tests[i].retval); - ret = 1; - } - regfree (&r); - } - return ret; -} diff --git a/testsuite/bug-regex28.c b/testsuite/bug-regex28.c deleted file mode 100644 index 3a4dbec..0000000 --- a/testsuite/bug-regex28.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Test RE_HAT_LISTS_NOT_NEWLINE and RE_DOT_NEWLINE. - Copyright (C) 2007-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2007. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <config.h> -#include <regex.h> -#include <stdio.h> -#include <string.h> - -struct tests -{ - const char *regex; - const char *string; - reg_syntax_t syntax; - int retval; -} tests[] = { -#define EGREP RE_SYNTAX_EGREP -#define EGREP_NL (RE_SYNTAX_EGREP | RE_DOT_NEWLINE) & ~RE_HAT_LISTS_NOT_NEWLINE - { "a.b", "a\nb", EGREP, -1 }, - { "a.b", "a\nb", EGREP_NL, 0 }, - { "a[^x]b", "a\nb", EGREP, -1 }, - { "a[^x]b", "a\nb", EGREP_NL, 0 }, - /* While \S and \W are internally handled as [^[:space:]] and [^[:alnum:]_], - RE_HAT_LISTS_NOT_NEWLINE did not make any difference, so ensure - it doesn't change. */ - { "a\\Sb", "a\nb", EGREP, -1 }, - { "a\\Sb", "a\nb", EGREP_NL, -1 }, - { "a\\Wb", "a\nb", EGREP, 0 }, - { "a\\Wb", "a\nb", EGREP_NL, 0 } -}; - -int -main (void) -{ - struct re_pattern_buffer r; - size_t i; - int ret = 0; - - for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i) - { - re_set_syntax (tests[i].syntax); - memset (&r, 0, sizeof (r)); - if (re_compile_pattern (tests[i].regex, strlen (tests[i].regex), &r)) - { - printf ("re_compile_pattern %lu failed\n", i); - ret = 1; - continue; - } - size_t len = strlen (tests[i].string); - int rv = re_search (&r, tests[i].string, len, 0, len, NULL); - if (rv != tests[i].retval) - { - printf ("re_search %lu unexpected value %d != %d\n", - i, rv, tests[i].retval); - ret = 1; - } - regfree (&r); - } - return ret; -} diff --git a/testsuite/bug-regex7.c b/testsuite/bug-regex7.c deleted file mode 100644 index 7a99dfc..0000000 --- a/testsuite/bug-regex7.c +++ /dev/null @@ -1,94 +0,0 @@ -/* Test for regs allocation in re_search and re_match. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Stepan Kasal <kasal@math.cas.cz>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <locale.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <regex.h> - - -int -main (void) -{ - struct re_pattern_buffer regex; - struct re_registers regs; - const char *s; - int match, n; - int result = 0; - - memset (®ex, '\0', sizeof (regex)); - regs.start = regs.end = NULL; - regs.num_regs = 0; - s = re_compile_pattern ("a", 1, ®ex); - if (s != NULL) - { - puts ("failed to compile pattern \"a\""); - result = 1; - } - else - { - match = re_search (®ex, "baobab", 6, 0, 6, ®s); - n = 1; - if (match != 1) - { - printf ("re_search returned %d, expected 1\n", match); - result = 1; - } - else if (regs.num_regs <= n || regs.start[n] != -1 || regs.end[n] != -1) - { - puts ("re_search failed to fill the -1 sentinel"); - result = 1; - } - } - - free (regex.buffer); - memset (®ex, '\0', sizeof (regex)); - - s = re_compile_pattern ("\\(\\(\\(a\\)\\)\\)", 13, ®ex); - if (s != NULL) - { - puts ("failed to compile pattern /\\(\\(\\(a\\)\\)\\)/"); - result = 1; - } - else - { - match = re_match (®ex, "apl", 3, 0, ®s); - n = 4; - if (match != 1) - { - printf ("re_match returned %d, expected 1\n", match); - result = 1; - } - else if (regs.num_regs <= n || regs.start[n] != -1 || regs.end[n] != -1) - { - puts ("re_match failed to fill the -1 sentinel"); - result = 1; - } - } - - if (result == 0) - puts (" -> OK"); - - return result; -} diff --git a/testsuite/bug-regex8.c b/testsuite/bug-regex8.c deleted file mode 100644 index f30341d..0000000 --- a/testsuite/bug-regex8.c +++ /dev/null @@ -1,86 +0,0 @@ -/* Test for the STOP parameter of re_match_2 and re_search_2. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Stepan Kasal <kasal@math.cas.cz>, 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <locale.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <regex.h> - - -int -main (void) -{ - struct re_pattern_buffer regex; - const char *s; - int match[4]; - - memset (®ex, '\0', sizeof (regex)); - - s = re_compile_pattern ("xy$", 3, ®ex); - if (s != NULL) - { - puts ("failed to compile pattern \"xy$\""); - return 1; - } - else - match[0] = re_match_2(®ex,"xyz",3,NULL,0,0,NULL,2); - - free (regex.buffer); - memset (®ex, '\0', sizeof (regex)); - - s = re_compile_pattern ("xy\\>", 4, ®ex); - if (s != NULL) - { - puts ("failed to compile pattern \"xy\\>\""); - return 1; - } - else - match[1] = re_search_2(®ex,"xyz",3,NULL,0,0,2,NULL,2); - - free (regex.buffer); - memset (®ex, '\0', sizeof (regex)); - - s = re_compile_pattern ("xy \\<", 5, ®ex); - if (s != NULL) - { - puts ("failed to compile pattern \"xy \\<\""); - return 1; - } - else - { - match[2] = re_match_2(®ex,"xy ",4,NULL,0,0,NULL,3); - match[3] = re_match_2(®ex,"xy z",4,NULL,0,0,NULL,3); - } - - if (match[0] != -1 || match[1] != -1 || match[2] != -1 || match[3] != 3) - { - printf ("re_{match,search}_2 returned %d,%d,%d,%d, expected -1,-1,-1,3\n", - match[0], match[1], match[2], match[3]); - return 1; - } - - puts (" -> OK"); - - return 0; -} diff --git a/testsuite/bug-regex9.c b/testsuite/bug-regex9.c deleted file mode 100644 index 7895215..0000000 --- a/testsuite/bug-regex9.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Test for memory handling in regex. - Copyright (C) 2002-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> - - -static const char text[] = "#! /bin/sh"; - -int -main (void) -{ - regex_t re; - regmatch_t rm[2]; - int n; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - n = regcomp (&re, "^#! */.*/(k|ba||pdk|z)sh", REG_EXTENDED); - if (n != 0) - { - char buf[500]; - regerror (n, &re, buf, sizeof (buf)); - printf ("regcomp failed: %s\n", buf); - exit (1); - } - - for (n = 0; n < 20; ++n) - { - if (regexec (&re, text, 2, rm, 0)) - { - puts ("regexec failed"); - exit (2); - } - if (rm[0].rm_so != 0 || rm[0].rm_eo != 10 - || rm[1].rm_so != 8 || rm[1].rm_eo != 8) - { - printf ("regexec match failure: %d %d %d %d\n", - rm[0].rm_so, rm[0].rm_eo, rm[1].rm_so, rm[1].rm_eo); - exit (3); - } - } - - regfree (&re); - - return 0; -} diff --git a/testsuite/local.mk b/testsuite/local.mk index 8a3cbd7..e30f445 100644 --- a/testsuite/local.mk +++ b/testsuite/local.mk @@ -113,16 +113,6 @@ check_PROGRAMS = testsuite/get-mb-cur-max testsuite/test-mbrtowc testsuite_get_mb_cur_max_LDADD = lib/libsed.a $(INTLLIBS) testsuite_test_mbrtowc_LDADD = lib/libsed.a $(INTLLIBS) -if TEST_REGEX -check_PROGRAMS += testsuite/bug-regex7 \ - testsuite/bug-regex8 testsuite/bug-regex9 testsuite/bug-regex10 \ - testsuite/bug-regex11 testsuite/bug-regex12 testsuite/bug-regex13 \ - testsuite/bug-regex14 testsuite/bug-regex15 testsuite/bug-regex16 \ - testsuite/bug-regex21 testsuite/bug-regex27 testsuite/bug-regex28 \ - testsuite/tst-pcre testsuite/tst-boost testsuite/runtests \ - testsuite/runptests testsuite/tst-rxspencer testsuite/tst-regex2 -endif - # Note that the first lines are statements. They ensure that environment # variables that can perturb tests are unset or set to expected values. # The rest are envvar settings that propagate build-related Makefile diff --git a/testsuite/runptests.c b/testsuite/runptests.c deleted file mode 100644 index bd28a62..0000000 --- a/testsuite/runptests.c +++ /dev/null @@ -1,125 +0,0 @@ -/* POSIX regex testsuite from IEEE 2003.2. - Copyright (C) 1998-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#include <regex.h> -#include <stdio.h> -#include <string.h> - -/* Data structure to describe the tests. */ -struct test -{ - int start; - int end; - const char *reg; - const char *str; - int options; -} tests[] = -{ -#include "ptestcases.h" -}; - - -int -main (int argc, char *argv[]) -{ - size_t cnt; - int errors = 0; - - for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt) - if (tests[cnt].str == NULL) - { - printf ("\n%s\n%.*s\n", tests[cnt].reg, - (int) strlen (tests[cnt].reg), - "-----------------------------------------------------"); - } - else if (tests[cnt].reg == NULL) - printf ("!!! %s\n", tests[cnt].str); - else - { - regex_t re; - regmatch_t match[20]; - int err; - - printf ("regexp: \"%s\", string: \"%s\" -> ", tests[cnt].reg, - tests[cnt].str); - - /* Compile the expression. */ - err = regcomp (&re, tests[cnt].reg, tests[cnt].options); - if (err != 0) - { - if (tests[cnt].start == -2) - puts ("compiling failed, OK"); - else - { - char buf[100]; - regerror (err, &re, buf, sizeof (buf)); - printf ("FAIL: %s\n", buf); - ++errors; - } - - continue; - } - else if (tests[cnt].start == -2) - { - puts ("compiling succeeds, FAIL"); - errors++; - continue; - } - - /* Run the actual test. */ - err = regexec (&re, tests[cnt].str, 20, match, 0); - - if (err != 0) - { - if (tests[cnt].start == -1) - puts ("no match, OK"); - else - { - puts ("no match, FAIL"); - ++errors; - } - } - else - { - if (match[0].rm_so == 0 && tests[cnt].start == 0 - && match[0].rm_eo == 0 && tests[cnt].end == 0) - puts ("match, OK"); - else if (match[0].rm_so + 1 == tests[cnt].start - && match[0].rm_eo == tests[cnt].end) - puts ("match, OK"); - else - { - printf ("wrong match (%d to %d): FAIL\n", - match[0].rm_so, match[0].rm_eo); - ++errors; - } - } - - /* Free all resources. */ - regfree (&re); - } - - printf ("\n%u tests, %d errors\n", (int) cnt, errors); - - return errors != 0; -} diff --git a/testsuite/runtests.c b/testsuite/runtests.c deleted file mode 100644 index 1c02c68..0000000 --- a/testsuite/runtests.c +++ /dev/null @@ -1,140 +0,0 @@ -/*********************************************************** - -Copyright 1995 by Tom Lord - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of the copyright holder not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -Tom Lord DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -EVENT SHALL TOM LORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -#include <config.h> - -#include <sys/types.h> -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -struct a_test -{ - int expected; - const char * pattern; - const unsigned char * data; -}; - -static const struct a_test the_tests[] = -{ -#include "testcases.h" - {-1, 0, 0} -}; - - - - -static int -run_a_test (int id, const struct a_test * t) -{ - static const char * last_pattern = 0; - static regex_t r; - int err; - char errmsg[100]; - int x; - regmatch_t regs[10]; - - if (!last_pattern || strcmp (last_pattern, t->pattern)) - { - if (last_pattern) - regfree (&r); - last_pattern = t->pattern; - err = regcomp (&r, t->pattern, REG_EXTENDED); - if (err) - { - if (t->expected == 2) - { - puts (" OK."); - return 0; - } - if (last_pattern) - regfree (&r); - last_pattern = NULL; - regerror (err, &r, errmsg, 100); - printf (" FAIL: %s.\n", errmsg); - return 1; - } - else if (t->expected == 2) - { - printf ("test %d\n", id); - printf ("pattern \"%s\" successful compilation not expected\n", - t->pattern); - return 1; - } - } - - for (x = 0; x < 10; ++x) - regs[x].rm_so = regs[x].rm_eo = -1; - - err = regexec (&r, t->data, 10, regs, 0); - - if (err != t->expected) - { - printf ("test %d\n", id); - printf ("pattern \"%s\" data \"%s\" wanted %d got %d\n", - t->pattern, t->data, t->expected, err); - for (x = 0; x < 10; ++x) - if (regs[x].rm_so != -1) - printf ("reg %d == (%d, %d) %.*s\n", - x, - regs[x].rm_so, - regs[x].rm_eo, - regs[x].rm_eo - regs[x].rm_so, - t->data + regs[x].rm_so); - return 1; - } - puts (" OK."); - return 0; -} - - - -int -main (int argc, char * argv[]) -{ - int x; - int lo; - int hi; - int res = 0; - - lo = 0; - hi = (sizeof (the_tests) / sizeof (the_tests[0])) - 1; - - if (argc > 1) - { - lo = atoi (argv[1]); - hi = lo + 1; - - if (argc > 2) - hi = atoi (argv[2]); - } - - for (x = lo; x < hi; ++x) - { - printf ("#%d:", x); - res |= run_a_test (x, &the_tests[x]); - } - return res != 0; -} diff --git a/testsuite/tst-boost.c b/testsuite/tst-boost.c deleted file mode 100644 index 8227deb..0000000 --- a/testsuite/tst-boost.c +++ /dev/null @@ -1,233 +0,0 @@ -/* Regular expression tests. - Copyright (C) 2003-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -void -frob_escapes (char *src, int pattern) -{ - char *dst; - - for (dst = src; *src != '\0'; dst++, src++) - { - if (*src == '\\') - { - switch (src[1]) - { - case 't': - src++; - *dst = '\t'; - continue; - case 'n': - src++; - *dst = '\n'; - continue; - case 'r': - src++; - *dst = '\r'; - continue; - case '\\': - case '^': - case '{': - case '|': - case '}': - if (!pattern) - { - src++; - *dst = *src; - continue; - } - break; - } - } - if (src != dst) - *dst = *src; - } - *dst = '\0'; -} - -int -main (int argc, char **argv) -{ - int ret = 0, n; - char *line = NULL; - size_t line_len = 0; - ssize_t len; - FILE *f; - char *pattern, *string; - int flags = REG_EXTENDED; - int eflags = 0; - regex_t re; - regmatch_t rm[20]; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - if (argc < 2) - { - fprintf (stderr, "Missing test filename\n"); - return 1; - } - - f = fopen (argv[1], "r"); - if (f == NULL) - { - fprintf (stderr, "Couldn't open %s\n", argv[1]); - return 1; - } - - while ((len = getline (&line, &line_len, f)) > 0) - { - char *p, *q; - int i; - - if (line[len - 1] == '\n') - line[--len] = '\0'; - - puts (line); - - if (line[0] == ';') - continue; - - if (line[0] == '\0') - continue; - - if (line[0] == '-') - { - if (strstr (line, "REG_BASIC")) - flags = 0; - else - flags = REG_EXTENDED; - if (strstr (line, "REG_ICASE")) - flags |= REG_ICASE; - if (strstr (line, "REG_NEWLINE")) - flags |= REG_NEWLINE; - eflags = 0; - if (strstr (line, "REG_NOTBOL")) - eflags |= REG_NOTBOL; - if (strstr (line, "REG_NOTEOL")) - eflags |= REG_NOTEOL; - continue; - } - - pattern = line + strspn (line, " \t"); - if (*pattern == '\0') - continue; - p = pattern + strcspn (pattern, " \t"); - if (*p == '\0') - continue; - *p++ = '\0'; - - string = p + strspn (p, " \t"); - if (*string == '\0') - continue; - if (*string == '"') - { - string++; - p = strchr (string, '"'); - if (p == NULL) - continue; - *p++ = '\0'; - } - else - { - p = string + strcspn (string, " \t"); - if (*string == '!') - string = NULL; - else if (*p == '\0') - continue; - else - *p++ = '\0'; - } - - frob_escapes (pattern, 1); - if (string != NULL) - frob_escapes (string, 0); - - n = regcomp (&re, pattern, flags); - if (n != 0) - { - if (string != NULL) - { - char buf[500]; - regerror (n, &re, buf, sizeof (buf)); - printf ("FAIL regcomp unexpectedly failed: %s\n", - buf); - ret = 1; - } - continue; - } - else if (string == NULL) - { - regfree (&re); - puts ("FAIL regcomp unpexpectedly succeeded"); - ret = 1; - continue; - } - - if (regexec (&re, string, 20, rm, eflags)) - { - for (i = 0; i < 20; ++i) - { - rm[i].rm_so = -1; - rm[i].rm_eo = -1; - } - } - - regfree (&re); - - for (i = 0; i < 20 && *p != '\0'; ++i) - { - int rm_so, rm_eo; - - rm_so = strtol (p, &q, 10); - if (p == q) - break; - p = q; - - rm_eo = strtol (p, &q, 10); - if (p == q) - break; - p = q; - - if (rm[i].rm_so != rm_so || rm[i].rm_eo != rm_eo) - { - printf ("FAIL rm[%d] %d..%d != expected %d..%d\n", - i, rm[i].rm_so, rm[i].rm_eo, rm_so, rm_eo); - ret = 1; - break; - } - } - } - - free (line); - fclose (f); - return ret; -} diff --git a/testsuite/tst-pcre.c b/testsuite/tst-pcre.c deleted file mode 100644 index ebc9ebb..0000000 --- a/testsuite/tst-pcre.c +++ /dev/null @@ -1,247 +0,0 @@ -/* Regular expression tests. - Copyright (C) 2003-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int -main (int argc, char **argv) -{ - int ret = 0; - char *line = NULL; - size_t line_len = 0; - ssize_t len; - FILE *f; - char *pattern = NULL, *string = NULL; - regmatch_t rm[20]; - size_t pattern_alloced = 0, string_alloced = 0; - int ignorecase = 0; - int pattern_valid = 0, rm_valid = 0; - size_t linenum; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - if (argc < 2) - { - fprintf (stderr, "Missing test filename\n"); - return 1; - } - - f = fopen (argv[1], "r"); - if (f == NULL) - { - fprintf (stderr, "Couldn't open %s\n", argv[1]); - return 1; - } - - if ((len = getline (&line, &line_len, f)) <= 0 - || strncmp (line, "# PCRE", 6) != 0) - { - fprintf (stderr, "Not a PCRE test file\n"); - fclose (f); - free (line); - return 1; - } - - linenum = 1; - - while ((len = getline (&line, &line_len, f)) > 0) - { - char *p; - unsigned long num; - - ++linenum; - - if (line[len - 1] == '\n') - line[--len] = '\0'; - - if (line[0] == '#') - continue; - - if (line[0] == '\0') - { - /* End of test. */ - ignorecase = 0; - pattern_valid = 0; - rm_valid = 0; - continue; - } - - if (line[0] == '/') - { - /* Pattern. */ - p = strrchr (line + 1, '/'); - - pattern_valid = 0; - rm_valid = 0; - if (p == NULL) - { - printf ("%lu: Invalid pattern line: %s\n", linenum, line); - ret = 1; - continue; - } - - if (p[1] == 'i' && p[2] == '\0') - ignorecase = 1; - else if (p[1] != '\0') - { - printf ("%lu: Invalid pattern line: %s\n", linenum, line); - ret = 1; - continue; - } - - if (pattern_alloced < (size_t) (p - line)) - { - pattern = realloc (pattern, p - line); - if (pattern == NULL) - { - printf ("%lu: Cannot record pattern: %m\n", linenum); - ret = 1; - break; - } - pattern_alloced = p - line; - } - - memcpy (pattern, line + 1, p - line - 1); - pattern[p - line - 1] = '\0'; - pattern_valid = 1; - continue; - } - - if (strncmp (line, " ", 4) == 0) - { - regex_t re; - int n; - - if (!pattern_valid) - { - printf ("%lu: No previous valid pattern %s\n", linenum, line); - continue; - } - - if (string_alloced < (size_t) (len - 3)) - { - string = realloc (string, len - 3); - if (string == NULL) - { - printf ("%lu: Cannot record search string: %m\n", linenum); - ret = 1; - break; - } - string_alloced = len - 3; - } - - memcpy (string, line + 4, len - 3); - - n = regcomp (&re, pattern, - REG_EXTENDED | (ignorecase ? REG_ICASE : 0)); - if (n != 0) - { - char buf[500]; - regerror (n, &re, buf, sizeof (buf)); - printf ("%lu: regcomp failed for %s: %s\n", - linenum, pattern, buf); - ret = 1; - continue; - } - - if (regexec (&re, string, 20, rm, 0)) - { - rm[0].rm_so = -1; - rm[0].rm_eo = -1; - } - - regfree (&re); - rm_valid = 1; - continue; - } - - if (!rm_valid) - { - printf ("%lu: No preceding pattern or search string\n", linenum); - ret = 1; - continue; - } - - if (strcmp (line, "No match") == 0) - { - if (rm[0].rm_so != -1 || rm[0].rm_eo != -1) - { - printf ("%lu: /%s/ on %s unexpectedly matched %d..%d\n", - linenum, pattern, string, rm[0].rm_so, rm[0].rm_eo); - ret = 1; - } - - continue; - } - - p = line; - if (*p == ' ') - ++p; - - num = strtoul (p, &p, 10); - if (num >= 20 || *p != ':' || p[1] != ' ') - { - printf ("%lu: Invalid line %s\n", linenum, line); - ret = 1; - continue; - } - - if (rm[num].rm_so == -1 || rm[num].rm_eo == -1) - { - if (strcmp (p + 2, "<unset>") != 0) - { - printf ("%lu: /%s/ on %s unexpectedly failed to match register %ld %d..%d\n", - linenum, pattern, string, num, - rm[num].rm_so, rm[num].rm_eo); - ret = 1; - } - continue; - } - - if (rm[num].rm_eo < rm[num].rm_so - || rm[num].rm_eo - rm[num].rm_so != len - (p + 2 - line) - || strncmp (p + 2, string + rm[num].rm_so, - rm[num].rm_eo - rm[num].rm_so) != 0) - { - printf ("%lu: /%s/ on %s unexpectedly failed to match %s for register %ld %d..%d\n", - linenum, pattern, string, p + 2, num, - rm[num].rm_so, rm[num].rm_eo); - ret = 1; - continue; - } - } - - free (pattern); - free (string); - free (line); - fclose (f); - return ret; -} diff --git a/testsuite/tst-regex.c b/testsuite/tst-regex.c deleted file mode 100644 index a74643d..0000000 --- a/testsuite/tst-regex.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Copyright (C) 2001-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <alloca.h> -#include <assert.h> -#include <errno.h> -#include <fcntl.h> -#include <iconv.h> -#include <locale.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <regex.h> - - -static iconv_t cd; -static char *mem; -static char *umem; -static size_t memlen; -static size_t umemlen; -static int test_expr (const char *expr, int expected, int expectedicase); -static int run_test (const char *expr, const char *mem, size_t memlen, - int icase, int expected); -static int run_test_backwards (const char *expr, const char *mem, - size_t memlen, int icase, int expected); - - -int -main (int argc, char *argv[]) -{ - int fd; - struct stat st; - int result; - char *inmem; - char *outmem; - size_t inlen; - size_t outlen; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - if (!argv[1]) - exit (1); - - /* Make the content of the file available in memory. */ - fd = open (argv[1], O_RDONLY); - if (fd == -1) - error (EXIT_FAILURE, errno, "cannot open %s", basename (argv[1])); - - if (fstat (fd, &st) != 0) - error (EXIT_FAILURE, errno, "cannot stat %s", basename (argv[1])); - memlen = st.st_size; - - mem = (char *) malloc (memlen + 1); - if (mem == NULL) - error (EXIT_FAILURE, errno, "while allocating buffer"); - - if ((size_t) read (fd, mem, memlen) != memlen) - error (EXIT_FAILURE, 0, "cannot read entire file"); - mem[memlen] = '\0'; - - close (fd); - - /* We have to convert a few things from Latin-1 to UTF-8. */ - cd = iconv_open ("UTF-8", "ISO-8859-1"); - if (cd == (iconv_t) -1) - error (EXIT_FAILURE, errno, "cannot get conversion descriptor"); - - /* For the second test we have to convert the file content to UTF-8. - Since the text is mostly ASCII it should be enough to allocate - twice as much memory for the UTF-8 text than for the Latin-1 - text. */ - umem = (char *) calloc (2, memlen); - if (umem == NULL) - error (EXIT_FAILURE, errno, "while allocating buffer"); - - inmem = mem; - inlen = memlen; - outmem = umem; - outlen = 2 * memlen - 1; - iconv (cd, &inmem, &inlen, &outmem, &outlen); - umemlen = outmem - umem; - if (inlen != 0) - error (EXIT_FAILURE, errno, "cannot convert buffer"); - -#ifdef DEBUG - re_set_syntax (RE_DEBUG); -#endif - - /* Run the actual tests. All tests are run in a single-byte and a - multi-byte locale. */ - result = test_expr ("[äáàâéèêíìîñöóòôüúùû]", 2, 2); - result |= test_expr ("G.ran", 2, 3); - result |= test_expr ("G.\\{1\\}ran", 2, 3); - result |= test_expr ("G.*ran", 3, 44); - result |= test_expr ("[äáàâ]", 0, 0); - result |= test_expr ("Uddeborg", 2, 2); - result |= test_expr (".Uddeborg", 2, 2); - - /* Free the resources. */ - free (umem); - iconv_close (cd); - free (mem); - - return result; -} - - -static int -test_expr (const char *expr, int expected, int expectedicase) -{ - int result; - printf ("\nTest \"%s\" with 8-bit locale\n", expr); - result = run_test (expr, mem, memlen, 0, expected); - printf ("\nTest \"%s\" with 8-bit locale, case insensitive\n", expr); - result |= run_test (expr, mem, memlen, 1, expectedicase); - printf ("\nTest \"%s\" backwards with 8-bit locale\n", expr); - result |= run_test_backwards (expr, mem, memlen, 0, expected); - printf ("\nTest \"%s\" backwards with 8-bit locale, case insensitive\n", - expr); - result |= run_test_backwards (expr, mem, memlen, 1, expectedicase); - return result; -} - - -static int -run_test (const char *expr, const char *mem, size_t memlen, int icase, - int expected) -{ - regex_t re; - int err; - size_t offset; - int cnt; - - err = regcomp (&re, expr, REG_NEWLINE | (icase ? REG_ICASE : 0)); - if (err != REG_NOERROR) - { - char buf[200]; - regerror (err, &re, buf, sizeof buf); - error (EXIT_FAILURE, 0, "cannot compile expression: %s", buf); - } - - cnt = 0; - offset = 0; - assert (mem[memlen] == '\0'); - while (offset < memlen) - { - regmatch_t ma[1]; - const char *sp; - const char *ep; - - err = regexec (&re, mem + offset, 1, ma, 0); - if (err == REG_NOMATCH) - break; - - if (err != REG_NOERROR) - { - char buf[200]; - regerror (err, &re, buf, sizeof buf); - error (EXIT_FAILURE, 0, "cannot use expression: %s", buf); - } - - assert (ma[0].rm_so >= 0); - sp = mem + offset + ma[0].rm_so; - while (sp > mem && sp[-1] != '\n') - --sp; - - ep = mem + offset + ma[0].rm_so; - while (*ep != '\0' && *ep != '\n') - ++ep; - - printf ("match %d: \"%.*s\"\n", ++cnt, (int) (ep - sp), sp); - - offset = ep + 1 - mem; - } - - regfree (&re); - - /* Return an error if the number of matches found is not match we - expect. */ - return cnt != expected; -} - - -static int -run_test_backwards (const char *expr, const char *mem, size_t memlen, - int icase, int expected) -{ - regex_t re; - const char *err; - size_t offset; - int cnt; - - re_set_syntax ((RE_SYNTAX_POSIX_BASIC & ~RE_DOT_NEWLINE) - | RE_HAT_LISTS_NOT_NEWLINE - | (icase ? RE_ICASE : 0)); - - memset (&re, 0, sizeof (re)); - re.fastmap = malloc (256); - if (re.fastmap == NULL) - error (EXIT_FAILURE, errno, "cannot allocate fastmap"); - - err = re_compile_pattern (expr, strlen (expr), &re); - if (err != NULL) - error (EXIT_FAILURE, 0, "cannot compile expression: %s", err); - - if (re_compile_fastmap (&re)) - error (EXIT_FAILURE, 0, "couldn't compile fastmap"); - - cnt = 0; - offset = memlen; - assert (mem[memlen] == '\0'); - while (offset <= memlen) - { - int start; - const char *sp; - const char *ep; - - start = re_search (&re, mem, memlen, offset, -offset, NULL); - if (start == -1) - break; - - if (start == -2) - error (EXIT_FAILURE, 0, "internal error in re_search"); - - sp = mem + start; - while (sp > mem && sp[-1] != '\n') - --sp; - - ep = mem + start; - while (*ep != '\0' && *ep != '\n') - ++ep; - - printf ("match %d: \"%.*s\"\n", ++cnt, (int) (ep - sp), sp); - - offset = sp - 1 - mem; - } - - regfree (&re); - - /* Return an error if the number of matches found is not match we - expect. */ - return cnt != expected; -} diff --git a/testsuite/tst-regex2.c b/testsuite/tst-regex2.c deleted file mode 100644 index dd65bb3..0000000 --- a/testsuite/tst-regex2.c +++ /dev/null @@ -1,207 +0,0 @@ -#include <config.h> - -#include <errno.h> -#include <fcntl.h> -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> - -int -main (int argc, char *argv[]) -{ - struct stat st; - static const char *pat[] = { - ".?.?.?.?.?.?.?argc", - "(.?)(.?)(.?)(.?)(.?)(.?)(.?)argc", - "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))" - "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))" - "((((((((((.?))))))))))argc" }; - - size_t len; - int fd; - int testno, i, j, k, l; - char *string; - char *buf; - - if (argc < 2) - abort (); - - fd = open (argv[1], O_RDONLY); - if (fd < 0) - { - printf ("Couldn't open %s: %s\n", argv[1], strerror (errno)); - abort (); - } - - if (fstat (fd, &st) < 0) - { - printf ("Couldn't fstat %s: %s\n", argv[1], strerror (errno)); - abort (); - } - - buf = malloc (st.st_size + 1); - if (buf == NULL) - { - printf ("Couldn't allocate buffer: %s\n", strerror (errno)); - abort (); - } - - if (read (fd, buf, st.st_size) != (ssize_t) st.st_size) - { - printf ("Couldn't read %s", argv[1]); - abort (); - } - - close (fd); - buf[st.st_size] = '\0'; - - string = buf; - len = st.st_size; - - for (testno = 0; testno < 4; ++testno) - for (i = 0; i < sizeof (pat) / sizeof (pat[0]); ++i) - { - regex_t rbuf; - struct re_pattern_buffer rpbuf; - int err; - - printf ("test %d pattern %d", testno, i); - if (testno < 2) - { - err = regcomp (&rbuf, pat[i], - REG_EXTENDED | (testno ? REG_NOSUB : 0)); - if (err != 0) - { - char errstr[300]; - putchar ('\n'); - regerror (err, &rbuf, errstr, sizeof (errstr)); - puts (errstr); - return err; - } - } - else - { - const char *s; - re_set_syntax (RE_SYNTAX_POSIX_EGREP - | (testno == 3 ? RE_NO_SUB : 0)); - - memset (&rpbuf, 0, sizeof (rpbuf)); - s = re_compile_pattern (pat[i], strlen (pat[i]), &rpbuf); - if (s != NULL) - { - printf ("\n%s\n", s); - abort (); - } - - /* Just so that this can be tested with earlier glibc as well. */ - if (testno == 3) - rpbuf.no_sub = 1; - } - - if (testno < 2) - { - regmatch_t pmatch[71]; - err = regexec (&rbuf, string, 71, pmatch, 0); - if (err == REG_NOMATCH) - { - puts ("\nregexec failed"); - abort (); - } - - if (testno == 0) - { - if (pmatch[0].rm_eo != pmatch[0].rm_so + 11 - || pmatch[0].rm_eo > len - || string + pmatch[0].rm_so >= strchr (string, 'R') - || strncmp (string + pmatch[0].rm_so, - "n (int argc", - sizeof "n (int argc" - 1) - != 0) - { - puts ("\nregexec without REG_NOSUB did not find the correct match"); - abort (); - } - - if (i > 0) - for (j = 0, l = 1; j < 7; ++j) - for (k = 0; k < (i == 1 ? 1 : 10); ++k, ++l) - if (pmatch[l].rm_so != pmatch[0].rm_so + j - || pmatch[l].rm_eo != pmatch[l].rm_so + 1) - { - printf ("\npmatch[%d] incorrect\n", l); - abort (); - } - } - } - else - { - struct re_registers regs; - int match; - - memset (®s, 0, sizeof (regs)); - match = re_search (&rpbuf, string, len, 0, len, - ®s); - if (match < 0) - { - puts ("\nre_search failed"); - abort (); - } - - if (match + 11 > len - || string + match >= strchr (string, 'R') - || strncmp (string + match, - "n (int argc", - sizeof "n (int argc" - 1) - != 0) - { - puts ("\nre_search did not find the correct match"); - abort (); - } - - if (testno == 2) - { - if (regs.num_regs != 2 + (i == 0 ? 0 : i == 1 ? 7 : 70)) - { - printf ("\nincorrect num_regs %d\n", regs.num_regs); - abort (); - } - - if (regs.start[0] != match || regs.end[0] != match + 11) - { - printf ("\nincorrect regs.{start,end}[0] = { %d, %d}\n", - regs.start[0], regs.end[0]); - abort (); - } - - if (regs.start[regs.num_regs - 1] != -1 - || regs.end[regs.num_regs - 1] != -1) - { - puts ("\nincorrect regs.{start,end}[num_regs - 1]"); - abort (); - } - - if (i > 0) - for (j = 0, l = 1; j < 7; ++j) - for (k = 0; k < (i == 1 ? 1 : 10); ++k, ++l) - if (regs.start[l] != match + j - || regs.end[l] != regs.start[l] + 1) - { - printf ("\nregs.{start,end}[%d] incorrect\n", l); - abort (); - } - } - } - - putchar ('\n'); - - if (testno < 2) - regfree (&rbuf); - else - regfree (&rpbuf); - } - - exit (0); -} diff --git a/testsuite/tst-rxspencer.c b/testsuite/tst-rxspencer.c deleted file mode 100644 index a8785bd..0000000 --- a/testsuite/tst-rxspencer.c +++ /dev/null @@ -1,558 +0,0 @@ -/* Regular expression tests. - Copyright (C) 2003-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. */ - -#include <config.h> - -#include <sys/types.h> -#ifdef HAVE_MCHECK_H -#include <mcheck.h> -#endif -#include <regex.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <locale.h> -#include <getopt.h> - -static void -replace_special_chars (char *str) -{ - for (; (str = strpbrk (str, "NTSZ")) != NULL; ++str) - switch (*str) - { - case 'N': *str = '\n'; break; - case 'T': *str = '\t'; break; - case 'S': *str = ' '; break; - case 'Z': *str = '\0'; break; - } -} - -static void -glibc_re_syntax (char *str) -{ - char *p, *end = strchr (str, '\0') + 1; - - /* Replace [[:<:]] with \< and [[:>:]] with \>. */ - for (p = str; (p = strstr (p, "[[:")) != NULL; ) - if ((p[3] == '<' || p[3] == '>') && strncmp (p + 4, ":]]", 3) == 0) - { - p[0] = '\\'; - p[1] = p[3]; - memmove (p + 2, p + 7, end - p - 7); - end -= 5; - p += 2; - } - else - p += 3; -} - -static char * -mb_replace (char *dst, const char c) -{ - switch (c) - { - /* Replace a with \'a and A with \'A. */ - case 'a': - *dst++ = '\xc3'; - *dst++ = '\xa1'; - break; - case 'A': - *dst++ = '\xc3'; - *dst++ = '\x81'; - break; - /* Replace b with \v{c} and B with \v{C}. */ - case 'b': - *dst++ = '\xc4'; - *dst++ = '\x8d'; - break; - case 'B': - *dst++ = '\xc4'; - *dst++ = '\x8c'; - break; - /* Replace c with \v{d} and C with \v{D}. */ - case 'c': - *dst++ = '\xc4'; - *dst++ = '\x8f'; - break; - case 'C': - *dst++ = '\xc4'; - *dst++ = '\x8e'; - break; - /* Replace d with \'e and D with \'E. */ - case 'd': - *dst++ = '\xc3'; - *dst++ = '\xa9'; - break; - case 'D': - *dst++ = '\xc3'; - *dst++ = '\x89'; - break; - } - return dst; -} - -static char * -mb_frob_string (const char *str, const char *letters) -{ - char *ret, *dst; - const char *src; - - if (str == NULL) - return NULL; - - ret = malloc (2 * strlen (str) + 1); - if (ret == NULL) - return NULL; - - for (src = str, dst = ret; *src; ++src) - if (strchr (letters, *src)) - dst = mb_replace (dst, *src); - else - *dst++ = *src; - *dst = '\0'; - return ret; -} - -/* Like mb_frob_string, but don't replace anything between - [: and :], [. and .] or [= and =]. */ - -static char * -mb_frob_pattern (const char *str, const char *letters) -{ - char *ret, *dst; - const char *src; - int in_class = 0; - - if (str == NULL) - return NULL; - - ret = malloc (2 * strlen (str) + 1); - if (ret == NULL) - return NULL; - - for (src = str, dst = ret; *src; ++src) - if (!in_class && strchr (letters, *src)) - dst = mb_replace (dst, *src); - else - { - if (!in_class && *src == '[' && strchr (":.=", src[1])) - in_class = 1; - else if (in_class && *src == ']' && strchr (":.=", src[-1])) - in_class = 0; - *dst++ = *src; - } - *dst = '\0'; - return ret; -} - -static int -check_match (regmatch_t *rm, int idx, const char *string, - const char *match, const char *fail) -{ - if (match[0] == '-' && match[1] == '\0') - { - if (rm[idx].rm_so == -1 && rm[idx].rm_eo == -1) - return 0; - printf ("%s rm[%d] unexpectedly matched\n", fail, idx); - return 1; - } - - if (rm[idx].rm_so == -1 || rm[idx].rm_eo == -1) - { - printf ("%s rm[%d] unexpectedly did not match\n", fail, idx); - return 1; - } - - if (match[0] == '@') - { - if (rm[idx].rm_so != rm[idx].rm_eo) - { - printf ("%s rm[%d] not empty\n", fail, idx); - return 1; - } - - if (strncmp (string + rm[idx].rm_so, match + 1, strlen (match + 1) - ? strlen (match + 1) : 1)) - { - printf ("%s rm[%d] not matching %s\n", fail, idx, match); - return 1; - } - return 0; - } - - if (rm[idx].rm_eo - rm[idx].rm_so != strlen (match) - || strncmp (string + rm[idx].rm_so, match, - rm[idx].rm_eo - rm[idx].rm_so)) - { - printf ("%s rm[%d] not matching %s\n", fail, idx, match); - return 1; - } - - return 0; -} - -static int -test (const char *pattern, int cflags, const char *string, int eflags, - char *expect, char *matches, const char *fail) -{ - regex_t re; - regmatch_t rm[10]; - int n, ret = 0; - - n = regcomp (&re, pattern, cflags); - if (n != 0) - { - char buf[500]; - if (eflags == -1) - { - static struct { reg_errcode_t code; const char *name; } codes [] -#define C(x) { REG_##x, #x } - = { C(NOERROR), C(NOMATCH), C(BADPAT), C(ECOLLATE), - C(ECTYPE), C(EESCAPE), C(ESUBREG), C(EBRACK), - C(EPAREN), C(EBRACE), C(BADBR), C(ERANGE), - C(ESPACE), C(BADRPT) }; - - int i; - for (i = 0; i < sizeof (codes) / sizeof (codes[0]); ++i) - if (n == codes[i].code) - { - if (strcmp (string, codes[i].name)) - { - printf ("%s regcomp returned REG_%s (expected REG_%s)\n", - fail, codes[i].name, string); - return 1; - } - return 0; - } - - printf ("%s regcomp return value REG_%d\n", fail, n); - return 1; - } - - regerror (n, &re, buf, sizeof (buf)); - printf ("%s regcomp failed: %s\n", fail, buf); - return 1; - } - - if (eflags == -1) - { - regfree (&re); - - /* The test case file assumes something only guaranteed by the - rxspencer regex implementation. Namely that for empty - expressions regcomp() return REG_EMPTY. This is not the case - for us and so we ignore this error. */ - if (strcmp (string, "EMPTY") == 0) - return 0; - - printf ("%s regcomp unexpectedly succeeded\n", fail); - return 1; - } - - if (regexec (&re, string, 10, rm, eflags)) - { - regfree (&re); - if (expect == NULL) - return 0; - printf ("%s regexec failed\n", fail); - return 1; - } - - regfree (&re); - - if (expect == NULL) - { - printf ("%s regexec unexpectedly succeeded\n", fail); - return 1; - } - - if (cflags & REG_NOSUB) - return 0; - - ret = check_match (rm, 0, string, expect, fail); - if (matches == NULL) - return ret; - - for (n = 1; ret == 0 && n < 10; ++n) - { - char *p = NULL; - - if (matches) - { - p = strchr (matches, ','); - if (p != NULL) - *p = '\0'; - } - ret = check_match (rm, n, string, matches ? matches : "-", fail); - if (p) - { - *p = ','; - matches = p + 1; - } - else - matches = NULL; - } - - return ret; -} - -static int -mb_test (const char *pattern, int cflags, const char *string, int eflags, - char *expect, const char *matches, const char *letters, - const char *fail) -{ - char *pattern_mb = mb_frob_pattern (pattern, letters); - const char *string_mb - = eflags == -1 ? string : mb_frob_string (string, letters); - char *expect_mb = mb_frob_string (expect, letters); - char *matches_mb = mb_frob_string (matches, letters); - int ret = 0; - - if (!pattern_mb || !string_mb - || (expect && !expect_mb) || (matches && !matches_mb)) - { - printf ("%s %m", fail); - ret = 1; - } - else - ret = test (pattern_mb, cflags, string_mb, eflags, expect_mb, - matches_mb, fail); - - free (matches_mb); - free (expect_mb); - if (string_mb != string) - free (string_mb); - free (pattern_mb); - return ret; -} - -static int -mb_tests (const char *pattern, int cflags, const char *string, int eflags, - char *expect, const char *matches) -{ - int ret = 0; - int i; - char letters[9], fail[20]; - - /* The tests aren't supposed to work with xdigit, since a-dA-D are - hex digits while \'a \'A \v{c}\v{C}\v{d}\v{D}\'e \'E are not. */ - if (strstr (pattern, "[:xdigit:]")) - return 0; - - /* XXX: regex ATM handles only single byte equivalence classes. */ - if (strstr (pattern, "[[=b=]]")) - return 0; - - for (i = 1; i < 16; ++i) - { - char *p = letters; - if (i & 1) - { - if (!strchr (pattern, 'a') && !strchr (string, 'a') - && !strchr (pattern, 'A') && !strchr (string, 'A')) - continue; - *p++ = 'a', *p++ = 'A'; - } - if (i & 2) - { - if (!strchr (pattern, 'b') && !strchr (string, 'b') - && !strchr (pattern, 'B') && !strchr (string, 'B')) - continue; - *p++ = 'b', *p++ = 'B'; - } - if (i & 4) - { - if (!strchr (pattern, 'c') && !strchr (string, 'c') - && !strchr (pattern, 'C') && !strchr (string, 'C')) - continue; - *p++ = 'c', *p++ = 'C'; - } - if (i & 8) - { - if (!strchr (pattern, 'd') && !strchr (string, 'd') - && !strchr (pattern, 'D') && !strchr (string, 'D')) - continue; - *p++ = 'd', *p++ = 'D'; - } - *p++ = '\0'; - sprintf (fail, "UTF-8 %s FAIL", letters); - ret |= mb_test (pattern, cflags, string, eflags, expect, matches, - letters, fail); - } - return ret; -} - -int -main (int argc, char **argv) -{ - int ret = 0; - char *line = NULL; - size_t line_len = 0; - ssize_t len; - FILE *f; - static int test_utf8 = 0; - static const struct option options[] = - { - {"utf8", no_argument, &test_utf8, 1}, - {NULL, 0, NULL, 0 } - }; - -#ifdef HAVE_MCHECK_H - mtrace (); -#endif - - while (getopt_long (argc, argv, "", options, NULL) >= 0); - - if (optind + 1 != argc) - { - fprintf (stderr, "Missing test filename\n"); - return 1; - } - - f = fopen (argv[optind], "r"); - if (f == NULL) - { - fprintf (stderr, "Couldn't open %s\n", argv[optind]); - return 1; - } - - while ((len = getline (&line, &line_len, f)) > 0) - { - char *pattern, *flagstr, *string, *expect, *matches, *p; - int cflags = REG_EXTENDED, eflags = 0, try_bre_ere = 0; - - if (line[len - 1] == '\n') - line[len - 1] = '\0'; - - /* Skip comments and empty lines. */ - if (*line == '#' || *line == '\0') - continue; - - puts (line); - fflush (stdout); - - pattern = strtok (line, "\t"); - if (pattern == NULL) - continue; - - if (strcmp (pattern, "\"\"") == 0) - pattern += 2; - - flagstr = strtok (NULL, "\t"); - if (flagstr == NULL) - continue; - - string = strtok (NULL, "\t"); - if (string == NULL) - continue; - - if (strcmp (string, "\"\"") == 0) - string += 2; - - for (p = flagstr; *p; ++p) - switch (*p) - { - case '-': - break; - case 'b': - cflags &= ~REG_EXTENDED; - break; - case '&': - try_bre_ere = 1; - break; - case 'C': - eflags = -1; - break; - case 'i': - cflags |= REG_ICASE; - break; - case 's': - cflags |= REG_NOSUB; - break; - case 'n': - cflags |= REG_NEWLINE; - break; - case '^': - eflags |= REG_NOTBOL; - break; - case '$': - eflags |= REG_NOTEOL; - break; - case 'm': - case 'p': - case '#': - /* Not supported. */ - flagstr = NULL; - break; - } - - if (flagstr == NULL) - continue; - - replace_special_chars (pattern); - glibc_re_syntax (pattern); - if (eflags != -1) - replace_special_chars (string); - - expect = strtok (NULL, "\t"); - matches = NULL; - if (expect != NULL) - { - replace_special_chars (expect); - matches = strtok (NULL, "\t"); - if (matches != NULL) - replace_special_chars (matches); - } - - if (setlocale (LC_ALL, "C") == NULL) - { - puts ("setlocale C failed"); - ret = 1; - } - if (test (pattern, cflags, string, eflags, expect, matches, "FAIL") - || (try_bre_ere - && test (pattern, cflags & ~REG_EXTENDED, string, eflags, - expect, matches, "FAIL"))) - ret = 1; - else if (test_utf8) - { - if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL) - { - puts ("setlocale cs_CZ.UTF-8 failed"); - ret = 1; - } - else if (test (pattern, cflags, string, eflags, expect, matches, - "UTF-8 FAIL") - || (try_bre_ere - && test (pattern, cflags & ~REG_EXTENDED, string, - eflags, expect, matches, "UTF-8 FAIL"))) - ret = 1; - else if (mb_tests (pattern, cflags, string, eflags, expect, matches) - || (try_bre_ere - && mb_tests (pattern, cflags & ~REG_EXTENDED, string, - eflags, expect, matches))) - ret = 1; - } - } - - free (line); - fclose (f); - return ret; -} |