Commit | Line | Data |
---|---|---|
b45f050a JF |
1 | #!./perl -w |
2 | ||
21adcf33 KW |
3 | $|=1; # outherwise things get mixed up in output |
4 | ||
b45f050a JF |
5 | BEGIN { |
6 | chdir 't' if -d 't'; | |
cb79f740 | 7 | require './test.pl'; |
624c42e2 | 8 | set_up_inc( qw '../lib ../ext/re' ); |
cb79f740 | 9 | eval 'require Config'; # assume defaults if this fails |
b45f050a JF |
10 | } |
11 | ||
624c42e2 N |
12 | skip_all_without_unicode_tables(); |
13 | ||
cb79f740 | 14 | use strict; |
c1d900c3 | 15 | use open qw(:utf8 :std); |
b45f050a | 16 | |
b1793c1a KW |
17 | # Kind of a kludge to mark warnings to be expected only if we are testing |
18 | # under "use re 'strict'" | |
19 | my $only_strict_marker = ':expected_only_under_strict'; | |
20 | ||
b45f050a | 21 | ## If the markers used are changed (search for "MARKER1" in regcomp.c), |
cb79f740 | 22 | ## update only these two regexs, and leave the {#} in the @death/@warning |
b45f050a JF |
23 | ## arrays below. The {#} is a meta-marker -- it marks where the marker should |
24 | ## go. | |
af01601c | 25 | |
b1793c1a KW |
26 | sub fixup_expect ($$) { |
27 | ||
28 | # Fixes up the expected results by inserting the boiler plate text. | |
29 | # Returns empty string if that is what is expected. Otherwise, handles | |
30 | # either a scalar, turning it into a single element array; or a ref to an | |
31 | # array, adjusting each element. If called in array context, returns an | |
32 | # array, otherwise the join of all elements. | |
33 | ||
34 | # The string $only_strict_marker will be removed from any expect line it | |
35 | # begins, and if $strict is not true, that expect line will be removed | |
36 | # from the output (hence won't be expected) | |
37 | ||
38 | my ($expect_ref, $strict) = @_; | |
63374c78 | 39 | return "" if $expect_ref eq ""; |
af01601c KW |
40 | |
41 | my @expect; | |
42 | if (ref $expect_ref) { | |
43 | @expect = @$expect_ref; | |
44 | } | |
45 | else { | |
46 | @expect = $expect_ref; | |
47 | } | |
48 | ||
b1793c1a | 49 | my @new_expect; |
af01601c | 50 | foreach my $element (@expect) { |
b1793c1a KW |
51 | $element =~ s/\{\#\}/in regex; marked by <-- HERE in/; |
52 | $element =~ s/\{\#\}/ <-- HERE /; | |
af01601c | 53 | $element .= " at "; |
b1793c1a KW |
54 | next if $element =~ s/ ^ $only_strict_marker \s* //x && ! $strict; |
55 | push @new_expect, $element; | |
af01601c | 56 | } |
b1793c1a | 57 | return wantarray ? @new_expect : join "", @new_expect; |
cb79f740 | 58 | } |
b45f050a | 59 | |
c1d900c3 | 60 | ## Because we don't "use utf8" in this file, we need to do some extra legwork |
b0e1d434 KW |
61 | ## for the utf8 tests: Prepend 'use utf8' to the pattern, and mark the strings |
62 | ## to check against as UTF-8, but for this all to work properly, the character | |
63 | ## 'ネ' (U+30CD) is required in each pattern somewhere as a marker. | |
4cabb89a BF |
64 | ## |
65 | ## This also creates a second variant of the tests to check if the | |
b0e1d434 KW |
66 | ## latin1 error messages are working correctly. Because we don't 'use utf8', |
67 | ## we can't tell if something is UTF-8 or Latin1, so you need the suffix | |
68 | ## '; no latin1' to not have the second variant. | |
4cabb89a BF |
69 | my $l1 = "\x{ef}"; |
70 | my $utf8 = "\x{30cd}"; | |
71 | utf8::encode($utf8); | |
72 | ||
c1d900c3 BF |
73 | sub mark_as_utf8 { |
74 | my @ret; | |
67cdf558 KW |
75 | for (my $i = 0; $i < @_; $i += 2) { |
76 | my $pat = $_[$i]; | |
77 | my $msg = $_[$i+1]; | |
4cabb89a BF |
78 | my $l1_pat = $pat =~ s/$utf8/$l1/gr; |
79 | my $l1_msg; | |
c1d900c3 | 80 | $pat = "use utf8; $pat"; |
b0e1d434 | 81 | |
c1d900c3 | 82 | if (ref $msg) { |
4cabb89a BF |
83 | $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ]; |
84 | @$msg = map { my $c = $_; utf8::decode($c); $c } @$msg; | |
c1d900c3 BF |
85 | } |
86 | else { | |
4cabb89a | 87 | $l1_msg = $msg =~ s/$utf8/$l1/gr; |
c1d900c3 BF |
88 | utf8::decode($msg); |
89 | } | |
90 | push @ret, $pat => $msg; | |
b0e1d434 | 91 | |
4cabb89a | 92 | push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/; |
c1d900c3 BF |
93 | } |
94 | return @ret; | |
95 | } | |
96 | ||
cb79f740 NC |
97 | my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1; |
98 | my $inf_p1 = $inf_m1 + 2; | |
b45f050a | 99 | |
c877af1b KW |
100 | my $B_hex = sprintf("\\x%02X", ord "B"); |
101 | my $low_mixed_alpha = ('A' lt 'a') ? 'A' : 'a'; | |
102 | my $high_mixed_alpha = ('A' lt 'a') ? 'a' : 'A'; | |
103 | my $low_mixed_digit = ('A' lt '0') ? 'A' : '0'; | |
104 | my $high_mixed_digit = ('A' lt '0') ? '0' : 'A'; | |
105 | ||
acdfc3b6 KW |
106 | my $colon_hex = sprintf "%02X", ord(":"); |
107 | my $tab_hex = sprintf "%02X", ord("\t"); | |
108 | ||
d30277c7 KW |
109 | # Key-value pairs of strings eval'd as patterns => warn/error messages that |
110 | # they should generate. In some cases, the value is an array of multiple | |
111 | # messages. Some groups have the message(s) be default on; others, default | |
112 | # off. This can be overridden on an individual key basis by preceding the | |
113 | # pattern string with either 'default_on' or 'default_off' | |
114 | # | |
115 | # The first set are those that should be fatal errors. | |
116 | ||
b45f050a JF |
117 | my @death = |
118 | ( | |
6d24e9d4 | 119 | '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/', |
b45f050a | 120 | |
58e23c8d | 121 | '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/', |
b45f050a | 122 | |
58e23c8d | 123 | '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/', |
b45f050a | 124 | |
6d24e9d4 | 125 | '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/', |
b45f050a | 126 | |
9da1dd8f | 127 | '/(?{ 1/' => 'Missing right curly or square bracket', |
b45f050a | 128 | |
6d24e9d4 | 129 | '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/', |
311cc1ad | 130 | '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/', |
b45f050a | 131 | |
8fb0127d YO |
132 | '/(?(1)/' => 'Switch (?(condition)... not terminated {#} m/(?(1){#}/', |
133 | '/(?(1)x/' => 'Switch (?(condition)... not terminated {#} m/(?(1)x{#}/', | |
134 | '/(?(1)x|y/' => 'Switch (?(condition)... not terminated {#} m/(?(1)x|y{#}/', | |
6d24e9d4 | 135 | '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/', |
b45f050a | 136 | |
c1d900c3 | 137 | '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/', |
10380cb3 FC |
138 | '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/', |
139 | '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/', | |
b45f050a | 140 | |
6d24e9d4 | 141 | '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/', |
b45f050a | 142 | |
6d24e9d4 KW |
143 | '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/', |
144 | '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/', | |
145 | '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/', | |
146 | '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/', | |
147 | '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/', | |
148 | '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/', | |
149 | '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/', | |
150 | '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/', | |
151 | '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/', | |
152 | '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/', | |
153 | '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/', | |
154 | '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/', | |
155 | '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/', | |
156 | '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/', | |
157 | '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/', | |
158 | '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/', | |
159 | '/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/', | |
160 | '/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/', | |
161 | '/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/', | |
162 | '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/', | |
cc74c5bd | 163 | |
6d24e9d4 | 164 | '/((x)/' => 'Unmatched ( {#} m/({#}(x)/', |
77eddfe1 | 165 | '/{(}/' => 'Unmatched ( {#} m/{({#}}/', # [perl #127599] |
b45f050a | 166 | |
6d24e9d4 | 167 | "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/", |
b45f050a | 168 | |
b45f050a | 169 | |
6d24e9d4 | 170 | '/x**/' => 'Nested quantifiers {#} m/x**{#}/', |
b45f050a | 171 | |
6d24e9d4 | 172 | '/x[/' => 'Unmatched [ {#} m/x[{#}/', |
b45f050a | 173 | |
6d24e9d4 | 174 | '/*/', => 'Quantifier follows nothing {#} m/*{#}/', |
b45f050a | 175 | |
6d24e9d4 | 176 | '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/', |
b45f050a | 177 | |
6d24e9d4 | 178 | '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/', |
b45f050a | 179 | |
6d24e9d4 | 180 | '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/', |
b45f050a | 181 | |
779fedd7 | 182 | '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/', |
76cccc4d KW |
183 | '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/', |
184 | ||
40809656 | 185 | 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/', |
b45f050a | 186 | |
6d24e9d4 KW |
187 | '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/', |
188 | '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/', | |
189 | ||
190 | '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/', | |
191 | '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/', | |
192 | ||
193 | '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/', | |
194 | '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/', | |
195 | ||
196 | '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/', | |
197 | '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/', | |
198 | ||
199 | '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/', | |
200 | ||
201 | '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/', | |
202 | ||
203 | '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/', | |
204 | ||
205 | '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/', | |
206 | ||
c30c479a | 207 | '/\p/' => 'Empty \p {#} m/\p{#}/', |
856d91b3 KW |
208 | '/\P/' => 'Empty \P {#} m/\P{#}/', |
209 | '/\p{}/' => 'Empty \p{} {#} m/\p{{#}}/', | |
6d24e9d4 | 210 | '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/', |
64935bc6 KW |
211 | |
212 | '/a\b{cde/' => 'Missing right brace on \b{} {#} m/a\b{{#}cde/', | |
213 | '/a\B{cde/' => 'Missing right brace on \B{} {#} m/a\B{{#}cde/', | |
214 | ||
215 | '/\b{}/' => 'Empty \b{} {#} m/\b{}{#}/', | |
216 | '/\B{}/' => 'Empty \B{} {#} m/\B{}{#}/', | |
217 | ||
218 | '/\b{gc}/' => "'gc' is an unknown bound type {#} m/\\b{gc{#}}/", | |
219 | '/\B{gc}/' => "'gc' is an unknown bound type {#} m/\\B{gc{#}}/", | |
220 | ||
46d34d0e KW |
221 | '/(?[[[::]]])/' => "Syntax error in (?[...]) in regex m/(?[[[::]]])/", |
222 | '/(?[[[:w:]]])/' => "Syntax error in (?[...]) in regex m/(?[[[:w:]]])/", | |
223 | '/(?[[:w:]])/' => "", | |
d8387e4d KW |
224 | '/([.].*)[.]/' => "", # [perl #127582] |
225 | '/[.].*[.]/' => "", # [perl #127604] | |
6d24e9d4 | 226 | '/(?[a])/' => 'Unexpected character {#} m/(?[a{#}])/', |
6d24e9d4 KW |
227 | '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/', |
228 | '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/', | |
229 | '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/', | |
230 | '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/', | |
231 | '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/', | |
232 | '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/', | |
233 | '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/', | |
234 | '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/', | |
235 | '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/', | |
236 | '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/', | |
237 | '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/', | |
238 | '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/', | |
239 | '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/', | |
c333712c KW |
240 | '/(?[ ( ) ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ ( ){#} ])/', |
241 | '/(?[[0]+()+])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[[0]+(){#}+])/', | |
29f52644 KW |
242 | '/(?[ \p{foo} ])/' => 'Can\'t find Unicode property definition "foo" {#} m/(?[ \p{foo}{#} ])/', |
243 | '/(?[ \p{ foo = bar } ])/' => 'Can\'t find Unicode property definition "foo = bar" {#} m/(?[ \p{ foo = bar }{#} ])/', | |
6d24e9d4 | 244 | '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/', |
3f4fde43 KW |
245 | '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/', |
246 | '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/', | |
247 | '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/', | |
248 | '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/', | |
249 | '/(?[ \t + \e # This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # This was supposed to be a comment ])/', | |
6d24e9d4 KW |
250 | '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/', |
251 | 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/', | |
252 | 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/', | |
253 | 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/', | |
254 | 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/', | |
8f0cd35a | 255 | 'm/(?[[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/(?[[^\N{U+100.300{#}}]])/', |
b5864679 KW |
256 | 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/', |
257 | 'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/', | |
6d24e9d4 KW |
258 | 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/', |
259 | 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/', | |
260 | 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/', | |
261 | 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/', | |
262 | 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/', | |
263 | 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/', | |
264 | 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/', | |
f1e1b256 YO |
265 | 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/', |
266 | 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/', | |
267 | 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/', | |
07ea66ee FC |
268 | 'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/', |
269 | 'm/(?&a/' => 'Sequence (?&... not terminated {#} m/(?&a{#}/', | |
75839571 FC |
270 | 'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/', |
271 | "m/(?'/" => "Sequence (?'... not terminated {#} m/(?'{#}/", | |
272 | "m/(?</" => "Sequence (?<... not terminated {#} m/(?<{#}/", | |
273 | 'm/(?&/' => 'Sequence (?&... not terminated {#} m/(?&{#}/', | |
274 | 'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/', | |
275 | "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/", | |
276 | 'm/\g{/' => 'Sequence \g{... not terminated {#} m/\g{{#}/', | |
277 | 'm/\k</' => 'Sequence \k<... not terminated {#} m/\k<{#}/', | |
9b8f4e92 | 278 | 'm/\cß/' => "Character following \"\\c\" must be printable ASCII", |
cd209d9d KW |
279 | '/((?# This is a comment in the middle of a token)?:foo)/' => 'In \'(?...)\', the \'(\' and \'?\' must be adjacent {#} m/((?# This is a comment in the middle of a token)?{#}:foo)/', |
280 | '/((?# This is a comment in the middle of a token)*FAIL)/' => 'In \'(*VERB...)\', the \'(\' and \'*\' must be adjacent {#} m/((?# This is a comment in the middle of a token)*{#}FAIL)/', | |
5a55ed33 | 281 | '/(?[\ &!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ &!{#}])/', # [perl #126180] |
f4b6841f KW |
282 | '/(?[\ +!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ +!{#}])/', # [perl #126180] |
283 | '/(?[\ -!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ -!{#}])/', # [perl #126180] | |
284 | '/(?[\ ^!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ ^!{#}])/', # [perl #126180] | |
285 | '/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/', # [perl #126180] | |
c333712c | 286 | '/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[(){#}-!])/', # [perl #126204] |
174c9902 | 287 | '/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/', # [perl #126404] |
8e84dec2 KW |
288 | '/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/', |
289 | '/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/', | |
290 | '/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/', | |
77c8f263 KW |
291 | '/abc/xix' => "", |
292 | '/(?xmsixp:abc)/' => "", | |
293 | '/(?xmsixp)abc/' => "", | |
294 | '/(?xxxx:abc)/' => "", | |
f2e32b2c | 295 | '/(?<=/' => 'Sequence (?... not terminated {#} m/(?<={#}/', # [perl #128170] |
60108b47 | 296 | |
b45f050a | 297 | ); |
c1d900c3 | 298 | |
67cdf558 KW |
299 | # These are messages that are warnings when not strict; death under 'use re |
300 | # "strict". See comment before @warnings as to why some have a \x{100} in | |
301 | # them. This array has 3 elements per construct. [0] is the regex to use; | |
302 | # [1] is the message under no strict, and [2] is under strict. | |
303 | my @death_only_under_strict = ( | |
304 | 'm/\xABC/' => "", | |
305 | => 'Use \x{...} for more than two hex characters {#} m/\xABC{#}/', | |
306 | 'm/[\xABC]/' => "", | |
307 | => 'Use \x{...} for more than two hex characters {#} m/[\xABC{#}]/', | |
308 | ||
309 | # XXX This is a confusing error message. The G isn't ignored; it just | |
310 | # terminates the \x. Also some messages below are missing the <-- HERE, | |
311 | # aren't all category 'regexp'. (Hence we have to turn off 'digit' | |
312 | # messages as well below) | |
313 | 'm/\xAG/' => 'Illegal hexadecimal digit \'G\' ignored', | |
314 | => 'Non-hex character {#} m/\xAG{#}/', | |
315 | 'm/[\xAG]/' => 'Illegal hexadecimal digit \'G\' ignored', | |
316 | => 'Non-hex character {#} m/[\xAG{#}]/', | |
317 | 'm/\o{789}/' => 'Non-octal character \'8\'. Resolved as "\o{7}"', | |
318 | => 'Non-octal character {#} m/\o{78{#}9}/', | |
319 | 'm/[\o{789}]/' => 'Non-octal character \'8\'. Resolved as "\o{7}"', | |
320 | => 'Non-octal character {#} m/[\o{78{#}9}]/', | |
321 | 'm/\x{}/' => "", | |
322 | => 'Number with no digits {#} m/\x{}{#}/', | |
323 | 'm/[\x{}]/' => "", | |
324 | => 'Number with no digits {#} m/[\x{}{#}]/', | |
325 | 'm/\x{ABCDEFG}/' => 'Illegal hexadecimal digit \'G\' ignored', | |
326 | => 'Non-hex character {#} m/\x{ABCDEFG{#}}/', | |
327 | 'm/[\x{ABCDEFG}]/' => 'Illegal hexadecimal digit \'G\' ignored', | |
328 | => 'Non-hex character {#} m/[\x{ABCDEFG{#}}]/', | |
67cdf558 KW |
329 | "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/', |
330 | => 'Unrecognized escape \y in character class {#} m/[\y{#}]\x{100}/', | |
331 | 'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
332 | => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
333 | 'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/', | |
334 | => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/', | |
335 | 'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/', | |
336 | => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/', | |
337 | 'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/', | |
338 | => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/', | |
339 | 'm/[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]/' => 'Using just the first character returned by \N{} in character class {#} m/[^\N{U+100.300}{#}]/', | |
340 | => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[^\N{U+100.300{#}}]/', | |
341 | 'm/[\x03-\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]/' => 'Using just the first character returned by \N{} in character class {#} m/[\x03-\N{U+100.300}{#}]/', | |
342 | => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\x03-\N{U+100.300{#}}]/', | |
343 | 'm/[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}-\x{10FFFF}]/' => 'Using just the first character returned by \N{} in character class {#} m/[\N{U+100.300}{#}-\x{10FFFF}]/', | |
344 | => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\N{U+100.300{#}}-\x{10FFFF}]/', | |
345 | '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/', | |
346 | => 'Need exactly 3 octal digits {#} m/[\08{#}]/', | |
347 | '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/', | |
348 | => 'Need exactly 3 octal digits {#} m/[\018{#}]/', | |
349 | '/[\_\0]/' => "", | |
350 | => 'Need exactly 3 octal digits {#} m/[\_\0]{#}/', | |
351 | '/[\07]/' => "", | |
352 | => 'Need exactly 3 octal digits {#} m/[\07]{#}/', | |
353 | '/[\0005]/' => "", | |
354 | => 'Need exactly 3 octal digits {#} m/[\0005]{#}/', | |
355 | '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/', | |
356 | 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/', | |
357 | ], | |
358 | => 'Unrecognized escape \8 in character class {#} m/[\8{#}\9]\x{100}/', | |
359 | '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
360 | => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
361 | '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/', | |
362 | => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/', | |
363 | '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/', | |
364 | => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/', | |
365 | '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/', | |
366 | => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/', | |
367 | '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/', | |
368 | => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/', | |
369 | '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/', | |
370 | => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/', | |
371 | '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/', | |
372 | => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/', | |
373 | '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/', | |
374 | => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/', | |
375 | '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/', | |
376 | => 'Unrecognized escape \z in character class {#} m/[a\z{#}b]\x{100}/', | |
53fdf12a KW |
377 | 'default_on/:{4,a}/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/:{{#}4,a}/', |
378 | => 'Unescaped left brace in regex is illegal here {#} m/:{{#}4,a}/', | |
379 | 'default_on/xa{3\,4}y/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/xa{{#}3\,4}y/', | |
380 | => 'Unescaped left brace in regex is illegal here {#} m/xa{{#}3\,4}y/', | |
381 | 'default_on/\\${[^\\}]*}/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/\\${{#}[^\\}]*}/', | |
382 | => 'Unescaped left brace in regex is illegal here {#} m/\\${{#}[^\\}]*}/', | |
67cdf558 KW |
383 | ); |
384 | ||
b0e1d434 | 385 | # These need the character 'ネ' as a marker for mark_as_utf8() |
c1d900c3 | 386 | my @death_utf8 = mark_as_utf8( |
c1d900c3 BF |
387 | '/ネ(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/', |
388 | ||
389 | '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/', | |
390 | ||
391 | '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/', | |
392 | ||
476afc4b | 393 | '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/', |
c1d900c3 BF |
394 | |
395 | '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/', | |
396 | ||
397 | '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/', | |
398 | ||
399 | '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/', | |
400 | ||
401 | '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/', | |
402 | '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/', | |
403 | '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/', | |
404 | '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/', | |
405 | '/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/', | |
406 | '/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/', | |
407 | '/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/', | |
408 | ||
409 | '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/', | |
410 | ||
411 | "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/", | |
412 | ||
413 | ||
414 | '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/', | |
415 | ||
416 | '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/', | |
417 | ||
418 | '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/', | |
419 | ||
420 | '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/', | |
421 | ||
422 | '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/', | |
423 | ||
4cabb89a | 424 | '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/', |
c1d900c3 BF |
425 | |
426 | 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/', | |
427 | ||
428 | '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/', | |
429 | '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/', | |
430 | '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/', | |
431 | ||
432 | '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/', | |
46d34d0e | 433 | '/ネ[[:ネ:]]ネ/' => "", |
c1d900c3 | 434 | |
c1d900c3 BF |
435 | '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/', |
436 | ||
437 | '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/', | |
438 | ||
46d34d0e KW |
439 | '/ネ(?[[[:ネ]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ]]])ネ/", |
440 | '/ネ(?[[[:ネ: ])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ: ])ネ/", | |
441 | '/ネ(?[[[::]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[::]]])ネ/", | |
442 | '/ネ(?[[[:ネ:]]])ネ/' => "Syntax error in (?[...]) in regex m/ネ(?[[[:ネ:]]])ネ/", | |
443 | '/ネ(?[[:ネ:]])ネ/' => "", | |
c1d900c3 | 444 | '/ネ(?[ネ])ネ/' => 'Unexpected character {#} m/ネ(?[ネ{#}])ネ/', |
c1d900c3 BF |
445 | '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/', |
446 | '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/', | |
447 | '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/', | |
448 | '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/', | |
449 | '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/', | |
450 | '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/', | |
451 | '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/', | |
452 | '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/', | |
29f52644 KW |
453 | '/(?[ \p{ネ} ])/' => 'Can\'t find Unicode property definition "ネ" {#} m/(?[ \p{ネ}{#} ])/', |
454 | '/(?[ \p{ ネ = bar } ])/' => 'Can\'t find Unicode property definition "ネ = bar" {#} m/(?[ \p{ ネ = bar }{#} ])/', | |
c1d900c3 BF |
455 | '/ネ(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/ネ(?[ \t ]/', |
456 | '/(?[ \t + \e # ネ This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # ネ This was supposed to be a comment ])/', | |
9b8f4e92 KW |
457 | 'm/(*ネ)ネ/' => q<Unknown verb pattern 'ネ' {#} m/(*ネ){#}ネ/>, |
458 | '/\cネ/' => "Character following \"\\c\" must be printable ASCII", | |
64935bc6 KW |
459 | '/\b{ネ}/' => "'ネ' is an unknown bound type {#} m/\\b{ネ{#}}/", |
460 | '/\B{ネ}/' => "'ネ' is an unknown bound type {#} m/\\B{ネ{#}}/", | |
c1d900c3 BF |
461 | ); |
462 | push @death, @death_utf8; | |
463 | ||
67cdf558 KW |
464 | my @death_utf8_only_under_strict = ( |
465 | "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/', | |
466 | => 'Unrecognized escape \y in character class {#} m/ネ[\y{#}]ネ/', | |
467 | 'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/', | |
468 | => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/', | |
469 | 'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/', | |
470 | => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/', | |
471 | 'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/', | |
472 | => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/', | |
473 | '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/', | |
474 | => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/', | |
475 | '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/', | |
476 | => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/', | |
477 | '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/', | |
478 | => 'Unrecognized escape \z in character class {#} m/ネ[a\z{#}b]ネ/', | |
479 | ); | |
902994e4 | 480 | # Tests involving a user-defined charnames translator are in pat_advanced.t |
b45f050a | 481 | |
af01601c KW |
482 | # In the following arrays of warnings, the value can be an array of things to |
483 | # expect. If the empty string, it means no warning should be raised. | |
484 | ||
6d24e9d4 | 485 | |
499333dc KW |
486 | # Key-value pairs of code/error of code that should have non-fatal regexp |
487 | # warnings. Most currently have \x{100} appended to them to force them to be | |
488 | # upgraded to UTF-8, and the first pass restarted. Previously this would | |
489 | # cause some warnings to be output twice. This tests that that behavior has | |
490 | # been fixed. | |
6d24e9d4 | 491 | |
499333dc KW |
492 | my @warning = ( |
493 | 'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/', | |
64935bc6 KW |
494 | '/\b{g}/a' => "Using /u for '\\b{g}' instead of /a {#} m/\\b{g}{#}/", |
495 | '/\B{gcb}/a' => "Using /u for '\\B{gcb}' instead of /a {#} m/\\B{gcb}{#}/", | |
499333dc | 496 | 'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/', |
7dbd4c44 | 497 | 'm/[[:cntrl:]][:^ascii:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[[:cntrl:]][:^ascii:]{#}\x{100}/', |
46d34d0e KW |
498 | 'm/[[:ascii]]\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/[[:ascii{#}]]\\x{100}/", |
499 | 'm/(?[[:word]])\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/(?[[:word{#}]])\\x{100}/", | |
499333dc | 500 | "m'\\y\\x{100}'" => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/', |
6d24e9d4 KW |
501 | '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/', |
502 | '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/', | |
503 | '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/', | |
6d24e9d4 KW |
504 | '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/', |
505 | 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/', | |
506 | '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/', | |
499333dc | 507 | |
e1729dc6 FC |
508 | # These two tests do not include the marker, because regcomp.c no |
509 | # longer knows where it goes by the time this warning is emitted. | |
510 | # See [perl #122680] regcomp warning gives wrong position of | |
499333dc | 511 | # problem. |
e1729dc6 FC |
512 | '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/', |
513 | '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/', | |
499333dc | 514 | |
63fbd1cb | 515 | '/\_/' => "", |
63fbd1cb | 516 | '/[\006]/' => "", |
499333dc | 517 | '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/', |
46d34d0e KW |
518 | '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:zog:]{#}\x{100}/', |
519 | '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes (but this one isn\'t implemented) {#} m/[.zog.]{#}\x{100}/', | |
63fbd1cb | 520 | '/[a-b]/' => "", |
499333dc KW |
521 | '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/', |
522 | '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/', | |
523 | '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/', | |
524 | '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/', | |
525 | '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/', | |
526 | '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/', | |
527 | '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/', | |
528 | 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/', | |
63fbd1cb | 529 | ], |
499333dc KW |
530 | '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/', |
531 | 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/', | |
63fbd1cb KW |
532 | ], |
533 | # (?c) means (?g) error won't be thrown | |
499333dc KW |
534 | '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/', |
535 | 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/', | |
63fbd1cb | 536 | ], |
499333dc KW |
537 | '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/', |
538 | 'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/', | |
539 | 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/', | |
63fbd1cb | 540 | ], |
499333dc | 541 | '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/', |
c877af1b | 542 | "/(?[ [ % - % ] ])/" => "", |
d4360efa S |
543 | "/(?[ [ : - \\x$colon_hex ] ])\\x{100}/" => "\": - \\x$colon_hex \" is more clearly written simply as \":\" {#} m/(?[ [ : - \\x$colon_hex {#}] ])\\x{100}/", |
544 | "/(?[ [ \\x$colon_hex - : ] ])\\x{100}/" => "\"\\x$colon_hex\ - : \" is more clearly written simply as \":\" {#} m/(?[ [ \\x$colon_hex - : {#}] ])\\x{100}/", | |
545 | "/(?[ [ \\t - \\x$tab_hex ] ])\\x{100}/" => "\"\\t - \\x$tab_hex \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\t - \\x$tab_hex {#}] ])\\x{100}/", | |
546 | "/(?[ [ \\x$tab_hex - \\t ] ])\\x{100}/" => "\"\\x$tab_hex\ - \\t \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\x$tab_hex - \\t {#}] ])\\x{100}/", | |
c877af1b KW |
547 | "/(?[ [ $B_hex - C ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $B_hex - C {#}] ])/", |
548 | "/(?[ [ A - $B_hex ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ A - $B_hex {#}] ])/", | |
549 | "/(?[ [ $low_mixed_alpha - $high_mixed_alpha ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $low_mixed_alpha - $high_mixed_alpha {#}] ])/", | |
550 | "/(?[ [ $low_mixed_digit - $high_mixed_digit ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $low_mixed_digit - $high_mixed_digit {#}] ])/", | |
46d34d0e KW |
551 | "/[alnum]/" => "", |
552 | "/[^alnum]/" => "", | |
553 | '/[:blank]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:blank{#}]\x{100}/', | |
554 | '/[[:digit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:digit{#}]]\x{100}/', # [perl # 8904] | |
555 | '/[[:digit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:digit:{#}foo]\x{100}/', | |
556 | '/[[:di#it:foo]\x{100}/x' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:di#it:{#}foo]\x{100}/', | |
557 | '/[[:dgit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:dgit{#}]]\x{100}/', | |
558 | '/[[:dgit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:dgit:{#}foo]\x{100}/', | |
559 | '/[[:dgt]]\x{100}/' => "", # Far enough away from a real class to not be recognized as one | |
560 | '/[[:dgt:foo]\x{100}/' => "", | |
561 | '/[[:DIGIT]]\x{100}/' => [ 'Assuming NOT a POSIX class since the name must be all lowercase letters {#} m/[[:DIGIT{#}]]\x{100}/', | |
562 | 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:DIGIT{#}]]\x{100}/', | |
563 | ], | |
564 | '/[[digit]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}digit]\x{100}/', | |
565 | 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[digit{#}]\x{100}/', | |
566 | ], | |
567 | '/[[alpha]]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}alpha]]\x{100}/', | |
568 | 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[alpha{#}]]\x{100}/', | |
569 | ], | |
570 | '/[[^word]\x{100}/' => [ 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[^{#}word]\x{100}/', | |
571 | 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[^{#}word]\x{100}/', | |
572 | 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[^word{#}]\x{100}/', | |
573 | ], | |
574 | '/[[ ^ : x d i g i t : ] ]\x{100}/' => [ 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ {#}^ : x d i g i t : ] ]\x{100}/', | |
575 | 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[ ^{#} : x d i g i t : ] ]\x{100}/', | |
576 | 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ {#}: x d i g i t : ] ]\x{100}/', | |
577 | 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ : {#}x d i g i t : ] ]\x{100}/', | |
578 | 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ : x d i g i t : ]{#} ]\x{100}/', | |
a4368cc3 | 579 | $only_strict_marker . 'Unescaped literal \']\' {#} m/[[ ^ : x d i g i t : ] ]{#}\x{100}/', |
46d34d0e KW |
580 | ], |
581 | '/[foo:lower:]]\x{100}/' => 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#}:lower:]]\x{100}/', | |
582 | '/[[;upper;]]\x{100}/' => [ 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;{#}upper;]]\x{100}/', | |
583 | 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;upper;]{#}]\x{100}/', | |
584 | ], | |
585 | '/[foo;punct;]]\x{100}/' => [ 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#};punct;]]\x{100}/', | |
586 | 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;{#}punct;]]\x{100}/', | |
587 | 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;punct;]{#}]\x{100}/', | |
588 | ], | |
d730a801 YO |
589 | '/[][[:alpha:]]/' => "", # [perl #127581] |
590 | '/[][[:alpha:]\\@\\\\^_?]/' => "", # [perl #131522] | |
499333dc | 591 | ); # See comments before this for why '\x{100}' is generally needed |
6fe2934b | 592 | |
b0e1d434 | 593 | # These need the character 'ネ' as a marker for mark_as_utf8() |
c1d900c3 BF |
594 | my @warnings_utf8 = mark_as_utf8( |
595 | 'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/', | |
596 | '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/', | |
46d34d0e | 597 | 'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/ネ[:foo:]{#}ネ/', |
b0e1d434 | 598 | '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/', |
c1d900c3 BF |
599 | '/utf8 ネ (?ogc) ネ/' => [ |
600 | 'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/', | |
601 | 'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/', | |
602 | 'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/', | |
603 | ], | |
604 | ||
605 | ); | |
606 | ||
607 | push @warning, @warnings_utf8; | |
608 | ||
63374c78 | 609 | my @warning_only_under_strict = ( |
b927b7e9 KW |
610 | '/[\N{U+00}-\x01]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+00}-\x01{#}]\x{100}/', |
611 | '/[\x00-\N{SOH}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\x00-\N{U+01}{#}]\x{100}/', | |
612 | '/[\N{DEL}-\o{377}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\o{377}{#}]\x{100}/', | |
613 | '/[\o{0}-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\o{0}-\N{U+01}{#}]\x{100}/', | |
614 | '/[\000-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\000-\N{U+01}{#}]\x{100}/', | |
615 | '/[\N{DEL}-\377]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\377{#}]\x{100}/', | |
c877af1b KW |
616 | '/[\N{U+00}-A]\x{100}/' => 'Ranges of ASCII printables should be some subset of "0-9", "A-Z", or "a-z" {#} m/[\N{U+00}-A{#}]\x{100}/', |
617 | '/[a-\N{U+FF}]\x{100}/' => 'Ranges of ASCII printables should be some subset of "0-9", "A-Z", or "a-z" {#} m/[a-\N{U+FF}{#}]\x{100}/', | |
b927b7e9 KW |
618 | '/[\N{U+00}-\a]\x{100}/' => "", |
619 | '/[\a-\N{U+FF}]\x{100}/' => "", | |
620 | '/[\N{U+FF}-\x{100}]/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+FF}-\x{100}{#}]/', | |
621 | '/[\N{U+100}-\x{101}]/' => "", | |
c877af1b | 622 | "/[%-%]/" => "", |
d4360efa S |
623 | "/[:-\\x$colon_hex]\\x{100}/" => "\":-\\x$colon_hex\" is more clearly written simply as \":\" {#} m/[:-\\x$colon_hex\{#}]\\x{100}/", |
624 | "/[\\x$colon_hex-:]\\x{100}/" => "\"\\x$colon_hex-:\" is more clearly written simply as \":\" {#} m/[\\x$colon_hex\-:{#}]\\x{100}/", | |
625 | "/[\\t-\\x$tab_hex]\\x{100}/" => "\"\\t-\\x$tab_hex\" is more clearly written simply as \"\\t\" {#} m/[\\t-\\x$tab_hex\{#}]\\x{100}/", | |
626 | "/[\\x$tab_hex-\\t]\\x{100}/" => "\"\\x$tab_hex-\\t\" is more clearly written simply as \"\\t\" {#} m/[\\x$tab_hex\-\\t{#}]\\x{100}/", | |
c877af1b KW |
627 | "/[$B_hex-C]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$B_hex-C{#}]/", |
628 | "/[A-$B_hex]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[A-$B_hex\{#}]/", | |
629 | "/[$low_mixed_alpha-$high_mixed_alpha]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_alpha-$high_mixed_alpha\{#}]/", | |
630 | "/[$low_mixed_digit-$high_mixed_digit]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_digit-$high_mixed_digit\{#}]/", | |
a4368cc3 KW |
631 | '/\b<GCB}/' => 'Unescaped literal \'}\' {#} m/\b<GCB}{#}/', |
632 | '/[ ]def]/' => 'Unescaped literal \']\' {#} m/[ ]def]{#}/', | |
c877af1b KW |
633 | ); |
634 | ||
635 | my @warning_utf8_only_under_strict = mark_as_utf8( | |
636 | '/ネ[᪉-᪐]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᪉-᪐{#}]/", | |
637 | '/ネ(?[ [ ᪉ - ᪐ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᪉ - ᪐ {#}] ])/", | |
638 | '/ネ[᧙-᧚]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᧙-᧚{#}]/", | |
639 | '/ネ(?[ [ ᧙ - ᧚ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᧙ - ᧚ {#}] ])/", | |
8bafd282 KW |
640 | '/ネ(?[ [ 𝟘 - 𝟡 ] ])/; #no latin1' => "", |
641 | '/ネ(?[ [ 𝟧 - 𝟱 ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ 𝟧 - 𝟱 {#}] ])/", | |
642 | '/ネ(?[ [ 𝟧 - 𝟰 ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ 𝟧 - 𝟰 {#}] ])/", | |
63374c78 KW |
643 | ); |
644 | ||
c877af1b KW |
645 | push @warning_only_under_strict, @warning_utf8_only_under_strict; |
646 | ||
6fe2934b | 647 | my @experimental_regex_sets = ( |
6d24e9d4 | 648 | '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/', |
c1d900c3 BF |
649 | 'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' }, |
650 | '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/', | |
b45f050a JF |
651 | ); |
652 | ||
63fbd1cb | 653 | my @deprecated = ( |
8e84dec2 KW |
654 | '/^{/' => "", |
655 | '/foo|{/' => "", | |
656 | '/foo|^{/' => "", | |
657 | '/foo({bar)/' => "", | |
658 | '/foo(:?{bar)/' => "", | |
659 | '/\s*{/' => "", | |
660 | '/a{3,4}{/' => "", | |
286c9456 A |
661 | '/.{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/.{{#}/', |
662 | '/[x]{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/[x]{{#}/', | |
663 | '/\p{Latin}{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/\p{Latin}{{#}/', | |
63fbd1cb KW |
664 | ); |
665 | ||
67cdf558 KW |
666 | for my $strict ("", "use re 'strict';") { |
667 | ||
668 | # First time just use @death; but under strict we add the things that fail | |
669 | # there. Doing it this way makes sure that 'strict' doesnt change the | |
670 | # things that are already fatal when not under strict. | |
671 | if ($strict) { | |
672 | for (my $i = 0; $i < @death_only_under_strict; $i += 3) { | |
673 | push @death, $death_only_under_strict[$i], # The regex | |
674 | $death_only_under_strict[$i+2]; # The fatal msg | |
675 | } | |
676 | for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) { | |
677 | ||
678 | # Same with the utf8 versions | |
679 | push @death, mark_as_utf8($death_utf8_only_under_strict[$i], | |
680 | $death_utf8_only_under_strict[$i+2]); | |
681 | } | |
682 | } | |
d6609144 | 683 | for (my $i = 0; $i < @death; $i += 2) { |
d30277c7 | 684 | my $regex = $death[$i] =~ s/ default_ (on | off) //rx; |
b1793c1a | 685 | my $expect = fixup_expect($death[$i+1], $strict); |
d6609144 KW |
686 | no warnings 'experimental::regex_sets'; |
687 | no warnings 'experimental::re_strict'; | |
d6609144 KW |
688 | |
689 | warning_is(sub { | |
690 | my $eval_string = "$strict $regex"; | |
691 | $_ = "x"; | |
692 | eval $eval_string; | |
693 | like($@, qr/\Q$expect/, $eval_string); | |
694 | }, undef, "... and died without any other warnings"); | |
695 | } | |
67cdf558 | 696 | } |
b45f050a | 697 | |
63374c78 KW |
698 | for my $strict ("", "no warnings 'experimental::re_strict'; use re 'strict';") { |
699 | my @warning_tests = @warning; | |
67cdf558 | 700 | |
63374c78 KW |
701 | # Build the tests for @warning. Use the strict/non-strict versions |
702 | # appropriately. | |
703 | if ($strict) { | |
704 | push @warning_tests, @warning_only_under_strict; | |
705 | } | |
706 | else { | |
707 | for (my $i = 0; $i < @warning_only_under_strict; $i += 2) { | |
a4368cc3 KW |
708 | |
709 | # (?[ ]) are always under strict | |
63374c78 KW |
710 | if ($warning_only_under_strict[$i] =~ /\Q(?[/) { |
711 | push @warning_tests, $warning_only_under_strict[$i], # The regex | |
712 | $warning_only_under_strict[$i+1]; | |
713 | } | |
714 | else { | |
715 | push @warning_tests, $warning_only_under_strict[$i], # The regex | |
716 | ""; # No warning because not strict | |
717 | } | |
718 | } | |
67cdf558 | 719 | for (my $i = 0; $i < @death_only_under_strict; $i += 3) { |
63374c78 KW |
720 | push @warning_tests, $death_only_under_strict[$i], # The regex |
721 | $death_only_under_strict[$i+1]; # The warning | |
67cdf558 KW |
722 | } |
723 | for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) { | |
63374c78 | 724 | push @warning_tests, mark_as_utf8($death_utf8_only_under_strict[$i], |
d6609144 | 725 | $death_utf8_only_under_strict[$i+1]); |
67cdf558 KW |
726 | } |
727 | } | |
d6609144 | 728 | |
63374c78 | 729 | foreach my $ref (\@warning_tests, \@experimental_regex_sets, \@deprecated) { |
d6609144 | 730 | my $warning_type; |
63374c78 | 731 | my $turn_off_warnings = ""; |
d6609144 | 732 | my $default_on; |
63374c78 | 733 | if ($ref == \@warning_tests) { |
d6609144 | 734 | $warning_type = 'regexp, digit'; |
63374c78 | 735 | $turn_off_warnings = "no warnings 'experimental::regex_sets';"; |
d6609144 | 736 | $default_on = $strict; |
af01601c | 737 | } |
d6609144 KW |
738 | elsif ($ref == \@deprecated) { |
739 | $warning_type = 'regexp, deprecated'; | |
740 | $default_on = 1; | |
741 | } | |
742 | else { | |
743 | $warning_type = 'experimental::regex_sets'; | |
744 | $default_on = 1; | |
745 | } | |
746 | for (my $i = 0; $i < @$ref; $i += 2) { | |
d30277c7 | 747 | my $this_default_on = $default_on; |
d6609144 | 748 | my $regex = $ref->[$i]; |
d30277c7 KW |
749 | if ($regex =~ s/ default_ (on | off) //x) { |
750 | $this_default_on = $1 eq 'on'; | |
751 | } | |
b1793c1a | 752 | my @expect = fixup_expect($ref->[$i+1], $strict); |
63374c78 KW |
753 | |
754 | # A length-1 array with an empty warning means no warning gets | |
755 | # generated at all. | |
756 | undef @expect if @expect == 1 && $expect[0] eq ""; | |
757 | ||
d6609144 KW |
758 | { |
759 | $_ = "x"; | |
d8d26cac KW |
760 | #use feature 'unicode_eval'; |
761 | #print STDERR __LINE__, ": ", "eval '$strict no warnings; $regex'", "\n"; | |
d6609144 | 762 | eval "$strict no warnings; $regex"; |
af01601c | 763 | } |
d6609144 KW |
764 | if (is($@, "", "$strict $regex did not die")) { |
765 | my @got = capture_warnings(sub { | |
766 | $_ = "x"; | |
63374c78 | 767 | eval "$strict $turn_off_warnings $regex" }); |
d6609144 KW |
768 | my $count = @expect; |
769 | if (! is(scalar @got, scalar @expect, | |
770 | "... and gave expected number ($count) of warnings")) | |
771 | { | |
772 | if (@got < @expect) { | |
773 | $count = @got; | |
774 | note "Expected warnings not gotten:\n\t" . join "\n\t", | |
775 | @expect[$count .. $#expect]; | |
776 | } | |
777 | else { | |
778 | note "Unexpected warnings gotten:\n\t" . join("\n\t", | |
779 | @got[$count .. $#got]); | |
780 | } | |
b0b90d25 | 781 | } |
d6609144 KW |
782 | foreach my $i (0 .. $count - 1) { |
783 | if (! like($got[$i], qr/\Q$expect[$i]/, | |
784 | "... and gave expected warning")) | |
785 | { | |
786 | chomp($got[$i]); | |
787 | chomp($expect[$i]); | |
788 | diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'"); | |
67cdf558 KW |
789 | } |
790 | else { | |
d6609144 KW |
791 | ok (0 == capture_warnings(sub { |
792 | $_ = "x"; | |
793 | eval "$strict no warnings '$warning_type'; $regex;" } | |
794 | ), | |
795 | "... and turning off '$warning_type' warnings suppressed it"); | |
796 | ||
797 | # Test that whether the warning is on by default is | |
798 | # correct. This test relies on the fact that we | |
799 | # are outside the scope of any ‘use warnings’. | |
800 | local $^W; | |
801 | my @warns = capture_warnings(sub { $_ = "x"; | |
802 | eval "$strict $regex" }); | |
63374c78 KW |
803 | # Warning should be on as well if is testing |
804 | # '(?[...])' which turns on strict | |
d30277c7 | 805 | if ($this_default_on || grep { $_ =~ /\Q(?[/ } @expect ) { |
d6609144 KW |
806 | ok @warns > 0, "... and the warning is on by default"; |
807 | } | |
808 | else { | |
809 | ok @warns == 0, "... and the warning is off by default"; | |
810 | } | |
67cdf558 | 811 | } |
af01601c KW |
812 | } |
813 | } | |
b42857f3 | 814 | } |
6fe2934b KW |
815 | } |
816 | } | |
b45f050a | 817 | |
cb79f740 | 818 | done_testing(); |