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:
20 # Columns 4 and 5 are used only if column 3 contains C<y> or C<c>.
22 # Column 4 contains a string, usually C<$&>.
24 # Column 5 contains the expected result of double-quote
25 # interpolating that string after the match, or start of error message.
27 # \n in the tests are interpolated, as are variables of the form ${\w+}.
29 # If you want to add a regular expression test that can't be expressed
30 # in this format, don't add it here: put it in op/pat.t instead.
34 @INC = '../lib' if -d '../lib';
39 $iters = shift || 1; # Poor man performance suite, 10000 is OK.
41 open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests') ||
42 die "Can't open re_tests";
49 $bang = sprintf "\\%03o", ord "!"; # \41 would not be portable.
52 print "1..$numtests\n# $iters iterations\n";
57 ($pat, $subject, $result, $repl, $expect) = split(/\t/,$_);
58 $input = join(':',$pat,$subject,$result,$repl,$expect);
60 infty_subst(\$expect);
61 $pat = "'$pat'" unless $pat =~ /^[:']/;
63 $pat =~ s/(\$\{\w+\})/$1/eeg;
64 $subject =~ s/\\n/\n/g;
65 $expect =~ s/\\n/\n/g;
66 $expect = $repl = '-' if $skip_amp and $input =~ /\$[&\`\']/;
67 for $study ("", "study \$subject") {
69 eval "$study; \$match = (\$subject =~ m$pat) while \$c--; \$got = \"$repl\";";
72 if ($err !~ m!^\Q$expect!) { print "not ok $. (compile) $input => `$err'\n"; next TEST }
73 last; # no need to study a syntax error
76 print "not ok $. $input => error `$err'\n"; next TEST;
78 elsif ($result eq 'n') {
79 if ($match) { print "not ok $. ($study) $input => false positive\n"; next TEST }
82 if (!$match || $got ne $expect) {
83 print "not ok $. ($study) $input => `$got', match=$match\n";
93 sub infty_subst # Special-case substitution
94 { # of $reg_infty and friends
96 $$tp =~ s/,\$reg_infty_m}/,$reg_infty_m}/o;
97 $$tp =~ s/,\$reg_infty_p}/,$reg_infty_p}/o;
98 $$tp =~ s/,\$reg_infty}/,$reg_infty}/o;