1 #pragma prototyped noticed
4 * regex(3) test harness
6 * build: cc -o testregex testregex.c
7 * help: testregex --man
8 * note: REG_* features are detected by #ifdef; if REG_* are enums
9 * then supply #define REG_foo REG_foo for each enum REG_foo
11 * Glenn Fowler <glenn.s.fowler@gmail.com>
14 * PLEASE: publish your tests so everyone can benefit
16 * The following license covers testregex.c and all associated test data.
18 * Permission is hereby granted, free of charge, to any person obtaining a
19 * copy of THIS SOFTWARE FILE (the "Software"), to deal in the Software
20 * without restriction, including without limitation the rights to use,
21 * copy, modify, merge, publish, distribute, and/or sell copies of the
22 * Software, and to permit persons to whom the Software is furnished to do
23 * so, subject to the following disclaimer:
25 * THIS SOFTWARE IS PROVIDED BY AT&T ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL AT&T BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 static const char id
[] = "\n@(#)$Id: testregex (AT&T Research) 2010-06-10 $\0\n";
42 #include <sys/types.h>
59 #define RE_DUP_MAX 32767
70 #define TEST_ARE 0x00000001
71 #define TEST_BRE 0x00000002
72 #define TEST_ERE 0x00000004
73 #define TEST_KRE 0x00000008
74 #define TEST_LRE 0x00000010
75 #define TEST_SRE 0x00000020
77 #define TEST_EXPAND 0x00000100
78 #define TEST_LENIENT 0x00000200
80 #define TEST_QUERY 0x00000400
81 #define TEST_SUB 0x00000800
82 #define TEST_UNSPECIFIED 0x00001000
83 #define TEST_VERIFY 0x00002000
84 #define TEST_AND 0x00004000
85 #define TEST_OR 0x00008000
87 #define TEST_DELIMIT 0x00010000
88 #define TEST_OK 0x00020000
89 #define TEST_SAME 0x00040000
91 #define TEST_ACTUAL 0x00100000
92 #define TEST_BASELINE 0x00200000
93 #define TEST_FAIL 0x00400000
94 #define TEST_PASS 0x00800000
95 #define TEST_SUMMARY 0x01000000
97 #define TEST_IGNORE_ERROR 0x02000000
98 #define TEST_IGNORE_OVER 0x04000000
99 #define TEST_IGNORE_POSITION 0x08000000
101 #define TEST_CATCH 0x10000000
102 #define TEST_VERBOSE 0x20000000
104 #define TEST_DECOMP 0x40000000
106 #define TEST_GLOBAL (TEST_ACTUAL|TEST_AND|TEST_BASELINE|TEST_CATCH|TEST_FAIL|TEST_IGNORE_ERROR|TEST_IGNORE_OVER|TEST_IGNORE_POSITION|TEST_OR|TEST_PASS|TEST_SUMMARY|TEST_VERBOSE)
108 #ifdef REG_DISCIPLINE
113 typedef struct Disc_s
121 compf(const regex_t
* re
, const char* xstr
, size_t xlen
, regdisc_t
* disc
)
123 Disc_t
* dp
= (Disc_t
*)disc
;
125 return (void*)((char*)0 + ++dp
->ordinal
);
129 execf(const regex_t
* re
, void* data
, const char* xstr
, size_t xlen
, const char* sstr
, size_t slen
, char** snxt
, regdisc_t
* disc
)
131 Disc_t
* dp
= (Disc_t
*)disc
;
133 sfprintf(dp
->sp
, "{%-.*s}(%lu:%d)", xlen
, xstr
, (char*)data
- (char*)0, slen
);
138 resizef(void* handle
, void* data
, size_t size
)
142 return stkalloc((Sfio_t
*)handle
, size
);
155 #define H(x) do{if(html)fprintf(stderr,x);}while(0)
156 #define T(x) fprintf(stderr,x)
161 H("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n");
164 H("<TITLE>testregex man document</TITLE>\n");
166 H("<BODY bgcolor=white>\n");
169 T(" testregex - regex(3) test harness\n");
172 T(" testregex [ options ]\n");
175 T(" testregex reads regex(3) test specifications, one per line, from the\n");
176 T(" standard input and writes one output line for each failed test. A\n");
177 T(" summary line is written after all tests are done. Each successful\n");
178 T(" test is run again with REG_NOSUB. Unsupported features are noted\n");
179 T(" before the first test, and tests requiring these features are\n");
180 T(" silently ignored.\n");
183 T(" -c catch signals and non-terminating calls\n");
184 T(" -e ignore error return mismatches\n");
185 T(" -h list help on standard error\n");
186 T(" -n do not repeat successful tests with regnexec()\n");
187 T(" -o ignore match[] overrun errors\n");
188 T(" -p ignore negative position mismatches\n");
189 T(" -s use stack instead of malloc\n");
190 T(" -x do not repeat successful tests with REG_NOSUB\n");
191 T(" -v list each test line\n");
192 T(" -A list failed test lines with actual answers\n");
193 T(" -B list all test lines with actual answers\n");
194 T(" -F list failed test lines\n");
195 T(" -P list passed test lines\n");
196 T(" -S output one summary line\n");
199 T(" Input lines may be blank, a comment beginning with #, or a test\n");
200 T(" specification. A specification is five fields separated by one\n");
201 T(" or more tabs. NULL denotes the empty string and NIL denotes the\n");
204 T(" Field 1: the regex(3) flags to apply, one character per REG_feature\n");
205 T(" flag. The test is skipped if REG_feature is not supported by the\n");
206 T(" implementation. If the first character is not [BEASKLP] then the\n");
207 T(" specification is a global control line. One or more of [BEASKLP] may be\n");
208 T(" specified; the test will be repeated for each mode.\n");
210 T(" B basic BRE (grep, ed, sed)\n");
211 T(" E REG_EXTENDED ERE (egrep)\n");
212 T(" A REG_AUGMENTED ARE (egrep with negation)\n");
213 T(" S REG_SHELL SRE (sh glob)\n");
214 T(" K REG_SHELL|REG_AUGMENTED KRE (ksh glob)\n");
215 T(" L REG_LITERAL LRE (fgrep)\n");
217 T(" a REG_LEFT|REG_RIGHT implicit ^...$\n");
218 T(" b REG_NOTBOL lhs does not match ^\n");
219 T(" c REG_COMMENT ignore space and #...\\n\n");
220 T(" d REG_SHELL_DOT explicit leading . match\n");
221 T(" e REG_NOTEOL rhs does not match $\n");
222 T(" f REG_MULTIPLE multiple \\n separated patterns\n");
223 T(" g FNM_LEADING_DIR testfnmatch only -- match until /\n");
224 T(" h REG_MULTIREF multiple digit backref\n");
225 T(" i REG_ICASE ignore case\n");
226 T(" j REG_SPAN . matches \\n\n");
227 T(" k REG_ESCAPE \\ to ecape [...] delimiter\n");
228 T(" l REG_LEFT implicit ^...\n");
229 T(" m REG_MINIMAL minimal match\n");
230 T(" n REG_NEWLINE explicit \\n match\n");
231 T(" o REG_ENCLOSED (|&) magic inside [@|&](...)\n");
232 T(" p REG_SHELL_PATH explicit / match\n");
233 T(" q REG_DELIMITED delimited pattern\n");
234 T(" r REG_RIGHT implicit ...$\n");
235 T(" s REG_SHELL_ESCAPED \\ not special\n");
236 T(" t REG_MUSTDELIM all delimiters must be specified\n");
237 T(" u standard unspecified behavior -- errors not counted\n");
238 T(" v REG_CLASS_ESCAPE \\ special inside [...]\n");
239 T(" w REG_NOSUB no subexpression match array\n");
240 T(" x REG_LENIENT let some errors slide\n");
241 T(" y REG_LEFT regexec() implicit ^...\n");
242 T(" z REG_NULL NULL subexpressions ok\n");
243 T(" $ expand C \\c escapes in fields 2 and 3\n");
244 T(" / field 2 is a regsubcomp() expression\n");
245 T(" = field 3 is a regdecomp() expression\n");
247 T(" Field 1 control lines:\n");
249 T(" C set LC_COLLATE and LC_CTYPE to locale in field 2\n");
251 T(" ?test ... output field 5 if passed and != EXPECTED, silent otherwise\n");
252 T(" &test ... output field 5 if current and previous passed\n");
253 T(" |test ... output field 5 if current passed and previous failed\n");
254 T(" ; ... output field 2 if previous failed\n");
255 T(" {test ... skip if failed until }\n");
256 T(" } end of skip\n");
258 T(" : comment comment copied as output NOTE\n");
259 T(" :comment:test :comment: ignored\n");
260 T(" N[OTE] comment comment copied as output NOTE\n");
261 T(" T[EST] comment comment\n");
263 T(" number use number for nmatch (20 by default)\n");
265 T(" Field 2: the regular expression pattern; SAME uses the pattern from\n");
266 T(" the previous specification. RE_DUP_MAX inside {...} expands to the\n");
267 T(" value from <limits.h>.\n");
269 T(" Field 3: the string to match. X...{RE_DUP_MAX} expands to RE_DUP_MAX\n");
270 T(" copies of X.\n");
272 T(" Field 4: the test outcome. This is either one of the posix error\n");
273 T(" codes (with REG_ omitted) or the match array, a list of (m,n)\n");
274 T(" entries with m and n being first and last+1 positions in the\n");
275 T(" field 3 string, or NULL if REG_NOSUB is in effect and success\n");
276 T(" is expected. BADPAT is acceptable in place of any regcomp(3)\n");
277 T(" error code. The match[] array is initialized to (-2,-2) before\n");
278 T(" each test. All array elements from 0 to nmatch-1 must be specified\n");
279 T(" in the outcome. Unspecified endpoints (offset -1) are denoted by ?.\n");
280 T(" Unset endpoints (offset -2) are denoted by X. {x}(o:n) denotes a\n");
281 T(" matched (?{...}) expression, where x is the text enclosed by {...},\n");
282 T(" o is the expression ordinal counting from 1, and n is the length of\n");
283 T(" the unmatched portion of the subject string. If x starts with a\n");
284 T(" number then that is the return value of re_execf(), otherwise 0 is\n");
285 T(" returned. RE_DUP_MAX[-+]N expands to the <limits.h> value -+N.\n");
287 T(" Field 5: optional comment appended to the report.\n");
290 T(" If a regex implementation misbehaves with memory then all bets are off.\n");
293 T(" Glenn Fowler glenn.s.fowler@gmail.com (ksh strmatch, regex extensions)\n");
294 T(" David Korn dgkorn@gmail.com (ksh glob matcher)\n");
295 T(" Doug McIlroy mcilroy@dartmouth.edu (ast regex/testre in C++)\n");
296 T(" Tom Lord lord@regexps.com (rx tests)\n");
297 T(" Henry Spencer henry@zoo.toronto.edu (original public regex)\n");
298 T(" Andrew Hume andrew@research.att.com (gre tests)\n");
299 T(" John Maddock John_Maddock@compuserve.com (regex++ tests)\n");
300 T(" Philip Hazel ph10@cam.ac.uk (pcre tests)\n");
301 T(" Ville Laurikari vl@iki.fi (libtre tests)\n");
308 #define elementsof(x) (sizeof(x)/sizeof(x[0]))
312 #define streq(a,b) (*(a)==*(b)&&!strcmp(a,b))
318 #ifndef REG_TEST_DEFAULT
319 #define REG_TEST_DEFAULT 0
322 #ifndef REG_EXEC_DEFAULT
323 #define REG_EXEC_DEFAULT 0
326 static const char* unsupported
[] =
332 #ifndef REG_AUGMENTED
339 #ifndef REG_CLASS_ESCAPE
345 #ifndef REG_DELIMITED
348 #ifndef REG_DISCIPLINE
375 #ifndef REG_MUSTDELIM
393 #ifndef REG_SHELL_DOT
396 #ifndef REG_SHELL_ESCAPED
399 #ifndef REG_SHELL_GROUP
402 #ifndef REG_SHELL_PATH
408 #if REG_NOSUB & REG_TEST_DEFAULT
423 #ifndef REG_CLASS_ESCAPE
424 #define REG_CLASS_ESCAPE NOTEST
427 #define REG_COMMENT NOTEST
429 #ifndef REG_DELIMITED
430 #define REG_DELIMITED NOTEST
433 #define REG_ESCAPE NOTEST
436 #define REG_ICASE NOTEST
439 #define REG_LEFT NOTEST
442 #define REG_LENIENT 0
445 #define REG_MINIMAL NOTEST
448 #define REG_MULTIPLE NOTEST
451 #define REG_MULTIREF NOTEST
453 #ifndef REG_MUSTDELIM
454 #define REG_MUSTDELIM NOTEST
457 #define REG_NEWLINE NOTEST
460 #define REG_NOTBOL NOTEST
463 #define REG_NOTEOL NOTEST
466 #define REG_NULL NOTEST
469 #define REG_RIGHT NOTEST
471 #ifndef REG_SHELL_DOT
472 #define REG_SHELL_DOT NOTEST
474 #ifndef REG_SHELL_ESCAPED
475 #define REG_SHELL_ESCAPED NOTEST
477 #ifndef REG_SHELL_GROUP
478 #define REG_SHELL_GROUP NOTEST
480 #ifndef REG_SHELL_PATH
481 #define REG_SHELL_PATH NOTEST
484 #define REG_SPAN NOTEST
487 #define REG_UNKNOWN (-1)
490 #define REG_ENEWLINE (REG_UNKNOWN-1)
494 #define REG_ENULL (REG_UNKNOWN-2)
496 #define REG_ENULL REG_EMPTY
500 #define REG_ECOUNT (REG_UNKNOWN-3)
503 #define REG_BADESC (REG_UNKNOWN-4)
506 #define REG_EMEM (REG_UNKNOWN-5)
509 #define REG_EHUNG (REG_UNKNOWN-6)
512 #define REG_EBUS (REG_UNKNOWN-7)
515 #define REG_EFAULT (REG_UNKNOWN-8)
518 #define REG_EFLAGS (REG_UNKNOWN-9)
521 #define REG_EDELIM (REG_UNKNOWN-9)
524 static const struct { int code
; char* name
; } codes
[] =
526 REG_UNKNOWN
, "UNKNOWN",
527 REG_NOMATCH
, "NOMATCH",
528 REG_BADPAT
, "BADPAT",
529 REG_ECOLLATE
, "ECOLLATE",
530 REG_ECTYPE
, "ECTYPE",
531 REG_EESCAPE
, "EESCAPE",
532 REG_ESUBREG
, "ESUBREG",
533 REG_EBRACK
, "EBRACK",
534 REG_EPAREN
, "EPAREN",
535 REG_EBRACE
, "EBRACE",
537 REG_ERANGE
, "ERANGE",
538 REG_ESPACE
, "ESPACE",
539 REG_BADRPT
, "BADRPT",
540 REG_ENEWLINE
, "ENEWLINE",
542 REG_ECOUNT
, "ECOUNT",
543 REG_BADESC
, "BADESC",
547 REG_EFAULT
, "EFAULT",
548 REG_EFLAGS
, "EFLAGS",
549 REG_EDELIM
, "EDELIM",
568 #ifdef REG_DISCIPLINE
574 quote(char* s
, int len
, unsigned long test
)
576 unsigned char* u
= (unsigned char*)s
;
585 else if (!*u
&& len
<= 1)
587 else if (test
& TEST_EXPAND
)
590 len
= strlen((char*)u
);
592 if (test
& TEST_DELIMIT
)
601 if (test
& TEST_DELIMIT
)
633 if ((w
= mblen(s
, (char*)e
- s
)) > 1)
636 fwrite(s
, 1, w
, stdout
);
640 if (!iscntrl(c
) && isprint(c
))
643 printf("\\x%02x", c
);
646 if (test
& TEST_DELIMIT
)
654 report(char* comment
, char* fun
, char* re
, char* s
, int len
, char* msg
, int flags
, unsigned long test
)
657 printf("%s:", state
.file
);
658 printf("%d:", state
.lineno
);
662 quote(re
, -1, test
|TEST_DELIMIT
);
666 quote(s
, len
, test
|TEST_DELIMIT
);
669 if (test
& TEST_UNSPECIFIED
)
672 printf(" unspecified behavior");
677 printf(" %s", state
.which
);
678 if (flags
& REG_NOSUB
)
682 if (comment
[strlen(comment
)-1] == '\n')
683 printf(" %s", comment
);
686 printf(" %s: ", comment
);
693 error(regex_t
* preg
, int code
)
704 msg
= "memory fault";
707 msg
= "did not terminate";
710 regerror(code
, preg
, msg
= buf
, sizeof buf
);
717 bad(char* comment
, char* re
, char* s
, int len
, unsigned long test
)
719 printf("bad test case ");
720 report(comment
, NiL
, re
, s
, len
, NiL
, 0, test
);
733 for (b
= t
= s
; *t
= *s
; s
++, t
++)
776 q
= c
== 'u' ? (s
+ 5) : (char*)0;
778 while (!e
|| !q
|| s
< q
)
782 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
783 c
= (c
<< 4) + *s
- 'a' + 10;
785 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
786 c
= (c
<< 4) + *s
- 'A' + 10;
788 case '0': case '1': case '2': case '3': case '4':
789 case '5': case '6': case '7': case '8': case '9':
790 c
= (c
<< 4) + *s
- '0';
814 case '0': case '1': case '2': case '3':
815 case '4': case '5': case '6': case '7':
822 case '0': case '1': case '2': case '3':
823 case '4': case '5': case '6': case '7':
824 c
= (c
<< 3) + *s
- '0';
835 bad("invalid C \\ escape\n", s
- 1, NiL
, 0, 0);
841 matchoffprint(int off
)
858 matchprint(regmatch_t
* match
, int nmatch
, int nsub
, char* ans
, unsigned long test
)
862 for (; nmatch
> nsub
+ 1; nmatch
--)
863 if ((match
[nmatch
-1].rm_so
!= -1 || match
[nmatch
-1].rm_eo
!= -1) && (!(test
& TEST_IGNORE_POSITION
) || match
[nmatch
-1].rm_so
>= 0 && match
[nmatch
-1].rm_eo
>= 0))
865 for (i
= 0; i
< nmatch
; i
++)
868 matchoffprint(match
[i
].rm_so
);
870 matchoffprint(match
[i
].rm_eo
);
873 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
)))
876 printf(" expected: %s", ans
);
882 matchcheck(regmatch_t
* match
, int nmatch
, int nsub
, char* ans
, char* re
, char* s
, int len
, int flags
, unsigned long test
)
889 if (streq(ans
, "OK"))
890 return test
& (TEST_BASELINE
|TEST_PASS
|TEST_VERIFY
);
891 for (i
= 0, p
= ans
; i
< nmatch
&& *p
; i
++)
895 #ifdef REG_DISCIPLINE
898 if (!(x
= sfstruse(state
.disc
.sp
)))
899 bad("out of space [discipline string]\n", NiL
, NiL
, 0, 0);
902 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
904 report("callout failed", NiL
, re
, s
, len
, NiL
, flags
, test
);
906 printf(" expected, ");
908 printf(" returned\n");
914 bad("improper answer\n", re
, s
, -1, test
);
920 else if (*p
== 'R' && !memcmp(p
, "RE_DUP_MAX", 10))
924 if (*p
== '+' || *p
== '-')
925 m
+= strtol(p
, &p
, 10);
928 m
= strtol(p
, &p
, 10);
930 bad("improper answer\n", re
, s
, -1, test
);
936 else if (*p
== 'R' && !memcmp(p
, "RE_DUP_MAX", 10))
940 if (*p
== '+' || *p
== '-')
941 n
+= strtol(p
, &p
, 10);
944 n
= strtol(p
, &p
, 10);
946 bad("improper answer\n", re
, s
, -1, test
);
947 if (m
!=match
[i
].rm_so
|| n
!=match
[i
].rm_eo
)
949 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
)))
951 report("failed: match was", NiL
, re
, s
, len
, NiL
, flags
, test
);
952 matchprint(match
, nmatch
, nsub
, ans
, test
);
957 for (; i
< nmatch
; i
++)
959 if (match
[i
].rm_so
!=-1 || match
[i
].rm_eo
!=-1)
961 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_VERIFY
)))
963 if ((test
& TEST_IGNORE_POSITION
) && (match
[i
].rm_so
<0 || match
[i
].rm_eo
<0))
968 if (!(test
& TEST_SUMMARY
))
970 report("failed: match was", NiL
, re
, s
, len
, NiL
, flags
, test
);
971 matchprint(match
, nmatch
, nsub
, ans
, test
);
977 if (!(test
& TEST_IGNORE_OVER
) && match
[nmatch
].rm_so
!= state
.NOMATCH
.rm_so
)
979 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
)))
981 report("failed: overran match array", NiL
, re
, s
, len
, NiL
, flags
, test
);
982 matchprint(match
, nmatch
+ 1, nsub
, NiL
, test
);
1002 else op
= SIG_SETMASK
;
1003 sigprocmask(op
, &mask
, NiL
);
1006 sigsetmask(s
? (sigsetmask(0L) & ~sigmask(s
)) : 0L);
1016 signal(sig
, gotcha
);
1032 longjmp(state
.gotcha
, ret
);
1038 static char buf
[32 * 1024];
1040 register char* s
= buf
;
1041 register char* e
= &buf
[sizeof(buf
)];
1046 if (!(b
= fgets(s
, e
- s
, fp
)))
1050 if (s
== b
|| *--s
!= '\n' || s
== b
|| *(s
- 1) != '\\')
1060 static unsigned long
1061 note(unsigned long level
, char* msg
, unsigned long skip
, unsigned long test
)
1063 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_SUMMARY
)) && !skip
)
1067 printf("%s: ", msg
);
1068 printf("skipping lines %d", state
.lineno
);
1070 return skip
| level
;
1073 #define TABS(n) &ts[7-((n)&7)]
1075 static char ts
[] = "\t\t\t\t\t\t\t";
1077 static unsigned long
1078 extract(int* tabs
, char* spec
, char* re
, char* s
, char* ans
, char* msg
, char* accept
, regmatch_t
* match
, int nmatch
, int nsub
, unsigned long skip
, unsigned long level
, unsigned long test
)
1080 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_OK
|TEST_PASS
|TEST_SUMMARY
))
1082 state
.extracted
= 1;
1086 if ((test
& TEST_VERIFY
) && !(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_SUMMARY
)))
1088 if (msg
&& strcmp(msg
, "EXPECTED"))
1089 printf("NOTE\t%s\n", msg
);
1092 test
&= ~(TEST_PASS
|TEST_QUERY
);
1094 if (test
& (TEST_QUERY
|TEST_VERIFY
))
1096 if (test
& TEST_BASELINE
)
1097 test
&= ~(TEST_BASELINE
|TEST_PASS
);
1102 if (!(test
& TEST_OK
))
1104 if (test
& TEST_UNSPECIFIED
)
1105 state
.unspecified
++;
1109 if (test
& (TEST_PASS
|TEST_SUMMARY
))
1111 test
&= ~TEST_DELIMIT
;
1112 printf("%s%s", spec
, TABS(*tabs
++));
1113 if ((test
& (TEST_BASELINE
|TEST_SAME
)) == (TEST_BASELINE
|TEST_SAME
))
1116 quote(re
, -1, test
);
1117 printf("%s", TABS(*tabs
++));
1119 printf("%s", TABS(*tabs
++));
1120 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
)) || !accept
&& !match
)
1123 printf("%s", accept
);
1125 matchprint(match
, nmatch
, nsub
, NiL
, test
);
1127 printf("%s%s", TABS(*tabs
++), msg
);
1130 else if (test
& TEST_QUERY
)
1131 skip
= note(level
, msg
, skip
, test
);
1132 else if (test
& TEST_VERIFY
)
1133 state
.extracted
= 1;
1138 catchfree(regex_t
* preg
, int flags
, int* tabs
, char* spec
, char* re
, char* s
, char* ans
, char* msg
, char* accept
, regmatch_t
* match
, int nmatch
, int nsub
, unsigned long skip
, unsigned long level
, unsigned long test
)
1142 if (!(test
& TEST_CATCH
))
1147 else if (!(eret
= setjmp(state
.gotcha
)))
1153 else if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
1154 extract(tabs
, spec
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
);
1157 report("failed", "regfree", re
, NiL
, -1, msg
, flags
, test
);
1164 expand(char* os
, char* ot
)
1185 if (n
== 1 && !memcmp(s
, "E_DUP_MAX", 9))
1188 for (t
= ot
; os
< s
; *t
++ = *os
++);
1189 r
= ((t
- ot
) >= 5 && t
[-1] == '{' && t
[-2] == '.' && t
[-3] == '.' && t
[-4] == '.') ? t
[-5] : 0;
1192 if (*(s
+= 10) == '+' || *s
== '-')
1193 m
+= strtol(s
, &s
, 10);
1199 while (*s
&& *s
++ != '}');
1202 t
+= snprintf(t
, 32, "%ld", m
);
1217 main(int argc
, char** argv
)
1235 unsigned long level
;
1253 regmatch_t match
[100];
1256 static char pat
[32 * 1024];
1257 static char patbuf
[32 * 1024];
1258 static char strbuf
[32 * 1024];
1260 int nonosub
= REG_NOSUB
== 0;
1263 unsigned long test
= 0;
1265 static char* filter
[] = { "-", 0 };
1267 state
.NOMATCH
.rm_so
= state
.NOMATCH
.rm_eo
= -2;
1269 version
= (char*)id
+ 10;
1270 while (p
< &unit
[sizeof(unit
)-1] && (*p
= *version
++) && !isspace(*p
))
1273 while ((p
= *++argv
) && *p
== '-')
1284 test
|= TEST_IGNORE_ERROR
;
1297 test
|= TEST_IGNORE_OVER
;
1300 test
|= TEST_IGNORE_POSITION
;
1303 #ifdef REG_DISCIPLINE
1304 if (!(state
.stack
= stkalloc(stkstd
, 0)))
1305 fprintf(stderr
, "%s: out of space [stack]", unit
);
1306 state
.disc
.disc
.re_resizef
= resizef
;
1307 state
.disc
.disc
.re_resizehandle
= (void*)stkstd
;
1314 test
|= TEST_VERBOSE
;
1317 test
|= TEST_ACTUAL
;
1320 test
|= TEST_BASELINE
;
1329 test
|= TEST_SUMMARY
;
1332 fprintf(stderr
, "%s: %c: invalid option\n", unit
, *p
);
1340 while (state
.file
= *argv
++)
1342 if (streq(state
.file
, "-") || streq(state
.file
, "/dev/stdin") || streq(state
.file
, "/dev/fd/0"))
1347 else if (!(fp
= fopen(state
.file
, "r")))
1349 fprintf(stderr
, "%s: %s: cannot read\n", unit
, state
.file
);
1352 testno
= state
.errors
= state
.ignored
= state
.lineno
= state
.passed
=
1353 state
.signals
= state
.unspecified
= state
.warnings
= 0;
1356 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_SUMMARY
)))
1358 printf("TEST\t%s ", unit
);
1380 subunit
= state
.file
;
1383 subunitlen
= p
- subunit
;
1384 printf("%-.*s ", subunitlen
, subunit
);
1388 for (s
= version
; *s
&& (*s
!= ' ' || *(s
+ 1) != '$'); s
++)
1390 if (test
& TEST_CATCH
)
1392 if (test
& TEST_IGNORE_ERROR
)
1393 printf(", ignore error code mismatches");
1394 if (test
& TEST_IGNORE_POSITION
)
1395 printf(", ignore negative position mismatches");
1396 #ifdef REG_DISCIPLINE
1400 if (test
& TEST_VERBOSE
)
1401 printf(", verbose");
1403 #ifdef REG_VERSIONID
1404 if (regerror(REG_VERSIONID
, NiL
, pat
, sizeof(pat
)) > 0)
1408 #ifdef REG_TEST_VERSION
1409 s
= REG_TEST_VERSION
;
1413 printf("NOTE\t%s\n", s
);
1414 if (elementsof(unsupported
) > 1)
1416 #if (REG_TEST_DEFAULT & (REG_AUGMENTED|REG_EXTENDED|REG_SHELL)) || !defined(REG_EXTENDED)
1419 i
= REG_EXTENDED
!= 0;
1421 for (got
= 0; i
< elementsof(unsupported
) - 1; i
++)
1426 printf("NOTE\tunsupported: %s", unsupported
[i
]);
1429 printf(",%s", unsupported
[i
]);
1435 #ifdef REG_DISCIPLINE
1436 state
.disc
.disc
.re_version
= REG_VERSION
;
1437 state
.disc
.disc
.re_compf
= compf
;
1438 state
.disc
.disc
.re_execf
= execf
;
1439 if (!(state
.disc
.sp
= sfstropen()))
1440 bad("out of space [discipline string stream]\n", NiL
, NiL
, 0, 0);
1441 preg
.re_disc
= &state
.disc
.disc
;
1443 if (test
& TEST_CATCH
)
1445 signal(SIGALRM
, gotcha
);
1446 signal(SIGBUS
, gotcha
);
1447 signal(SIGSEGV
, gotcha
);
1449 while (p
= get_line(fp
))
1455 if (*p
== ':' && !isspace(*(p
+ 1)))
1457 while (*++p
&& *p
!= ':');
1460 if (test
& TEST_BASELINE
)
1461 printf("%s\n", line
);
1467 if (*p
== 0 || *p
== '#' || *p
== 'T')
1469 if (test
& TEST_BASELINE
)
1470 printf("%s\n", line
);
1473 if (*p
== ':' || *p
== 'N')
1475 if (test
& TEST_BASELINE
)
1476 printf("%s\n", line
);
1477 else if (!(test
& (TEST_ACTUAL
|TEST_FAIL
|TEST_PASS
|TEST_SUMMARY
)))
1479 while (*++p
&& !isspace(*p
));
1482 printf("NOTE %s\n", p
);
1498 *(delim
[i
] = p
- 1) = 0;
1502 if (streq(s
, "NIL"))
1504 else if (streq(s
, "NULL"))
1514 if (i
>= elementsof(field
))
1515 bad("too many fields\n", NiL
, NiL
, 0, 0);
1523 if (!(spec
= field
[0]))
1524 bad("NIL spec\n", NiL
, NiL
, 0, 0);
1528 cflags
= REG_TEST_DEFAULT
;
1529 eflags
= REG_EXEC_DEFAULT
;
1530 test
&= TEST_GLOBAL
;
1531 state
.extracted
= 0;
1534 for (p
= spec
; *p
; p
++)
1538 nmatch
= strtol(p
, &p
, 10);
1539 if (nmatch
>= elementsof(match
))
1540 bad("nmatch must be < 100\n", NiL
, NiL
, 0, 0);
1553 if (!(test
& TEST_QUERY
) && !(skip
& level
))
1554 bad("locale must be nested\n", NiL
, NiL
, 0, 0);
1555 test
&= ~TEST_QUERY
;
1557 bad("locale nesting not supported\n", NiL
, NiL
, 0, 0);
1559 bad("locale field expected\n", NiL
, NiL
, 0, 0);
1560 if (!(skip
& level
))
1562 #if defined(LC_COLLATE) && defined(LC_CTYPE)
1564 if (!s
|| streq(s
, "POSIX"))
1566 if ((ans
= setlocale(LC_COLLATE
, s
)) && streq(ans
, "POSIX"))
1568 if (!ans
|| !streq(ans
, s
) && streq(s
, "C"))
1570 else if ((ans
= setlocale(LC_CTYPE
, s
)) && streq(ans
, "POSIX"))
1572 if (!ans
|| !streq(ans
, s
) && streq(s
, "C"))
1573 skip
= note(level
, s
, skip
, test
);
1576 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_SUMMARY
)))
1577 printf("NOTE \"%s\" locale\n", s
);
1581 skip
= note(level
, skip
, test
, "locales not supported");
1600 cflags
|= REG_LEFT
|REG_RIGHT
;
1603 eflags
|= REG_NOTBOL
;
1606 cflags
|= REG_COMMENT
;
1609 cflags
|= REG_SHELL_DOT
;
1612 eflags
|= REG_NOTEOL
;
1615 cflags
|= REG_MULTIPLE
;
1621 cflags
|= REG_MULTIREF
;
1624 cflags
|= REG_ICASE
;
1630 cflags
|= REG_ESCAPE
;
1636 cflags
|= REG_MINIMAL
;
1639 cflags
|= REG_NEWLINE
;
1642 cflags
|= REG_SHELL_GROUP
;
1645 cflags
|= REG_SHELL_PATH
;
1648 cflags
|= REG_DELIMITED
;
1651 cflags
|= REG_RIGHT
;
1654 cflags
|= REG_SHELL_ESCAPED
;
1657 cflags
|= REG_MUSTDELIM
;
1660 test
|= TEST_UNSPECIFIED
;
1663 cflags
|= REG_CLASS_ESCAPE
;
1666 cflags
|= REG_NOSUB
;
1670 cflags
|= REG_LENIENT
;
1672 test
|= TEST_LENIENT
;
1682 test
|= TEST_EXPAND
;
1690 test
|= TEST_DECOMP
;
1694 test
|= TEST_VERIFY
;
1695 test
&= ~(TEST_AND
|TEST_OR
);
1696 state
.verify
= state
.passed
;
1699 test
|= TEST_VERIFY
|TEST_AND
;
1703 test
|= TEST_VERIFY
|TEST_OR
;
1713 if (skip
& (level
>> 1))
1726 bad("invalid {...} nesting\n", NiL
, NiL
, 0, 0);
1727 if ((skip
& level
) && !(skip
& (level
>>1)))
1729 if (!(test
& (TEST_BASELINE
|TEST_SUMMARY
)))
1731 if (test
& (TEST_ACTUAL
|TEST_FAIL
))
1733 else if (!(test
& TEST_PASS
))
1734 printf("-%d\n", state
.lineno
);
1737 #if defined(LC_COLLATE) && defined(LC_CTYPE)
1738 else if (locale
& level
)
1741 if (!(skip
& level
))
1744 setlocale(LC_COLLATE
, s
);
1745 setlocale(LC_CTYPE
, s
);
1746 if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_SUMMARY
)))
1747 printf("NOTE \"%s\" locale\n", s
);
1748 else if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_PASS
))
1751 else if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
))
1760 bad("bad spec\n", spec
, NiL
, 0, test
);
1766 if ((cflags
|eflags
) == NOTEST
|| (skip
& level
) && (test
& TEST_BASELINE
))
1768 if (test
& TEST_BASELINE
)
1772 printf("%s\n", line
);
1778 if (!(test
& TEST_VERIFY
))
1781 if (state
.passed
== state
.verify
&& i
> 1)
1782 printf("NOTE\t%s\n", field
[1]);
1785 else if (state
.passed
> state
.verify
)
1788 else if (test
& TEST_AND
)
1790 if (state
.passed
== state
.verify
)
1792 state
.passed
= state
.verify
;
1794 if (i
< ((test
& TEST_DECOMP
) ? 3 : 4))
1795 bad("too few fields\n", NiL
, NiL
, 0, test
);
1796 while (i
< elementsof(field
))
1800 if (streq(re
, "SAME"))
1807 if (test
& TEST_EXPAND
)
1809 re
= expand(re
, patbuf
);
1810 strcpy(ppat
= pat
, re
);
1818 s
= expand(s
, strbuf
);
1819 if (test
& TEST_EXPAND
)
1823 if (nstr
!= strlen(s
))
1828 if (!(ans
= field
[(test
& TEST_DECOMP
) ? 2 : 3]))
1829 bad("NIL answer\n", NiL
, NiL
, 0, test
);
1832 if (test
& TEST_SUB
)
1834 cflags
|= REG_DELIMITED
;
1839 if (test
& TEST_DECOMP
)
1845 if (state
.extracted
|| (skip
& level
))
1847 #if !(REG_TEST_DEFAULT & (REG_AUGMENTED|REG_EXTENDED|REG_SHELL))
1849 if (REG_EXTENDED
!= 0 && (test
& TEST_BRE
))
1851 if (test
& TEST_BRE
)
1856 state
.which
= "BRE";
1861 if (test
& TEST_ERE
)
1864 flags
= cflags
| REG_EXTENDED
;
1865 state
.which
= "ERE";
1869 #ifdef REG_AUGMENTED
1870 if (test
& TEST_ARE
)
1873 flags
= cflags
| REG_AUGMENTED
;
1874 state
.which
= "ARE";
1879 if (test
& TEST_LRE
)
1882 flags
= cflags
| REG_LITERAL
;
1883 state
.which
= "LRE";
1888 if (test
& TEST_SRE
)
1891 flags
= cflags
| REG_SHELL
;
1892 state
.which
= "SRE";
1895 #ifdef REG_AUGMENTED
1896 if (test
& TEST_KRE
)
1899 flags
= cflags
| REG_SHELL
| REG_AUGMENTED
;
1900 state
.which
= "KRE";
1906 if (test
& (TEST_BASELINE
|TEST_PASS
|TEST_VERIFY
))
1907 extract(tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
|TEST_OK
);
1910 if ((test
& (TEST_QUERY
|TEST_VERBOSE
|TEST_VERIFY
)) == TEST_VERBOSE
)
1912 printf("test %-3d %s ", state
.lineno
, state
.which
);
1913 quote(re
, -1, test
|TEST_DELIMIT
);
1915 quote(s
, nstr
, test
|TEST_DELIMIT
);
1922 if (nstr
>= 0 && nstr
!= strlen(s
))
1928 if (state
.extracted
|| (skip
& level
))
1930 if (!(test
& TEST_QUERY
))
1932 #ifdef REG_DISCIPLINE
1934 stkset(stkstd
, state
.stack
, 0);
1935 flags
|= REG_DISCIPLINE
;
1936 state
.disc
.ordinal
= 0;
1937 sfstrseek(state
.disc
.sp
, 0, SEEK_SET
);
1939 if (!(test
& TEST_CATCH
))
1940 cret
= regcomp(&preg
, re
, flags
);
1941 else if (!(cret
= setjmp(state
.gotcha
)))
1944 cret
= regcomp(&preg
, re
, flags
);
1948 if (!cret
&& (test
& TEST_SUB
))
1951 p
= re
+ preg
.re_npat
;
1952 if (!(test
& TEST_CATCH
))
1953 cret
= regsubcomp(&preg
, p
, NiL
, 0, 0);
1954 else if (!(cret
= setjmp(state
.gotcha
)))
1957 cret
= regsubcomp(&preg
, p
, NiL
, 0, 0);
1960 if (!cret
&& *(p
+= preg
.re_npat
) && !(preg
.re_sub
->re_flags
& REG_SUB_LAST
))
1962 if (catchfree(&preg
, flags
, tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
))
1969 if (!cret
&& (test
& TEST_DECOMP
))
1973 if ((j
= nmatch
) > sizeof(buf
))
1976 p
= re
+ preg
.re_npat
;
1977 if (!(test
& TEST_CATCH
))
1978 i
= regdecomp(&preg
, -1, buf
, j
);
1979 else if (!(cret
= setjmp(state
.gotcha
)))
1982 i
= regdecomp(&preg
, -1, buf
, j
);
1987 catchfree(&preg
, flags
, tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
);
1990 if (i
!= (strlen(ans
) + 1))
1992 report("failed", fun
, re
, s
, nstr
, msg
, flags
, test
);
1993 printf(" %d byte buffer supplied, %d byte buffer required\n", j
, i
);
1996 else if (strcmp(buf
, ans
))
1998 report("failed", fun
, re
, s
, nstr
, msg
, flags
, test
);
1999 quote(ans
, -1, test
|TEST_DELIMIT
);
2000 printf(" expected, ");
2001 quote(buf
, -1, test
|TEST_DELIMIT
);
2002 printf(" returned\n");
2010 if (!(flags
& REG_NOSUB
) && nsub
< 0 && *ans
== '(')
2012 for (p
= ans
; *p
; p
++)
2019 if (test
& TEST_IGNORE_OVER
)
2024 else if (nsub
!= preg
.re_nsub
)
2026 if (nsub
> preg
.re_nsub
)
2028 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2029 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, "OK", NiL
, 0, 0, skip
, level
, test
|TEST_DELIMIT
);
2032 report("re_nsub incorrect", fun
, re
, NiL
, -1, msg
, flags
, test
);
2033 printf("at least %d expected, %d returned\n", nsub
, preg
.re_nsub
);
2038 nsub
= preg
.re_nsub
;
2042 if (!(test
& (TEST_DECOMP
|TEST_SUB
)) && *ans
&& *ans
!= '(' && !streq(ans
, "OK") && !streq(ans
, "NOMATCH"))
2044 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2045 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, "OK", NiL
, 0, 0, skip
, level
, test
|TEST_DELIMIT
);
2046 else if (!(test
& TEST_LENIENT
))
2048 report("failed", fun
, re
, NiL
, -1, msg
, flags
, test
);
2049 printf("%s expected, OK returned\n", ans
);
2051 catchfree(&preg
, flags
, tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
);
2057 if (test
& TEST_LENIENT
)
2058 /* we'll let it go this time */;
2059 else if (!*ans
|| ans
[0]=='(' || cret
== REG_BADPAT
&& streq(ans
, "NOMATCH"))
2062 for (i
= 1; i
< elementsof(codes
); i
++)
2063 if (cret
==codes
[i
].code
)
2065 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2066 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, codes
[got
].name
, NiL
, 0, 0, skip
, level
, test
|TEST_DELIMIT
);
2069 report("failed", fun
, re
, NiL
, -1, msg
, flags
, test
);
2070 printf("%s returned: ", codes
[got
].name
);
2077 for (i
= 1; i
< elementsof(codes
); i
++)
2079 if (streq(ans
, codes
[i
].name
))
2081 if (cret
==codes
[i
].code
)
2086 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2087 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, codes
[got
].name
, NiL
, 0, 0, skip
, level
, test
|TEST_DELIMIT
);
2090 report("failed: invalid error code", NiL
, re
, NiL
, -1, msg
, flags
, test
);
2091 printf("%s expected, %s returned\n", ans
, codes
[got
].name
);
2094 else if (cret
!= codes
[expected
].code
&& cret
!= REG_BADPAT
)
2096 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2097 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, codes
[got
].name
, NiL
, 0, 0, skip
, level
, test
|TEST_DELIMIT
);
2098 else if (test
& TEST_IGNORE_ERROR
)
2102 report("should fail and did", fun
, re
, NiL
, -1, msg
, flags
, test
);
2103 printf("%s expected, %s returned: ", ans
, codes
[got
].name
);
2121 for (i
= 0; i
< elementsof(match
); i
++)
2122 match
[i
] = state
.NOMATCH
;
2127 eret
= regnexec(&preg
, s
, nexec
, nmatch
, match
, eflags
);
2133 if (!(test
& TEST_CATCH
))
2134 eret
= regexec(&preg
, s
, nmatch
, match
, eflags
);
2135 else if (!(eret
= setjmp(state
.gotcha
)))
2138 eret
= regexec(&preg
, s
, nmatch
, match
, eflags
);
2143 if ((test
& TEST_SUB
) && !eret
)
2146 if (!(test
& TEST_CATCH
))
2147 eret
= regsubexec(&preg
, s
, nmatch
, match
);
2148 else if (!(eret
= setjmp(state
.gotcha
)))
2151 eret
= regsubexec(&preg
, s
, nmatch
, match
);
2156 if (flags
& REG_NOSUB
)
2160 if (eret
!= REG_NOMATCH
|| !streq(ans
, "NOMATCH"))
2162 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2163 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, "NOMATCH", NiL
, 0, 0, skip
, level
, test
|TEST_DELIMIT
);
2166 report("REG_NOSUB failed", fun
, re
, s
, nstr
, msg
, flags
, test
);
2171 else if (streq(ans
, "NOMATCH"))
2173 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2174 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, NiL
, match
, nmatch
, nsub
, skip
, level
, test
|TEST_DELIMIT
);
2177 report("should fail and didn't", fun
, re
, s
, nstr
, msg
, flags
, test
);
2184 if (eret
!= REG_NOMATCH
|| !streq(ans
, "NOMATCH"))
2186 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2187 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, "NOMATCH", NiL
, 0, nsub
, skip
, level
, test
|TEST_DELIMIT
);
2190 report("failed", fun
, re
, s
, nstr
, msg
, flags
, test
);
2191 if (eret
!= REG_NOMATCH
)
2194 printf("expected: %s\n", ans
);
2200 else if (streq(ans
, "NOMATCH"))
2202 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2203 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, NiL
, match
, nmatch
, nsub
, skip
, level
, test
|TEST_DELIMIT
);
2206 report("should fail and didn't", fun
, re
, s
, nstr
, msg
, flags
, test
);
2207 matchprint(match
, nmatch
, nsub
, NiL
, test
);
2211 else if (test
& TEST_SUB
)
2213 p
= preg
.re_sub
->re_buf
;
2216 report("failed", fun
, re
, s
, nstr
, msg
, flags
, test
);
2217 quote(ans
, -1, test
|TEST_DELIMIT
);
2218 printf(" expected, ");
2219 quote(p
, -1, test
|TEST_DELIMIT
);
2220 printf(" returned\n");
2226 if (match
[0].rm_so
!= state
.NOMATCH
.rm_so
)
2228 if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2229 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
);
2232 report("failed: no match but match array assigned", NiL
, re
, s
, nstr
, msg
, flags
, test
);
2233 matchprint(match
, nmatch
, nsub
, NiL
, test
);
2237 else if (matchcheck(match
, nmatch
, nsub
, ans
, re
, s
, nstr
, flags
, test
))
2240 if (nexec
< 0 && !nonexec
)
2242 nexec
= nstr
>= 0 ? nstr
: strlen(s
);
2248 if (!(test
& (TEST_DECOMP
|TEST_SUB
|TEST_VERIFY
)) && !nonosub
)
2250 if (catchfree(&preg
, flags
, tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
))
2255 if (test
& (TEST_BASELINE
|TEST_PASS
|TEST_VERIFY
))
2256 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, NiL
, match
, nmatch
, nsub
, skip
, level
, test
|TEST_OK
);
2258 else if (test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
|TEST_QUERY
|TEST_SUMMARY
|TEST_VERIFY
))
2259 skip
= extract(tabs
, line
, re
, s
, ans
, msg
, NiL
, match
, nmatch
, nsub
, skip
, level
, test
|TEST_DELIMIT
);
2260 if (catchfree(&preg
, flags
, tabs
, line
, re
, s
, ans
, msg
, NiL
, NiL
, 0, 0, skip
, level
, test
))
2264 if (test
& TEST_SUMMARY
)
2265 printf("tests=%-4d errors=%-4d warnings=%-2d ignored=%-2d unspecified=%-2d signals=%d\n", testno
, state
.errors
, state
.warnings
, state
.ignored
, state
.unspecified
, state
.signals
);
2266 else if (!(test
& (TEST_ACTUAL
|TEST_BASELINE
|TEST_FAIL
|TEST_PASS
)))
2268 printf("TEST\t%s", unit
);
2270 printf(" %-.*s", subunitlen
, subunit
);
2271 printf(", %d test%s", testno
, testno
== 1 ? "" : "s");
2273 printf(", %d ignored mismatche%s", state
.ignored
, state
.ignored
== 1 ? "" : "s");
2275 printf(", %d warning%s", state
.warnings
, state
.warnings
== 1 ? "" : "s");
2276 if (state
.unspecified
)
2277 printf(", %d unspecified difference%s", state
.unspecified
, state
.unspecified
== 1 ? "" : "s");
2279 printf(", %d signal%s", state
.signals
, state
.signals
== 1 ? "" : "s");
2280 printf(", %d error%s\n", state
.errors
, state
.errors
== 1 ? "" : "s");