3 # XXX known to leak scalars
4 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
6 # The tests are in a separate file 't/op/re_tests'.
7 # Each line in that file is a separate test.
8 # There are five columns, separated by tabs.
10 # Column 1 contains the pattern, optionally enclosed in C<''>.
11 # Modifiers can be put after the closing C<'>.
13 # Column 2 contains the string to be matched.
15 # Column 3 contains the expected result:
19 # B test exposes a known bug in Perl, should be skipped
20 # b test exposes a known bug in Perl, should be skipped if noamp
22 # Columns 4 and 5 are used only if column 3 contains C<y> or C<c>.
24 # Column 4 contains a string, usually C<$&>.
26 # Column 5 contains the expected result of double-quote
27 # interpolating that string after the match, or start of error message.
29 # Column 6, if present, contains a reason why the test is skipped.
30 # This is printed with "skipped", for harness to pick up.
32 # \n in the tests are interpolated, as are variables of the form ${\w+}.
34 # If you want to add a regular expression test that can't be expressed
35 # in this format, don't add it here: put it in op/pat.t instead.
42 $iters = shift || 1; # Poor man performance suite, 10000 is OK.
44 open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests') ||
45 die "Can't open re_tests";
52 $bang = sprintf "\\%03o", ord "!"; # \41 would not be portable.
53 $ffff = chr(0xff) x 2;
57 print "1..$numtests\n# $iters iterations\n";
62 ($pat, $subject, $result, $repl, $expect, $reason) = split(/\t/,$_,6);
63 $input = join(':',$pat,$subject,$result,$repl,$expect);
65 infty_subst(\$expect);
66 $pat = "'$pat'" unless $pat =~ /^[:']/;
67 $pat =~ s/(\$\{\w+\})/$1/eeg;
69 $subject =~ s/(\$\{\w+\})/$1/eeg;
70 $subject =~ s/\\n/\n/g;
71 $expect =~ s/(\$\{\w+\})/$1/eeg;
72 $expect =~ s/\\n/\n/g;
73 $expect = $repl = '-' if $skip_amp and $input =~ /\$[&\`\']/;
74 $skip = ($skip_amp ? ($result =~ s/B//i) : ($result =~ s/B//));
75 # Certain tests don't work with utf8 (the re_test should be in UTF8)
76 $skip = 1, $reason = 'utf8'
77 if ($^H &= ~0x00000008) && $pat =~ /\[:\^(alnum|print|word|ascii|xdigit):\]/;
78 $result =~ s/B//i unless $skip;
79 for $study ('', 'study \$subject') {
81 eval "$study; \$match = (\$subject =~ m$pat) while \$c--; \$got = \"$repl\";";
84 if ($err !~ m!^\Q$expect!) { print "not ok $. (compile) $input => `$err'\n"; next TEST }
85 last; # no need to study a syntax error
88 print "ok $. # skipped", length($reason) ? " $reason" : '', "\n";
92 print "not ok $. $input => error `$err'\n"; next TEST;
94 elsif ($result eq 'n') {
95 if ($match) { print "not ok $. ($study) $input => false positive\n"; next TEST }
98 if (!$match || $got ne $expect) {
99 print "not ok $. ($study) $input => `$got', match=$match\n";
109 sub infty_subst # Special-case substitution
110 { # of $reg_infty and friends
112 $$tp =~ s/,\$reg_infty_m}/,$reg_infty_m}/o;
113 $$tp =~ s/,\$reg_infty_p}/,$reg_infty_p}/o;
114 $$tp =~ s/,\$reg_infty}/,$reg_infty}/o;