Augment last change.
[glibc/history.git] / posix / runptests.c
blob4d43180e4116583bf587b2b2f9e8b15b921a9b4a
1 /* POSIX regex testsuite from IEEE 2003.2.
2 Copyright (C) 1998, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <sys/types.h>
22 #include <regex.h>
23 #include <stdio.h>
24 #include <string.h>
26 /* Data structure to describe the tests. */
27 struct test
29 int start;
30 int end;
31 const char *reg;
32 const char *str;
33 int options;
34 } tests[] =
36 #include "ptestcases.h"
40 int
41 main (int argc, char *argv[])
43 size_t cnt;
44 int errors = 0;
46 for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
47 if (tests[cnt].str == NULL)
49 printf ("\n%s\n%.*s\n", tests[cnt].reg,
50 (int) strlen (tests[cnt].reg),
51 "-----------------------------------------------------");
53 else if (tests[cnt].reg == NULL)
54 printf ("!!! %s\n", tests[cnt].str);
55 else
57 regex_t re;
58 regmatch_t match[20];
59 int err;
61 printf ("regexp: \"%s\", string: \"%s\" -> ", tests[cnt].reg,
62 tests[cnt].str);
64 /* Compile the expression. */
65 err = regcomp (&re, tests[cnt].reg, tests[cnt].options);
66 if (err != 0)
68 if (tests[cnt].start == -2)
69 puts ("compiling failed, OK");
70 else
72 char buf[100];
73 regerror (err, &re, buf, sizeof (buf));
74 printf ("FAIL: %s\n", buf);
75 ++errors;
78 continue;
80 else if (tests[cnt].start == -2)
82 puts ("compiling suceeds, FAIL");
83 errors++;
84 continue;
87 /* Run the actual test. */
88 err = regexec (&re, tests[cnt].str, 20, match, 0);
90 if (err != 0)
92 if (tests[cnt].start == -1)
93 puts ("no match, OK");
94 else
96 puts ("no match, FAIL");
97 ++errors;
100 else
102 if (match[0].rm_so == 0 && tests[cnt].start == 0
103 && match[0].rm_eo == 0 && tests[cnt].end == 0)
104 puts ("match, OK");
105 else if (match[0].rm_so + 1 == tests[cnt].start
106 && match[0].rm_eo == tests[cnt].end)
107 puts ("match, OK");
108 else
110 printf ("wrong match (%d to %d): FAIL\n",
111 match[0].rm_so, match[0].rm_eo);
112 ++errors;
116 /* Free all resources. */
117 regfree (&re);
120 printf ("\n%Zu tests, %d errors\n", cnt, errors);
122 return errors != 0;