This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #133767] Assertion failure
[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
58e23c8d 131 '/(?<= .*)/' => 'Variable length lookbehind 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
203 '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/',
204 '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/',
205
206 '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/',
207 '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/',
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{#}} ])/',
241 '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/',
242 '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/',
243 '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/',
244 '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/',
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]])/',
8f0cd35a 263 '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{#}}]])/',
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} ]))])/',
6d24e9d4
KW
266 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/',
267 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/',
268 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/',
269 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/',
270 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/',
271 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/',
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<{#}/',
9b8f4e92 286 'm/\cß/' => "Character following \"\\c\" must be printable ASCII",
cd209d9d
KW
287 '/((?# 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)/',
288 '/((?# 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
289 '/((?# 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)/',
290
291 '/(*script_runfoo)/' => 'Unknown \'(*...)\' construct \'script_runfoo\' {#} m/(*script_runfoo){#}/',
292 '/(*srfoo)/' => 'Unknown \'(*...)\' construct \'srfoo\' {#} m/(*srfoo){#}/',
293 '/(*script_run)/' => '\'(*script_run\' requires a terminating \':\' {#} m/(*script_run{#})/',
294 '/(*sr)/' => '\'(*sr\' requires a terminating \':\' {#} m/(*sr{#})/',
e7206367 295 '/(*pla)/' => '\'(*pla\' requires a terminating \':\' {#} m/(*pla{#})/',
d9790612
KW
296 '/(*script_run/' => 'Unterminated \'(*...\' construct {#} m/(*script_run{#}/',
297 '/(*sr/' => 'Unterminated \'(*...\' construct {#} m/(*sr{#}/',
298 '/(*script_run:foo/' => 'Unterminated \'(*...\' argument {#} m/(*script_run:foo{#}/',
299 '/(*sr:foo/' => 'Unterminated \'(*...\' argument {#} m/(*sr:foo{#}/',
5a55ed33 300 '/(?[\ &!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ &!{#}])/', # [perl #126180]
f4b6841f
KW
301 '/(?[\ +!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ +!{#}])/', # [perl #126180]
302 '/(?[\ -!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ -!{#}])/', # [perl #126180]
303 '/(?[\ ^!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ ^!{#}])/', # [perl #126180]
304 '/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/', # [perl #126180]
c333712c 305 '/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[(){#}-!])/', # [perl #126204]
174c9902 306 '/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/', # [perl #126404]
8e84dec2
KW
307 '/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/',
308 '/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/',
309 '/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/',
76416d1a
KW
310 '/.{, 4 }/' => 'Unescaped left brace in regex is illegal here {#} m/.{{#}, 4 }/',
311 '/[x]{, 4}/' => 'Unescaped left brace in regex is illegal here {#} m/[x]{{#}, 4}/',
312 '/\p{Latin}{,4 }/' => 'Unescaped left brace in regex is illegal here {#} m/\p{Latin}{{#},4 }/',
f2e32b2c 313 '/(?<=/' => 'Sequence (?... not terminated {#} m/(?<={#}/', # [perl #128170]
26a0fa3a 314 '/\p{vertical \v tab}/' => 'Can\'t find Unicode property definition "vertical \v tab" {#} m/\\p{vertical \v tab}{#}/', # [perl #132055]
4db502b8 315 "/$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 316 '/[^/' => 'Unmatched [ {#} m/[{#}^/', # [perl #133767]
60108b47 317
b45f050a 318);
c1d900c3 319
bd71b4b5
KW
320# These are messages that are death under 'use re "strict"', and may or may
321# not warn otherwise. See comment before @warning as to why some have a
322# \x{100} in them. This array has 3 elements per construct. [0] is the regex
323# to use; [1] is the message under no strict (empty to not warn), and [2] is
324# under strict.
67cdf558
KW
325my @death_only_under_strict = (
326 'm/\xABC/' => "",
327 => 'Use \x{...} for more than two hex characters {#} m/\xABC{#}/',
328 'm/[\xABC]/' => "",
329 => 'Use \x{...} for more than two hex characters {#} m/[\xABC{#}]/',
330
331 # XXX This is a confusing error message. The G isn't ignored; it just
332 # terminates the \x. Also some messages below are missing the <-- HERE,
333 # aren't all category 'regexp'. (Hence we have to turn off 'digit'
334 # messages as well below)
335 'm/\xAG/' => 'Illegal hexadecimal digit \'G\' ignored',
336 => 'Non-hex character {#} m/\xAG{#}/',
337 'm/[\xAG]/' => 'Illegal hexadecimal digit \'G\' ignored',
338 => 'Non-hex character {#} m/[\xAG{#}]/',
339 'm/\o{789}/' => 'Non-octal character \'8\'. Resolved as "\o{7}"',
340 => 'Non-octal character {#} m/\o{78{#}9}/',
341 'm/[\o{789}]/' => 'Non-octal character \'8\'. Resolved as "\o{7}"',
342 => 'Non-octal character {#} m/[\o{78{#}9}]/',
343 'm/\x{}/' => "",
344 => 'Number with no digits {#} m/\x{}{#}/',
345 'm/[\x{}]/' => "",
346 => 'Number with no digits {#} m/[\x{}{#}]/',
347 'm/\x{ABCDEFG}/' => 'Illegal hexadecimal digit \'G\' ignored',
348 => 'Non-hex character {#} m/\x{ABCDEFG{#}}/',
349 'm/[\x{ABCDEFG}]/' => 'Illegal hexadecimal digit \'G\' ignored',
350 => 'Non-hex character {#} m/[\x{ABCDEFG{#}}]/',
67cdf558
KW
351 "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/',
352 => 'Unrecognized escape \y in character class {#} m/[\y{#}]\x{100}/',
353 'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
354 => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
355 'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
356 => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/',
357 'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
358 => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/',
359 'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
360 => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/',
361 '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}{#}]/',
362 => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[^\N{U+100.300{#}}]/',
363 '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}{#}]/',
364 => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\x03-\N{U+100.300{#}}]/',
365 '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}]/',
366 => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\N{U+100.300{#}}-\x{10FFFF}]/',
367 '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/',
368 => 'Need exactly 3 octal digits {#} m/[\08{#}]/',
369 '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/',
370 => 'Need exactly 3 octal digits {#} m/[\018{#}]/',
371 '/[\_\0]/' => "",
372 => 'Need exactly 3 octal digits {#} m/[\_\0]{#}/',
373 '/[\07]/' => "",
374 => 'Need exactly 3 octal digits {#} m/[\07]{#}/',
375 '/[\0005]/' => "",
376 => 'Need exactly 3 octal digits {#} m/[\0005]{#}/',
377 '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/',
378 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/',
379 ],
380 => 'Unrecognized escape \8 in character class {#} m/[\8{#}\9]\x{100}/',
381 '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
382 => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/',
383 '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
384 => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/',
385 '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
386 => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/',
387 '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
388 => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/',
389 '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
390 => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/',
391 '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
392 => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/',
393 '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
394 => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/',
395 '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
396 => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/',
397 '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/',
398 => 'Unrecognized escape \z in character class {#} m/[a\z{#}b]\x{100}/',
2a6971a9
KW
399 '/[a\fb]/' => "",
400 => 'Literal vertical space in [] is illegal except under /x {#} m/[a\f{#}b]/',
76416d1a
KW
401 '/:{4,a}/' => 'Unescaped left brace in regex is passed through {#} m/:{{#}4,a}/',
402 => 'Unescaped left brace in regex is illegal here {#} m/:{{#}4,a}/',
403 '/xa{3\,4}y/' => 'Unescaped left brace in regex is passed through {#} m/xa{{#}3\,4}y/',
404 => 'Unescaped left brace in regex is illegal here {#} m/xa{{#}3\,4}y/',
405 '/\\${[^\\}]*}/' => 'Unescaped left brace in regex is passed through {#} m/\\${{#}[^\\}]*}/',
406 => 'Unescaped left brace in regex is illegal here {#} m/\\${{#}[^\\}]*}/',
407 '/.{/' => 'Unescaped left brace in regex is passed through {#} m/.{{#}/',
408 => 'Unescaped left brace in regex is illegal here {#} m/.{{#}/',
409 '/[x]{/' => 'Unescaped left brace in regex is passed through {#} m/[x]{{#}/',
410 => 'Unescaped left brace in regex is illegal here {#} m/[x]{{#}/',
411 '/\p{Latin}{/' => 'Unescaped left brace in regex is passed through {#} m/\p{Latin}{{#}/',
412 => 'Unescaped left brace in regex is illegal here {#} m/\p{Latin}{{#}/',
67cdf558
KW
413);
414
b0e1d434 415# These need the character 'ネ' as a marker for mark_as_utf8()
c1d900c3 416my @death_utf8 = mark_as_utf8(
c1d900c3
BF
417 '/ネ(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/',
418
419 '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/',
420
421 '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/',
422
476afc4b 423 '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/',
c1d900c3
BF
424
425 '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/',
426
427 '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/',
428
429 '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/',
430
431 '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/',
432 '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/',
433 '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/',
434 '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/',
435'/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/',
436'/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/',
437'/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/',
438
439 '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/',
440
441 "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/",
442
443
444 '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/',
445
446 '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/',
447
448 '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/',
449
450 '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/',
451
452 '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/',
453
4cabb89a 454 '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/',
c1d900c3
BF
455
456 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/',
457
458 '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/',
459 '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/',
460 '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/',
461
462 '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/',
c1d900c3 463
c1d900c3
BF
464 '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/',
465
466 '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/',
467
19a498a4
YO
468 '/ネ(?[[[:ネ]]])ネ/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[[[:ネ]]{#}])ネ/",
469 '/ネ(?[[[:ネ: ])ネ/' => "Syntax error in (?[...]) {#} m/ネ(?[[[:ネ: ])ネ{#}/",
470 '/ネ(?[[[::]]])ネ/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[[[::]]{#}])ネ/",
471 '/ネ(?[[[:ネ:]]])ネ/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[[[:ネ:]]{#}])ネ/",
c1d900c3 472 '/ネ(?[ネ])ネ/' => 'Unexpected character {#} m/ネ(?[ネ{#}])ネ/',
c1d900c3
BF
473 '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/',
474 '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/',
475 '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/',
476 '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/',
477 '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/',
478 '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/',
479 '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/',
480 '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/',
29f52644
KW
481 '/(?[ \p{ネ} ])/' => 'Can\'t find Unicode property definition "ネ" {#} m/(?[ \p{ネ}{#} ])/',
482 '/(?[ \p{ ネ = bar } ])/' => 'Can\'t find Unicode property definition "ネ = bar" {#} m/(?[ \p{ ネ = bar }{#} ])/',
19a498a4
YO
483 '/ネ(?[ \t ]/' => "Unexpected ']' with no following ')' in (?[... {#} m/ネ(?[ \\t ]{#}/",
484 '/(?[ \t + \e # ネ This was supposed to be a comment ])/' =>
485 "Syntax error in (?[...]) {#} m/(?[ \\t + \\e # ネ This was supposed to be a comment ]){#}/",
d9790612 486 'm/(*ネ)ネ/' => q<Unknown '(*...)' construct 'ネ' {#} m/(*ネ){#}ネ/>,
9b8f4e92 487 '/\cネ/' => "Character following \"\\c\" must be printable ASCII",
64935bc6
KW
488 '/\b{ネ}/' => "'ネ' is an unknown bound type {#} m/\\b{ネ{#}}/",
489 '/\B{ネ}/' => "'ネ' is an unknown bound type {#} m/\\B{ネ{#}}/",
c1d900c3
BF
490);
491push @death, @death_utf8;
492
67cdf558
KW
493my @death_utf8_only_under_strict = (
494 "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/',
495 => 'Unrecognized escape \y in character class {#} m/ネ[\y{#}]ネ/',
496 'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
497 => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/',
498 'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
499 => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/',
500 'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
501 => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/',
502 '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
503 => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/',
504 '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
505 => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/',
506 '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/',
507 => 'Unrecognized escape \z in character class {#} m/ネ[a\z{#}b]ネ/',
508);
902994e4 509# Tests involving a user-defined charnames translator are in pat_advanced.t
b45f050a 510
af01601c
KW
511# In the following arrays of warnings, the value can be an array of things to
512# expect. If the empty string, it means no warning should be raised.
513
6d24e9d4 514
499333dc
KW
515# Key-value pairs of code/error of code that should have non-fatal regexp
516# warnings. Most currently have \x{100} appended to them to force them to be
517# upgraded to UTF-8, and the first pass restarted. Previously this would
518# cause some warnings to be output twice. This tests that that behavior has
519# been fixed.
6d24e9d4 520
499333dc
KW
521my @warning = (
522 'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/',
64935bc6
KW
523 '/\b{g}/a' => "Using /u for '\\b{g}' instead of /a {#} m/\\b{g}{#}/",
524 '/\B{gcb}/a' => "Using /u for '\\B{gcb}' instead of /a {#} m/\\B{gcb}{#}/",
499333dc 525 'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/',
7dbd4c44 526 'm/[[:cntrl:]][:^ascii:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[[:cntrl:]][:^ascii:]{#}\x{100}/',
46d34d0e
KW
527 'm/[[:ascii]]\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/[[:ascii{#}]]\\x{100}/",
528 'm/(?[[:word]])\x{100}/' => "Assuming NOT a POSIX class since there is no terminating ':' {#} m/(?[[:word{#}]])\\x{100}/",
499333dc 529 "m'\\y\\x{100}'" => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/',
6d24e9d4
KW
530 '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
531 '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/',
532 '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/',
6d24e9d4
KW
533 '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/',
534 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
535 '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
282634ed 536 '/\q\p{Any}/' => 'Unrecognized escape \q passed through {#} m/\q{#}\p{Any}/',
499333dc 537
e1729dc6
FC
538 # These two tests do not include the marker, because regcomp.c no
539 # longer knows where it goes by the time this warning is emitted.
540 # See [perl #122680] regcomp warning gives wrong position of
499333dc 541 # problem.
e1729dc6
FC
542 '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/',
543 '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/',
499333dc 544
63fbd1cb 545 '/\_/' => "",
63fbd1cb 546 '/[\006]/' => "",
499333dc 547 '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/',
46d34d0e
KW
548 '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:zog:]{#}\x{100}/',
549 '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes (but this one isn\'t implemented) {#} m/[.zog.]{#}\x{100}/',
63fbd1cb 550 '/[a-b]/' => "",
499333dc
KW
551 '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/',
552 '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/',
553 '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/',
554 '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/',
555 '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/',
556 '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/',
557 '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/',
558 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/',
63fbd1cb 559 ],
499333dc
KW
560 '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/',
561 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/',
63fbd1cb
KW
562 ],
563 # (?c) means (?g) error won't be thrown
499333dc
KW
564 '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/',
565 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/',
63fbd1cb 566 ],
499333dc
KW
567 '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/',
568 'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/',
569 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/',
63fbd1cb 570 ],
499333dc 571 '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/',
c877af1b 572 "/(?[ [ % - % ] ])/" => "",
d4360efa
S
573 "/(?[ [ : - \\x$colon_hex ] ])\\x{100}/" => "\": - \\x$colon_hex \" is more clearly written simply as \":\" {#} m/(?[ [ : - \\x$colon_hex {#}] ])\\x{100}/",
574 "/(?[ [ \\x$colon_hex - : ] ])\\x{100}/" => "\"\\x$colon_hex\ - : \" is more clearly written simply as \":\" {#} m/(?[ [ \\x$colon_hex - : {#}] ])\\x{100}/",
575 "/(?[ [ \\t - \\x$tab_hex ] ])\\x{100}/" => "\"\\t - \\x$tab_hex \" is more clearly written simply as \"\\t\" {#} m/(?[ [ \\t - \\x$tab_hex {#}] ])\\x{100}/",
576 "/(?[ [ \\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
577 "/(?[ [ $B_hex - C ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $B_hex - C {#}] ])/",
578 "/(?[ [ A - $B_hex ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ A - $B_hex {#}] ])/",
579 "/(?[ [ $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 {#}] ])/",
580 "/(?[ [ $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
581 "/[alnum]/" => "",
582 "/[^alnum]/" => "",
583 '/[:blank]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/[:blank{#}]\x{100}/',
584 '/[[:digit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:digit{#}]]\x{100}/', # [perl # 8904]
585 '/[[:digit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:digit:{#}foo]\x{100}/',
586 '/[[:di#it:foo]\x{100}/x' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:di#it:{#}foo]\x{100}/',
587 '/[[:dgit]]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:dgit{#}]]\x{100}/',
588 '/[[:dgit:foo]\x{100}/' => 'Assuming NOT a POSIX class since there is no terminating \']\' {#} m/[[:dgit:{#}foo]\x{100}/',
589 '/[[:dgt]]\x{100}/' => "", # Far enough away from a real class to not be recognized as one
590 '/[[:dgt:foo]\x{100}/' => "",
591 '/[[:DIGIT]]\x{100}/' => [ 'Assuming NOT a POSIX class since the name must be all lowercase letters {#} m/[[:DIGIT{#}]]\x{100}/',
592 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[:DIGIT{#}]]\x{100}/',
593 ],
594 '/[[digit]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}digit]\x{100}/',
595 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[digit{#}]\x{100}/',
596 ],
597 '/[[alpha]]\x{100}/' => [ 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[{#}alpha]]\x{100}/',
598 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[alpha{#}]]\x{100}/',
599 ],
600 '/[[^word]\x{100}/' => [ 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[^{#}word]\x{100}/',
601 'Assuming NOT a POSIX class since there must be a starting \':\' {#} m/[[^{#}word]\x{100}/',
602 'Assuming NOT a POSIX class since there is no terminating \':\' {#} m/[[^word{#}]\x{100}/',
603 ],
604 '/[[ ^ : 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}/',
605 'Assuming NOT a POSIX class since the \'^\' must come after the colon {#} m/[[ ^{#} : x d i g i t : ] ]\x{100}/',
606 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ {#}: x d i g i t : ] ]\x{100}/',
607 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ : {#}x d i g i t : ] ]\x{100}/',
608 'Assuming NOT a POSIX class since no blanks are allowed in one {#} m/[[ ^ : x d i g i t : ]{#} ]\x{100}/',
a4368cc3 609 $only_strict_marker . 'Unescaped literal \']\' {#} m/[[ ^ : x d i g i t : ] ]{#}\x{100}/',
46d34d0e
KW
610 ],
611 '/[foo:lower:]]\x{100}/' => 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#}:lower:]]\x{100}/',
612 '/[[;upper;]]\x{100}/' => [ 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;{#}upper;]]\x{100}/',
613 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[[;upper;]{#}]\x{100}/',
614 ],
615 '/[foo;punct;]]\x{100}/' => [ 'Assuming NOT a POSIX class since it doesn\'t start with a \'[\' {#} m/[foo{#};punct;]]\x{100}/',
616 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;{#}punct;]]\x{100}/',
617 'Assuming NOT a POSIX class since a semi-colon was found instead of a colon {#} m/[foo;punct;]{#}]\x{100}/',
618 ],
d730a801
YO
619 '/[][[:alpha:]]/' => "", # [perl #127581]
620 '/[][[:alpha:]\\@\\\\^_?]/' => "", # [perl #131522]
611d6243
KW
621 '/(?[[:w:]])/' => "",
622 '/([.].*)[.]/' => "", # [perl #127582]
623 '/[.].*[.]/' => "", # [perl #127604]
624 '/abc/xix' => "",
625 '/(?xmsixp:abc)/' => "",
626 '/(?xmsixp)abc/' => "",
627 '/(?xxxx:abc)/' => "",
628
499333dc 629); # See comments before this for why '\x{100}' is generally needed
6fe2934b 630
b0e1d434 631# These need the character 'ネ' as a marker for mark_as_utf8()
c1d900c3
BF
632my @warnings_utf8 = mark_as_utf8(
633 'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/',
634 '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/',
46d34d0e 635 'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes (but this one isn\'t fully valid) {#} m/ネ[:foo:]{#}ネ/',
b0e1d434 636 '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/',
c1d900c3
BF
637 '/utf8 ネ (?ogc) ネ/' => [
638 'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/',
639 'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/',
640 'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/',
641 ],
611d6243
KW
642 '/ネ[[:ネ:]]ネ/' => "",
643 '/ネ(?[[:ネ:]])ネ/' => "",
c1d900c3
BF
644
645);
646
647push @warning, @warnings_utf8;
648
63374c78 649my @warning_only_under_strict = (
b927b7e9
KW
650 '/[\N{U+00}-\x01]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+00}-\x01{#}]\x{100}/',
651 '/[\x00-\N{SOH}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\x00-\N{U+01}{#}]\x{100}/',
652 '/[\N{DEL}-\o{377}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\o{377}{#}]\x{100}/',
653 '/[\o{0}-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\o{0}-\N{U+01}{#}]\x{100}/',
654 '/[\000-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\000-\N{U+01}{#}]\x{100}/',
655 '/[\N{DEL}-\377]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\377{#}]\x{100}/',
c877af1b
KW
656 '/[\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}/',
657 '/[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
658 '/[\N{U+00}-\a]\x{100}/' => "",
659 '/[\a-\N{U+FF}]\x{100}/' => "",
660 '/[\N{U+FF}-\x{100}]/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+FF}-\x{100}{#}]/',
661 '/[\N{U+100}-\x{101}]/' => "",
c877af1b 662 "/[%-%]/" => "",
d4360efa
S
663 "/[:-\\x$colon_hex]\\x{100}/" => "\":-\\x$colon_hex\" is more clearly written simply as \":\" {#} m/[:-\\x$colon_hex\{#}]\\x{100}/",
664 "/[\\x$colon_hex-:]\\x{100}/" => "\"\\x$colon_hex-:\" is more clearly written simply as \":\" {#} m/[\\x$colon_hex\-:{#}]\\x{100}/",
665 "/[\\t-\\x$tab_hex]\\x{100}/" => "\"\\t-\\x$tab_hex\" is more clearly written simply as \"\\t\" {#} m/[\\t-\\x$tab_hex\{#}]\\x{100}/",
666 "/[\\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
667 "/[$B_hex-C]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$B_hex-C{#}]/",
668 "/[A-$B_hex]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[A-$B_hex\{#}]/",
669 "/[$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\{#}]/",
670 "/[$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
671 '/\b<GCB}/' => 'Unescaped literal \'}\' {#} m/\b<GCB}{#}/',
672 '/[ ]def]/' => 'Unescaped literal \']\' {#} m/[ ]def]{#}/',
c877af1b
KW
673);
674
675my @warning_utf8_only_under_strict = mark_as_utf8(
676 '/ネ[᪉-᪐]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᪉-᪐{#}]/",
677 '/ネ(?[ [ ᪉ - ᪐ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᪉ - ᪐ {#}] ])/",
678 '/ネ[᧙-᧚]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᧙-᧚{#}]/",
679 '/ネ(?[ [ ᧙ - ᧚ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᧙ - ᧚ {#}] ])/",
8bafd282
KW
680 '/ネ(?[ [ 𝟘 - 𝟡 ] ])/; #no latin1' => "",
681 '/ネ(?[ [ 𝟧 - 𝟱 ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ 𝟧 - 𝟱 {#}] ])/",
682 '/ネ(?[ [ 𝟧 - 𝟰 ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ 𝟧 - 𝟰 {#}] ])/",
63374c78
KW
683);
684
c877af1b
KW
685push @warning_only_under_strict, @warning_utf8_only_under_strict;
686
6fe2934b 687my @experimental_regex_sets = (
6d24e9d4 688 '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/',
c1d900c3
BF
689 'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' },
690 '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/',
b45f050a
JF
691);
692
034602eb 693my @experimental_script_run = (
d9790612
KW
694 '/(*script_run:paypal.com)/' => 'The script_run feature is experimental {#} m/(*script_run:{#}paypal.com)/',
695 'use utf8; /utf8 ネ (*script_run:ネ)/' => do { use utf8; 'The script_run feature is experimental {#} m/utf8 ネ (*script_run:{#}ネ)/' },
696 '/noutf8 ネ (*script_run:ネ)/' => 'The script_run feature is experimental {#} m/noutf8 ネ (*script_run:{#}ネ)/',
034602eb
KW
697);
698
63fbd1cb 699my @deprecated = (
8e84dec2
KW
700 '/^{/' => "",
701 '/foo|{/' => "",
702 '/foo|^{/' => "",
0367231c 703 '/foo({bar)/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through {#} m/foo({{#}bar)/',
8e84dec2
KW
704 '/foo(:?{bar)/' => "",
705 '/\s*{/' => "",
706 '/a{3,4}{/' => "",
63fbd1cb
KW
707);
708
67cdf558
KW
709for my $strict ("", "use re 'strict';") {
710
711 # First time just use @death; but under strict we add the things that fail
712 # there. Doing it this way makes sure that 'strict' doesnt change the
713 # things that are already fatal when not under strict.
714 if ($strict) {
715 for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
716 push @death, $death_only_under_strict[$i], # The regex
717 $death_only_under_strict[$i+2]; # The fatal msg
718 }
719 for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
720
721 # Same with the utf8 versions
722 push @death, mark_as_utf8($death_utf8_only_under_strict[$i],
723 $death_utf8_only_under_strict[$i+2]);
724 }
725 }
d6609144 726 for (my $i = 0; $i < @death; $i += 2) {
d30277c7 727 my $regex = $death[$i] =~ s/ default_ (on | off) //rx;
b1793c1a 728 my $expect = fixup_expect($death[$i+1], $strict);
1765a25a
KW
729 if ($expect eq "") {
730 fail("$0: Internal error: '$death[$i]' should have an error message");
731 }
732 else {
d4abdeed 733 no warnings 'experimental::regex_sets';
034602eb 734 no warnings 'experimental::script_run';
d4abdeed 735 no warnings 'experimental::re_strict';
cc38b95d 736 no warnings 'experimental::alpha_assertions';
d6609144 737
d4abdeed 738 warning_is(sub {
1765a25a 739 my $meaning_of_life;
d6609144
KW
740 my $eval_string = "$strict $regex";
741 $_ = "x";
1765a25a
KW
742 eval "$eval_string; \$meaning_of_life = 42";
743 ok (! defined $meaning_of_life, "$eval_string died");
af05e4c0
YO
744 my $error= $@;
745 if ($error =~ qr/\Q$expect/) {
1765a25a 746 ok(1, "... and gave expected message");
af05e4c0
YO
747 } else {
748 ok(0,$eval_string);
3fb37286
YO
749 diag("Have: " . _q(add_markers($error)));
750 diag("Want: " . _q($death[$i+1]));
af05e4c0 751 }
1765a25a
KW
752 }, undef, "... and no other warnings");
753 }
d6609144 754 }
67cdf558 755}
b45f050a 756
63374c78
KW
757for my $strict ("", "no warnings 'experimental::re_strict'; use re 'strict';") {
758 my @warning_tests = @warning;
67cdf558 759
63374c78
KW
760 # Build the tests for @warning. Use the strict/non-strict versions
761 # appropriately.
762 if ($strict) {
763 push @warning_tests, @warning_only_under_strict;
764 }
765 else {
766 for (my $i = 0; $i < @warning_only_under_strict; $i += 2) {
a4368cc3
KW
767
768 # (?[ ]) are always under strict
63374c78
KW
769 if ($warning_only_under_strict[$i] =~ /\Q(?[/) {
770 push @warning_tests, $warning_only_under_strict[$i], # The regex
771 $warning_only_under_strict[$i+1];
772 }
773 else {
774 push @warning_tests, $warning_only_under_strict[$i], # The regex
775 ""; # No warning because not strict
776 }
777 }
67cdf558 778 for (my $i = 0; $i < @death_only_under_strict; $i += 3) {
63374c78
KW
779 push @warning_tests, $death_only_under_strict[$i], # The regex
780 $death_only_under_strict[$i+1]; # The warning
67cdf558
KW
781 }
782 for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) {
63374c78 783 push @warning_tests, mark_as_utf8($death_utf8_only_under_strict[$i],
d6609144 784 $death_utf8_only_under_strict[$i+1]);
67cdf558
KW
785 }
786 }
d6609144 787
034602eb
KW
788 foreach my $ref (\@warning_tests,
789 \@experimental_regex_sets,
790 \@experimental_script_run,
791 \@deprecated)
792 {
d6609144 793 my $warning_type;
63374c78 794 my $turn_off_warnings = "";
d6609144 795 my $default_on;
63374c78 796 if ($ref == \@warning_tests) {
d6609144 797 $warning_type = 'regexp, digit';
034602eb
KW
798 $turn_off_warnings = "no warnings 'experimental::regex_sets';"
799 . "no warnings 'experimental::script_run';";
d6609144 800 $default_on = $strict;
af01601c 801 }
d6609144
KW
802 elsif ($ref == \@deprecated) {
803 $warning_type = 'regexp, deprecated';
804 $default_on = 1;
805 }
034602eb 806 elsif ($ref == \@experimental_regex_sets) {
d6609144
KW
807 $warning_type = 'experimental::regex_sets';
808 $default_on = 1;
809 }
034602eb
KW
810 elsif ($ref == \@experimental_script_run) {
811 $warning_type = 'experimental::script_run';
812 $default_on = 1;
813 }
814 else {
815 fail("$0: Internal error: Unexpected loop variable");
816 }
817
d6609144 818 for (my $i = 0; $i < @$ref; $i += 2) {
d30277c7 819 my $this_default_on = $default_on;
d6609144 820 my $regex = $ref->[$i];
d30277c7
KW
821 if ($regex =~ s/ default_ (on | off) //x) {
822 $this_default_on = $1 eq 'on';
823 }
b1793c1a 824 my @expect = fixup_expect($ref->[$i+1], $strict);
63374c78
KW
825
826 # A length-1 array with an empty warning means no warning gets
827 # generated at all.
828 undef @expect if @expect == 1 && $expect[0] eq "";
829
d6609144
KW
830 {
831 $_ = "x";
d8d26cac
KW
832 #use feature 'unicode_eval';
833 #print STDERR __LINE__, ": ", "eval '$strict no warnings; $regex'", "\n";
d6609144 834 eval "$strict no warnings; $regex";
af01601c 835 }
d6609144
KW
836 if (is($@, "", "$strict $regex did not die")) {
837 my @got = capture_warnings(sub {
838 $_ = "x";
63374c78 839 eval "$strict $turn_off_warnings $regex" });
d6609144
KW
840 my $count = @expect;
841 if (! is(scalar @got, scalar @expect,
842 "... and gave expected number ($count) of warnings"))
843 {
844 if (@got < @expect) {
845 $count = @got;
846 note "Expected warnings not gotten:\n\t" . join "\n\t",
847 @expect[$count .. $#expect];
848 }
849 else {
850 note "Unexpected warnings gotten:\n\t" . join("\n\t",
851 @got[$count .. $#got]);
852 }
b0b90d25 853 }
d6609144
KW
854 foreach my $i (0 .. $count - 1) {
855 if (! like($got[$i], qr/\Q$expect[$i]/,
856 "... and gave expected warning"))
857 {
858 chomp($got[$i]);
859 chomp($expect[$i]);
860 diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'");
67cdf558
KW
861 }
862 else {
d6609144
KW
863 ok (0 == capture_warnings(sub {
864 $_ = "x";
865 eval "$strict no warnings '$warning_type'; $regex;" }
866 ),
867 "... and turning off '$warning_type' warnings suppressed it");
868
869 # Test that whether the warning is on by default is
870 # correct. This test relies on the fact that we
871 # are outside the scope of any ‘use warnings’.
872 local $^W;
873 my @warns = capture_warnings(sub { $_ = "x";
874 eval "$strict $regex" });
63374c78
KW
875 # Warning should be on as well if is testing
876 # '(?[...])' which turns on strict
d30277c7 877 if ($this_default_on || grep { $_ =~ /\Q(?[/ } @expect ) {
d6609144
KW
878 ok @warns > 0, "... and the warning is on by default";
879 }
880 else {
881 ok @warns == 0, "... and the warning is off by default";
882 }
67cdf558 883 }
af01601c
KW
884 }
885 }
b42857f3 886 }
6fe2934b
KW
887 }
888}
b45f050a 889
cb79f740 890done_testing();