Commit | Line | Data |
378cc40b |
1 | #!./perl |
2 | |
ad4f75a6 |
3 | # The tests are in a separate file 't/op/re_tests'. |
4 | # Each line in that file is a separate test. |
5 | # There are five columns, separated by tabs. |
6 | # |
7 | # Column 1 contains the pattern, optionally enclosed in C<''>. |
8 | # Modifiers can be put after the closing C<'>. |
9 | # |
10 | # Column 2 contains the string to be matched. |
11 | # |
12 | # Column 3 contains the expected result: |
13 | # y expect a match |
14 | # n expect no match |
15 | # c expect an error |
16 | # |
1b1626e4 |
17 | # Columns 4 and 5 are used only if column 3 contains C<y> or C<c>. |
ad4f75a6 |
18 | # |
19 | # Column 4 contains a string, usually C<$&>. |
20 | # |
21 | # Column 5 contains the expected result of double-quote |
c277df42 |
22 | # interpolating that string after the match, or start of error message. |
23 | # |
24 | # Columns 1, 2 and 5 are \n-interpolated. |
25 | |
26 | $iters = shift || 1; # Poor man performance suite, 10000 is OK. |
ad4f75a6 |
27 | |
fe14fcc3 |
28 | open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests') |
29 | || die "Can't open re_tests"; |
cfa4f241 |
30 | |
378cc40b |
31 | while (<TESTS>) { } |
32 | $numtests = $.; |
cfa4f241 |
33 | seek(TESTS,0,0); |
34 | $. = 0; |
378cc40b |
35 | |
1462b684 |
36 | $| = 1; |
c277df42 |
37 | print "1..$numtests\n# $iters iterations\n"; |
cfa4f241 |
38 | TEST: |
378cc40b |
39 | while (<TESTS>) { |
40 | ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_); |
41 | $input = join(':',$pat,$subject,$result,$repl,$expect); |
1b1626e4 |
42 | $pat = "'$pat'" unless $pat =~ /^[:']/; |
c277df42 |
43 | $pat =~ s/\\n/\n/g; |
44 | $subject =~ s/\\n/\n/g; |
45 | $expect =~ s/\\n/\n/g; |
46 | $expect = $repl = '-' if $skip_amp and $input =~ /\$[&\`\']/; |
ad4f75a6 |
47 | for $study ("", "study \$subject") { |
c277df42 |
48 | $c = $iters; |
49 | eval "$study; \$match = (\$subject =~ m$pat) while \$c--; \$got = \"$repl\";"; |
50 | chomp( $err = $@ ); |
cfa4f241 |
51 | if ($result eq 'c') { |
c277df42 |
52 | if ($err !~ m!^\Q$expect!) { print "not ok $. (compile) $input => `$err'\n"; next TEST } |
cfa4f241 |
53 | last; # no need to study a syntax error |
54 | } |
c277df42 |
55 | elsif ($@) { |
56 | print "not ok $. $input => error `$err'\n"; next TEST; |
57 | } |
cfa4f241 |
58 | elsif ($result eq 'n') { |
c277df42 |
59 | if ($match) { print "not ok $. ($study) $input => false positive\n"; next TEST } |
378cc40b |
60 | } |
61 | else { |
cfa4f241 |
62 | if (!$match || $got ne $expect) { |
c277df42 |
63 | print "not ok $. ($study) $input => `$got', match=$match\n"; |
cfa4f241 |
64 | next TEST; |
65 | } |
378cc40b |
66 | } |
67 | } |
cfa4f241 |
68 | print "ok $.\n"; |
378cc40b |
69 | } |
cfa4f241 |
70 | |
378cc40b |
71 | close(TESTS); |