Update.
[glibc.git] / posix / runptests.c
blobfcea5b342aa519981a522825516e8b1f3316cf72
1 /* POSIX regex testsuite from IEEE 2003.2.
2 Copyright (C) 1998 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 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
55 regex_t re;
56 regmatch_t match[20];
57 int err;
59 printf ("regexp: \"%s\", string: \"%s\" -> ", tests[cnt].reg,
60 tests[cnt].str);
62 /* Compile the expression. */
63 err = regcomp (&re, tests[cnt].reg, tests[cnt].options);
64 if (err != 0)
66 if (tests[cnt].start == -2)
67 puts ("compiling failed, OK");
68 else
70 char buf[100];
71 regerror (err, &re, buf, sizeof (buf));
72 printf ("FAIL: %s\n", buf);
73 ++errors;
76 continue;
78 else if (tests[cnt].start == -2)
80 puts ("compiling suceeds, FAIL");
81 errors++;
82 continue;
85 /* Run the actual test. */
86 err = regexec (&re, tests[cnt].str, 20, match, 0);
88 if (err != 0)
90 if (tests[cnt].start == -1)
91 puts ("no match, OK");
92 else
94 puts ("no match, FAIL");
95 ++errors;
98 else
100 if (match[0].rm_so == 0 && tests[cnt].start == 0
101 && match[0].rm_eo == 0 && tests[cnt].end == 0)
102 puts ("match, OK");
103 else if (match[0].rm_so + 1 == tests[cnt].start
104 && match[0].rm_eo == tests[cnt].end)
105 puts ("match, OK");
106 else
108 printf ("wrong match (%d to %d): FAIL\n",
109 match[0].rm_so, match[0].rm_eo);
110 ++errors;
114 /* Free all resources. */
115 regfree (&re);
118 printf ("\n%Zu tests, %d errors\n", cnt, errors);
120 /* We should return here the error status but since some tests are known
121 to fail this would only cause the libc testsuite to fail. */
122 //return errors != 0;
123 return 0;