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