@+, @- readonly (was Re: @<punct> interpolating in "")
[p5sagit/p5-mst-13.2.git] / t / op / regmesg.t
CommitLineData
b45f050a 1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 unshift @INC, '../lib';
6}
7
8my $debug = 1;
9
10##
11## If the markers used are changed (search for "MARKER1" in regcomp.c),
12## update only these two variables, and leave the {#} in the @death/@warning
13## arrays below. The {#} is a meta-marker -- it marks where the marker should
14## go.
15
16my $marker1 = "<HERE<";
17my $marker2 = " <<<HERE<<< ";
18
19##
20## Key-value pairs of code/error of code that should have fatal errors.
21##
69f2e79d 22
23eval 'use Config'; # assume defaults if fail
24our %Config;
25my $inf_m1 = ($Config{reg_infty} || 32767) - 1;
26my $inf_p1 = $inf_m1 + 2;
b45f050a 27my @death =
28(
29 '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions at {#} mark in regex m/[[=foo=]{#}]/',
30
31 '/(?<= .*)/' => 'Variable length lookbehind not implemented at {#} mark in regex m/(?<= .*){#}/',
32
33 '/(?<= x{10000})/' => 'Lookbehind longer than 255 not implemented at {#} mark in regex m/(?<= x{10000}){#}/',
34
35 '/(?@)/' => 'Sequence (?@...) not implemented at {#} mark in regex m/(?@{#})/',
36
37 '/(?{ 1/' => 'Sequence (?{...}) not terminated or not {}-balanced at {#} mark in regex m/(?{{#} 1/',
38
39 '/(?(1x))/' => 'Switch condition not recognized at {#} mark in regex m/(?(1x{#}))/',
40
41 '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches at {#} mark in regex m/(?(1)x|y|{#}z)/',
42
43 '/(?(x)y|x)/' => 'Unknown switch condition (?(x) at {#} mark in regex m/(?({#}x)y|x)/',
44
45 '/(?/' => 'Sequence (? incomplete at {#} mark in regex m/(?{#}/',
46
47 '/(?;x/' => 'Sequence (?;...) not recognized at {#} mark in regex m/(?;{#}x/',
48 '/(?<;x/' => 'Sequence (?<;...) not recognized at {#} mark in regex m/(?<;{#}x/',
49
50 '/((x)/' => 'Unmatched ( at {#} mark in regex m/({#}(x)/',
51
69f2e79d 52 "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 at {#} mark in regex m/x{{#}$inf_p1}/",
b45f050a 53
54 '/x{3,1}/' => 'Can\'t do {n,m} with n > m at {#} mark in regex m/x{3,1}{#}/',
55
56 '/x**/' => 'Nested quantifiers at {#} mark in regex m/x**{#}/',
57
58 '/x[/' => 'Unmatched [ at {#} mark in regex m/x[{#}/',
59
60 '/*/', => 'Quantifier follows nothing at {#} mark in regex m/*{#}/',
61
62 '/\p{x/' => 'Missing right brace on \p{} at {#} mark in regex m/\p{{#}x/',
63
64 'use utf8; /[\p{x]/' => 'Missing right brace on \p{} at {#} mark in regex m/[\p{{#}x]/',
65
66 '/(x)\2/' => 'Reference to nonexistent group at {#} mark in regex m/(x)\2{#}/',
67
68 'my $m = chr(92); $m =~ $m', => 'Trailing \ in regex m/\/',
69
70 '/\x{1/' => 'Missing right brace on \x{} at {#} mark in regex m/\x{{#}1/',
71
72 'use utf8; /[\x{X]/' => 'Missing right brace on \x{} at {#} mark in regex m/[\x{{#}X]/',
73
74 '/\x{x}/' => 'Can\'t use \x{} without \'use utf8\' declaration at {#} mark in regex m/\x{x}{#}/',
75
76 '/[[:barf:]]/' => 'POSIX class [:barf:] unknown at {#} mark in regex m/[[:barf:]{#}]/',
77
78 '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions at {#} mark in regex m/[[=barf=]{#}]/',
79
80 '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions at {#} mark in regex m/[[.barf.]{#}]/',
81
82 '/[z-a]/' => 'Invalid [] range "z-a" at {#} mark in regex m/[z-a{#}]/',
83);
84
85##
86## Key-value pairs of code/error of code that should have non-fatal warnings.
87##
88@warning = (
89 "m/(?p{ 'a' })/" => "(?p{}) is deprecated - use (??{}) at {#} mark in regex m/(?p{#}{ 'a' })/",
90
91 'm/\b*/' => '\b* matches null string many times at {#} mark in regex m/\b*{#}/',
92
93 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes at {#} mark in regex m/[:blank:]{#}/',
94
95 "m'[\\y]'" => 'Unrecognized escape \y in character class passed through at {#} mark in regex m/[\y{#}]/',
96
97 'm/[a-\d]/' => 'False [] range "a-\d" at {#} mark in regex m/[a-\d{#}]/',
98 'm/[\w-x]/' => 'False [] range "\w-" at {#} mark in regex m/[\w-{#}x]/',
99 "m'\\y'" => 'Unrecognized escape \y passed through at {#} mark in regex m/\y{#}/',
100);
101
102my $total = (@death + @warning)/2;
103
104print "1..$total\n";
105
106my $count = 0;
107
108while (@death)
109{
110 $count++;
111 my $regex = shift @death;
112 my $result = shift @death;
113
b45f050a 114 $_ = "x";
115 eval $regex;
116 if (not $@) {
69f2e79d 117 print "# oops, $regex didn't die\nnot ok $count\n";
b45f050a 118 next;
119 }
120 chomp $@;
b45f050a 121 $result =~ s/{\#}/$marker1/;
122 $result =~ s/{\#}/$marker2/;
69f2e79d 123 if ($@ !~ /^\Q$result/) {
124 print "# For $regex, expected:\n# $result\n# Got:\n# $@\n#\nnot ";
b45f050a 125 }
126 print "ok $count\n";
127}
128
129
130our $warning;
131$SIG{__WARN__} = sub { $warning = shift };
132
133while (@warning)
134{
135 $count++;
136 my $regex = shift @warning;
137 my $result = shift @warning;
138
139 undef $warning;
140 $_ = "x";
141 eval $regex;
142
143 if ($@)
144 {
69f2e79d 145 print "# oops, $regex died with:\n#\t$@#\nnot ok $count\n";
b45f050a 146 next;
147 }
148
149 if (not $warning)
150 {
69f2e79d 151 print "# oops, $regex didn't generate a warning\nnot ok $count\n";
b45f050a 152 next;
153 }
b45f050a 154 $result =~ s/{\#}/$marker1/;
155 $result =~ s/{\#}/$marker2/;
69f2e79d 156 if ($warning !~ /^\Q$result/)
b45f050a 157 {
69f2e79d 158 print <<"EOM";
159# For $regex, expected:
160# $result
161# Got:
162# $warning
163#
164not ok $count
165EOM
b45f050a 166 next;
167 }
168 print "ok $count\n";
169}
170
171
172