Update.
[glibc.git] / posix / runtests.c
blobb6a292e6f5b1457eea56cc2fc84aa6f865841bd8
1 /***********************************************************
3 Copyright 1995 by Tom Lord
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of the copyright holder not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 Tom Lord DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 EVENT SHALL TOM LORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
27 #include <sys/types.h>
28 #include <regex.h>
29 #include <stdio.h>
30 #include <stdlib.h>
34 struct a_test
36 int expected;
37 const char * pattern;
38 const unsigned char * data;
41 static const struct a_test the_tests[] =
43 #include "testcases.h"
44 {-1, 0, 0}
50 int
51 run_a_test (int id, const struct a_test * t)
53 static const char * last_pattern = 0;
54 static regex_t r;
55 int err;
56 char errmsg[100];
57 int x;
58 regmatch_t regs[10];
60 if (!last_pattern || strcmp (last_pattern, t->pattern))
62 if (last_pattern)
63 regfree (&r);
64 last_pattern = t->pattern;
65 err = regcomp (&r, t->pattern, REG_EXTENDED);
66 if (err)
68 if (t->expected)
70 puts (" OK.");
71 return 0;
73 regerror (err, &r, errmsg, 100);
74 printf ("test %d\n", id);
75 puts (errmsg);
76 return 1;
80 err = regexec (&r, t->data, 10, regs, 0);
82 if (err != t->expected)
84 printf ("test %d\n", id);
85 printf ("pattern \"%s\" data \"%s\" wanted %d got %d\n",
86 t->pattern, t->data, t->expected, err);
87 for (x = 0; x < 10; ++x)
88 printf ("reg %d == (%d, %d) %.*s\n",
90 regs[x].rm_so,
91 regs[x].rm_eo,
92 regs[x].rm_eo - regs[x].rm_so,
93 t->data + regs[x].rm_so);
94 return 1;
96 puts (" OK.");
97 return 0;
103 main (int argc, char * argv[])
105 int x;
106 int lo;
107 int hi;
108 int res = 0;
110 lo = 0;
111 hi = (sizeof (the_tests) / sizeof (the_tests[0])) - 1;
113 if (argc > 1)
115 lo = atoi (argv[1]);
116 hi = lo + 1;
118 if (argc > 2)
119 hi = atoi (argv[2]);
122 for (x = lo; x < hi; ++x)
124 printf ("#%d:", x);
125 res |= run_a_test (x, &the_tests[x]);
128 exit (0);