Tweak to hints/machten.sh: stop t/lib/complex.t from failing
[p5sagit/p5-mst-13.2.git] / t / op / regexp.t
CommitLineData
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
22# interpolating that string after the match.
23
fe14fcc3 24open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
25 || die "Can't open re_tests";
cfa4f241 26
378cc40b 27while (<TESTS>) { }
28$numtests = $.;
cfa4f241 29seek(TESTS,0,0);
30$. = 0;
378cc40b 31
1462b684 32$| = 1;
cfa4f241 33print "1..$numtests\n";
34TEST:
378cc40b 35while (<TESTS>) {
36 ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
37 $input = join(':',$pat,$subject,$result,$repl,$expect);
1b1626e4 38 $pat = "'$pat'" unless $pat =~ /^[:']/;
ad4f75a6 39 for $study ("", "study \$subject") {
cfa4f241 40 eval "$study; \$match = (\$subject =~ m$pat); \$got = \"$repl\";";
41 if ($result eq 'c') {
1b1626e4 42 if ($@ !~ m!^\Q$expect!) { print "not ok $.\n"; next TEST }
cfa4f241 43 last; # no need to study a syntax error
44 }
45 elsif ($result eq 'n') {
46 if ($match) { print "not ok $. $input => $got\n"; next TEST }
378cc40b 47 }
48 else {
cfa4f241 49 if (!$match || $got ne $expect) {
50 print "not ok $. $input => $got\n";
51 next TEST;
52 }
378cc40b 53 }
54 }
cfa4f241 55 print "ok $.\n";
378cc40b 56}
cfa4f241 57
378cc40b 58close(TESTS);