1 /***********************************************************
3 Copyright 1995 by Tom Lord
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>
42 static const struct a_test the_tests
[] =
44 #include "testcases.h"
52 run_a_test (int id
, const struct a_test
* t
)
54 static const char * last_pattern
= 0;
61 if (!last_pattern
|| strcmp (last_pattern
, t
->pattern
))
65 last_pattern
= t
->pattern
;
66 err
= regcomp (&r
, t
->pattern
, REG_EXTENDED
);
77 regerror (err
, &r
, errmsg
, 100);
78 printf (" FAIL: %s.\n", errmsg
);
81 else if (t
->expected
== 2)
83 printf ("test %d\n", id
);
84 printf ("pattern \"%s\" successful compilation not expected\n",
90 err
= regexec (&r
, t
->data
, 10, regs
, 0);
92 if (err
!= t
->expected
)
94 printf ("test %d\n", id
);
95 printf ("pattern \"%s\" data \"%s\" wanted %d got %d\n",
96 t
->pattern
, t
->data
, t
->expected
, err
);
97 for (x
= 0; x
< 10; ++x
)
98 printf ("reg %d == (%d, %d) %.*s\n",
102 regs
[x
].rm_eo
- regs
[x
].rm_so
,
103 t
->data
+ regs
[x
].rm_so
);
113 main (int argc
, char * argv
[])
121 hi
= (sizeof (the_tests
) / sizeof (the_tests
[0])) - 1;
132 for (x
= lo
; x
< hi
; ++x
)
135 res
|= run_a_test (x
, &the_tests
[x
]);