This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #122671] Many warnings in regcomp.c can occur twice
[perl5.git] / t / re / reg_mesg.t
CommitLineData
b45f050a
JF
1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
cc7e6304 5 @INC = qw '../lib ../ext/re';
cb79f740 6 require './test.pl';
2b08d1e2 7 skip_all_without_unicode_tables();
cb79f740 8 eval 'require Config'; # assume defaults if this fails
b45f050a
JF
9}
10
cb79f740 11use strict;
c1d900c3 12use open qw(:utf8 :std);
b45f050a
JF
13
14##
15## If the markers used are changed (search for "MARKER1" in regcomp.c),
cb79f740 16## update only these two regexs, and leave the {#} in the @death/@warning
b45f050a
JF
17## arrays below. The {#} is a meta-marker -- it marks where the marker should
18## go.
cb79f740 19##
af01601c
KW
20## Returns empty string if that is what is expected. Otherwise, handles
21## either a scalar, turning it into a single element array; or a ref to an
22## array, adjusting each element. If called in array context, returns an
23## array, otherwise the join of all elements
24
cb79f740 25sub fixup_expect {
af01601c
KW
26 my $expect_ref = shift;
27 return if $expect_ref eq "";
28
29 my @expect;
30 if (ref $expect_ref) {
31 @expect = @$expect_ref;
32 }
33 else {
34 @expect = $expect_ref;
35 }
36
37 foreach my $element (@expect) {
6d24e9d4 38 $element =~ s/{\#}/in regex; marked by <-- HERE in/;
af01601c
KW
39 $element =~ s/{\#}/ <-- HERE /;
40 $element .= " at ";
41 }
42 return wantarray ? @expect : join "", @expect;
cb79f740 43}
b45f050a 44
c1d900c3
BF
45## Because we don't "use utf8" in this file, we need to do some extra legwork
46## for the utf8 tests: Append 'use utf8' to the pattern, and mark the strings
47## to check against as UTF-8
4cabb89a
BF
48##
49## This also creates a second variant of the tests to check if the
50## latin1 error messages are working correctly.
51my $l1 = "\x{ef}";
52my $utf8 = "\x{30cd}";
53utf8::encode($utf8);
54
c1d900c3
BF
55sub mark_as_utf8 {
56 my @ret;
57 while ( my ($pat, $msg) = splice(@_, 0, 2) ) {
4cabb89a
BF
58 my $l1_pat = $pat =~ s/$utf8/$l1/gr;
59 my $l1_msg;
c1d900c3
BF
60 $pat = "use utf8; $pat";
61
62 if (ref $msg) {
4cabb89a
BF
63 $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ];
64 @$msg = map { my $c = $_; utf8::decode($c); $c } @$msg;
c1d900c3
BF
65 }
66 else {
4cabb89a 67 $l1_msg = $msg =~ s/$utf8/$l1/gr;
c1d900c3
BF
68 utf8::decode($msg);
69 }
70 push @ret, $pat => $msg;
4cabb89a 71 push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/;
c1d900c3
BF
72 }
73 return @ret;
74}
75
cb79f740
NC
76my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1;
77my $inf_p1 = $inf_m1 + 2;
b45f050a
JF
78
79##
80## Key-value pairs of code/error of code that should have fatal errors.
81##
82my @death =
83(
6d24e9d4 84 '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/',
b45f050a 85
58e23c8d 86 '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/',
b45f050a 87
58e23c8d 88 '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/',
b45f050a 89
6d24e9d4 90 '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/',
b45f050a 91
9da1dd8f 92 '/(?{ 1/' => 'Missing right curly or square bracket',
b45f050a 93
6d24e9d4 94 '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/',
311cc1ad 95 '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/',
b45f050a 96
6d24e9d4 97 '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/',
b45f050a 98
c1d900c3 99 '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/',
10380cb3
FC
100 '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/',
101 '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/',
b45f050a 102
6d24e9d4 103 '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/',
b45f050a 104
6d24e9d4
KW
105 '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/',
106 '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/',
107 '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/',
108 '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/',
109 '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/',
110 '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/',
111 '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/',
112 '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/',
113 '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/',
114 '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/',
115 '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
116 '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/',
117 '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/',
118 '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/',
119 '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/',
120 '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/',
121'/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/',
122'/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/',
123'/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/',
124'/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
32d02813
KW
125'/a\b{cde/' => 'Use "\b\{" instead of "\b{" {#} m/a\{#}b{cde/',
126'/a\B{cde/' => 'Use "\B\{" instead of "\B{" {#} m/a\{#}B{cde/',
cc74c5bd 127
6d24e9d4 128 '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
b45f050a 129
6d24e9d4 130 "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/",
b45f050a 131
b45f050a 132
6d24e9d4 133 '/x**/' => 'Nested quantifiers {#} m/x**{#}/',
b45f050a 134
6d24e9d4 135 '/x[/' => 'Unmatched [ {#} m/x[{#}/',
b45f050a 136
6d24e9d4 137 '/*/', => 'Quantifier follows nothing {#} m/*{#}/',
b45f050a 138
6d24e9d4 139 '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/',
b45f050a 140
6d24e9d4 141 '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/',
b45f050a 142
6d24e9d4 143 '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/',
b45f050a 144
779fedd7 145 '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/',
76cccc4d
KW
146 '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/',
147
40809656 148 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
b45f050a 149
6d24e9d4
KW
150 '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/',
151 '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/',
152
153 '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/',
154 '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/',
155
156 '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/',
157 '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/',
158
159 '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/',
160 '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/',
161
162 '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/',
163
164 '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/',
165
166 '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/',
167
168 '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/',
169
170 '/\p/' => 'Empty \p{} {#} m/\p{#}/',
171
172 '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/',
173 '/(?[[[:word]]])/' => "Unmatched ':' in POSIX class {#} m/(?[[[:word{#}]]])/",
174 '/(?[[:word]])/' => "Unmatched ':' in POSIX class {#} m/(?[[:word{#}]])/",
175 '/(?[[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[[:digit:{#} ])/",
176 '/(?[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[:digit:{#} ])/",
177 '/(?[[[::]]])/' => "POSIX class [::] unknown {#} m/(?[[[::]{#}]])/",
178 '/(?[[[:w:]]])/' => "POSIX class [:w:] unknown {#} m/(?[[[:w:]{#}]])/",
179 '/(?[[:w:]])/' => "POSIX class [:w:] unknown {#} m/(?[[:w:]{#}])/",
180 '/(?[a])/' => 'Unexpected character {#} m/(?[a{#}])/',
181 '/(?[\t])/l' => '(?[...]) not valid in locale {#} m/(?[{#}\t])/',
182 '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/',
183 '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/',
184 '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/',
185 '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/',
186 '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/',
187 '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/',
188 '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/',
189 '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/',
190 '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/',
191 '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/',
192 '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/',
193 '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/',
194 '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/',
195 '/(?[ \p{foo} ])/' => 'Property \'foo\' is unknown {#} m/(?[ \p{foo}{#} ])/',
196 '/(?[ \p{ foo = bar } ])/' => 'Property \'foo = bar\' is unknown {#} m/(?[ \p{ foo = bar }{#} ])/',
197 '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/',
3f4fde43
KW
198 '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/',
199 '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/',
200 '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/',
201 '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/',
202 '/(?[ \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
203 '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/',
204 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/',
205 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/',
206 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/',
207 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/',
208 'm/(?[[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in character class restricted to one character {#} m/(?[[\N{U+100.300{#}}]])/',
b5864679
KW
209 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/',
210 'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/',
6d24e9d4
KW
211 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/',
212 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/',
213 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/',
214 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/',
215 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/',
216 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/',
217 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
f1e1b256
YO
218 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/',
219 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/',
220 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/',
07ea66ee
FC
221 'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/',
222 'm/(?&a/' => 'Sequence (?&... not terminated {#} m/(?&a{#}/',
75839571
FC
223 'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/',
224 "m/(?'/" => "Sequence (?'... not terminated {#} m/(?'{#}/",
225 "m/(?</" => "Sequence (?<... not terminated {#} m/(?<{#}/",
226 'm/(?&/' => 'Sequence (?&... not terminated {#} m/(?&{#}/',
227 'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/',
228 "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/",
229 'm/\g{/' => 'Sequence \g{... not terminated {#} m/\g{{#}/',
230 'm/\k</' => 'Sequence \k<... not terminated {#} m/\k<{#}/',
9b8f4e92 231 'm/\cß/' => "Character following \"\\c\" must be printable ASCII",
cd209d9d
KW
232 '/((?# 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)/',
233 '/((?# 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)/',
b45f050a 234);
c1d900c3
BF
235
236my @death_utf8 = mark_as_utf8(
237 '/ネ[[=ネ=]]ネ/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/ネ[[=ネ=]{#}]ネ/',
238 '/ネ(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/',
239
240 '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/',
241
242 '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/',
243
476afc4b 244 '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/',
c1d900c3
BF
245
246 '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/',
247
248 '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/',
249
250 '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/',
251
252 '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/',
253 '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/',
254 '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/',
255 '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/',
256'/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/',
257'/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/',
258'/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/',
259
260 '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/',
261
262 "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/",
263
264
265 '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/',
266
267 '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/',
268
269 '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/',
270
271 '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/',
272
273 '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/',
274
4cabb89a 275 '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/',
c1d900c3
BF
276
277 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/',
278
279 '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/',
280 '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/',
281 '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/',
282
283 '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/',
284 '/ネ[[:ネ:]]ネ/' => 'POSIX class [:ネ:] unknown {#} m/ネ[[:ネ:]{#}]ネ/',
285
286 '/ネ[[=ネ=]]ネ/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/ネ[[=ネ=]{#}]ネ/',
287
288 '/ネ[[.ネ.]]ネ/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/ネ[[.ネ.]{#}]ネ/',
289
290 '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/',
291
292 '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/',
293
294 '/ネ(?[[[:ネ]]])ネ/' => "Unmatched ':' in POSIX class {#} m/ネ(?[[[:ネ{#}]]])ネ/",
295 '/ネ(?[[[:ネ: ])ネ/' => "Unmatched '[' in POSIX class {#} m/ネ(?[[[:ネ:{#} ])ネ/",
296 '/ネ(?[[[::]]])ネ/' => "POSIX class [::] unknown {#} m/ネ(?[[[::]{#}]])ネ/",
297 '/ネ(?[[[:ネ:]]])ネ/' => "POSIX class [:ネ:] unknown {#} m/ネ(?[[[:ネ:]{#}]])ネ/",
298 '/ネ(?[[:ネ:]])ネ/' => "POSIX class [:ネ:] unknown {#} m/ネ(?[[:ネ:]{#}])ネ/",
299 '/ネ(?[ネ])ネ/' => 'Unexpected character {#} m/ネ(?[ネ{#}])ネ/',
300 '/ネ(?[ネ])/l' => '(?[...]) not valid in locale {#} m/ネ(?[{#}ネ])/',
301 '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/',
302 '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/',
303 '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/',
304 '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/',
305 '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/',
306 '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/',
307 '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/',
308 '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/',
309 '/(?[ \p{ネ} ])/' => 'Property \'ネ\' is unknown {#} m/(?[ \p{ネ}{#} ])/',
310 '/(?[ \p{ ネ = bar } ])/' => 'Property \'ネ = bar\' is unknown {#} m/(?[ \p{ ネ = bar }{#} ])/',
311 '/ネ(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/ネ(?[ \t ]/',
312 '/(?[ \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
313 'm/(*ネ)ネ/' => q<Unknown verb pattern 'ネ' {#} m/(*ネ){#}ネ/>,
314 '/\cネ/' => "Character following \"\\c\" must be printable ASCII",
c1d900c3
BF
315);
316push @death, @death_utf8;
317
902994e4 318# Tests involving a user-defined charnames translator are in pat_advanced.t
b45f050a 319
af01601c
KW
320# In the following arrays of warnings, the value can be an array of things to
321# expect. If the empty string, it means no warning should be raised.
322
6d24e9d4 323
499333dc
KW
324# Key-value pairs of code/error of code that should have non-fatal regexp
325# warnings. Most currently have \x{100} appended to them to force them to be
326# upgraded to UTF-8, and the first pass restarted. Previously this would
327# cause some warnings to be output twice. This tests that that behavior has
328# been fixed.
6d24e9d4 329
499333dc
KW
330my @warning = (
331 'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/',
332 'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/',
333 "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/',
334 'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
335 'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
336 'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
337 'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
3da4c246 338 '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}]/',
499333dc 339 "m'\\y\\x{100}'" => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/',
6d24e9d4
KW
340 '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
341 '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/',
342 '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/',
343 '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/',
344 '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/',
6d24e9d4
KW
345 '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/',
346 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
347 '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
499333dc
KW
348
349 # Feel free to modify these 2 tests, should they start failing because the
350 # marker of where the problem is becomes wrong. The current behavior is
351 # bad, always marking at the very end of the regex instead of where the
352 # problem is. See [perl #122680] regcomp warning gives wrong position of
353 # problem.
354 '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression {#} m/(?=a){1,3}\x{100}{#}/',
355 '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression {#} m/(a|b)(?=a){3}\x{100}{#}/',
356
63fbd1cb
KW
357 '/\_/' => "",
358 '/[\_\0]/' => "",
359 '/[\07]/' => "",
360 '/[\006]/' => "",
361 '/[\0005]/' => "",
499333dc
KW
362 '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/',
363 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/',
63fbd1cb 364 ],
499333dc
KW
365 '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/',
366 '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:zog:]{#}\x{100}/',
367 '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes {#} m/[.zog.]{#}\x{100}/',
63fbd1cb 368 '/[a-b]/' => "",
499333dc
KW
369 '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
370 '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
371 '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
372 '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
373 '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
374 '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
375 '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
376 '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
377 '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/',
378 '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/',
379 '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/',
380 '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/',
381 '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/',
382 '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/',
383 '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/',
384 '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/',
385 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/',
63fbd1cb 386 ],
499333dc
KW
387 '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/',
388 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/',
63fbd1cb
KW
389 ],
390 # (?c) means (?g) error won't be thrown
499333dc
KW
391 '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/',
392 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/',
63fbd1cb 393 ],
499333dc
KW
394 '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/',
395 'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/',
396 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/',
63fbd1cb 397 ],
499333dc
KW
398 '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/',
399 '/b{3} +\x{100}/x' => 'Useless use of greediness modifier \'+\' {#} m/b{3} +{#}\x{100}/',
400); # See comments before this for why '\x{100}' is generally needed
6fe2934b 401
c1d900c3
BF
402my @warnings_utf8 = mark_as_utf8(
403 'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/',
404 '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/',
405 'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes {#} m/ネ[:foo:]{#}ネ/',
406 "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/',
407 'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
408 'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
409 'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
410 '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
411 '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
412 '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/',
413 '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/',
414 '/utf8 ネ (?ogc) ネ/' => [
415 'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/',
416 'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/',
417 'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/',
418 ],
419
420);
421
422push @warning, @warnings_utf8;
423
6fe2934b 424my @experimental_regex_sets = (
6d24e9d4 425 '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/',
c1d900c3
BF
426 'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' },
427 '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/',
b45f050a
JF
428);
429
63fbd1cb 430my @deprecated = (
412f55bb
KW
431 '/\w{/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/\w{{#}/',
432 '/\q{/' => [
433 'Unrecognized escape \q{ passed through {#} m/\q{{#}/',
434 'Unescaped left brace in regex is deprecated, passed through {#} m/\q{{#}/'
435 ],
436 '/:{4,a}/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/:{{#}4,a}/',
63fbd1cb
KW
437);
438
cb79f740
NC
439while (my ($regex, $expect) = splice @death, 0, 2) {
440 my $expect = fixup_expect($expect);
3f4fde43 441 no warnings 'experimental::regex_sets';
40809656 442 # skip the utf8 test on EBCDIC since they do not die
cb79f740 443 next if $::IS_EBCDIC && $regex =~ /utf8/;
b45f050a 444
cb79f740
NC
445 warning_is(sub {
446 $_ = "x";
447 eval $regex;
40e98def
KW
448 like($@, qr/\Q$expect/, $regex);
449 }, undef, "... and died without any other warnings");
b45f050a
JF
450}
451
63fbd1cb 452foreach my $ref (\@warning, \@experimental_regex_sets, \@deprecated) {
6fe2934b
KW
453 my $warning_type = ($ref == \@warning)
454 ? 'regexp'
63fbd1cb 455 : ($ref == \@deprecated)
c2a42ab2 456 ? 'regexp, deprecated'
63fbd1cb 457 : 'experimental::regex_sets';
b42857f3 458 while (my ($regex, $expect) = splice @$ref, 0, 2) {
af01601c
KW
459 my @expect = fixup_expect($expect);
460 {
461 $_ = "x";
462 no warnings;
463 eval $regex;
464 }
465 if (is($@, "", "$regex did not die")) {
466 my @got = capture_warnings(sub {
467 $_ = "x";
468 eval $regex });
469 my $count = @expect;
470 if (! is(scalar @got, scalar @expect, "... and gave expected number ($count) of warnings")) {
471 if (@got < @expect) {
472 $count = @got;
473 note "Expected warnings not gotten:\n\t" . join "\n\t", @expect[$count .. $#expect];
474 }
475 else {
476 note "Unexpected warnings gotten:\n\t" . join("\n\t", @got[$count .. $#got]);
477 }
478 }
479 foreach my $i (0 .. $count - 1) {
b0b90d25
KW
480 if (! like($got[$i], qr/\Q$expect[$i]/, "... and gave expected warning")) {
481 chomp($got[$i]);
482 chomp($expect[$i]);
483 diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'");
484 }
485 else {
af01601c
KW
486 ok (0 == capture_warnings(sub {
487 $_ = "x";
6fe2934b 488 eval "no warnings '$warning_type'; $regex;" }
af01601c
KW
489 ),
490 "... and turning off '$warning_type' warnings suppressed it");
9a5996c9
FC
491 # Test that whether the warning is on by default is
492 # correct. Experimental and deprecated warnings are;
493 # others are not. This test relies on the fact that we
494 # are outside the scope of any ‘use warnings’.
495 local $^W;
496 my $on = 'on' x ($warning_type ne 'regexp');
497 ok !!$on ==
498 capture_warnings(sub { $_ = "x"; eval $regex }),
499 "... and the warning is " . ($on||'off')
500 . " by default";
af01601c
KW
501 }
502 }
b42857f3 503 }
6fe2934b
KW
504 }
505}
b45f050a 506
cb79f740 507done_testing();