This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c, S_compile_runtime_code: croak using the SVf format
[perl5.git] / t / re / reg_mesg.t
CommitLineData
b45f050a
JF
1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
cb79f740
NC
6 require './test.pl';
7 eval 'require Config'; # assume defaults if this fails
b45f050a
JF
8}
9
cb79f740 10use strict;
b45f050a
JF
11
12##
13## If the markers used are changed (search for "MARKER1" in regcomp.c),
cb79f740 14## update only these two regexs, and leave the {#} in the @death/@warning
b45f050a
JF
15## arrays below. The {#} is a meta-marker -- it marks where the marker should
16## go.
cb79f740 17##
af01601c
KW
18## Returns empty string if that is what is expected. Otherwise, handles
19## either a scalar, turning it into a single element array; or a ref to an
20## array, adjusting each element. If called in array context, returns an
21## array, otherwise the join of all elements
22
cb79f740 23sub fixup_expect {
af01601c
KW
24 my $expect_ref = shift;
25 return if $expect_ref eq "";
26
27 my @expect;
28 if (ref $expect_ref) {
29 @expect = @$expect_ref;
30 }
31 else {
32 @expect = $expect_ref;
33 }
34
35 foreach my $element (@expect) {
6d24e9d4 36 $element =~ s/{\#}/in regex; marked by <-- HERE in/;
af01601c
KW
37 $element =~ s/{\#}/ <-- HERE /;
38 $element .= " at ";
39 }
40 return wantarray ? @expect : join "", @expect;
cb79f740 41}
b45f050a 42
cb79f740
NC
43my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1;
44my $inf_p1 = $inf_m1 + 2;
b45f050a
JF
45
46##
47## Key-value pairs of code/error of code that should have fatal errors.
48##
49my @death =
50(
6d24e9d4 51 '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/',
b45f050a 52
58e23c8d 53 '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/',
b45f050a 54
58e23c8d 55 '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/',
b45f050a 56
6d24e9d4 57 '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/',
b45f050a 58
9da1dd8f 59 '/(?{ 1/' => 'Missing right curly or square bracket',
b45f050a 60
6d24e9d4 61 '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/',
b45f050a 62
6d24e9d4 63 '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/',
b45f050a 64
6d24e9d4 65 '/(?(x)y|x)/' => 'Unknown switch condition (?(x) {#} m/(?({#}x)y|x)/',
b45f050a 66
6d24e9d4 67 '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/',
b45f050a 68
6d24e9d4
KW
69 '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/',
70 '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/',
71 '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/',
72 '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/',
73 '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/',
74 '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/',
75 '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/',
76 '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/',
77 '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/',
78 '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/',
79 '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
80 '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/',
81 '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/',
82 '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/',
83 '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/',
84 '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/',
85'/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/',
86'/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/',
87'/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/',
88'/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
cc74c5bd 89
6d24e9d4 90 '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
b45f050a 91
6d24e9d4 92 "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/",
b45f050a 93
b45f050a 94
6d24e9d4 95 '/x**/' => 'Nested quantifiers {#} m/x**{#}/',
b45f050a 96
6d24e9d4 97 '/x[/' => 'Unmatched [ {#} m/x[{#}/',
b45f050a 98
6d24e9d4 99 '/*/', => 'Quantifier follows nothing {#} m/*{#}/',
b45f050a 100
6d24e9d4 101 '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/',
b45f050a 102
6d24e9d4 103 '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/',
b45f050a 104
6d24e9d4 105 '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/',
b45f050a 106
779fedd7 107 '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/',
76cccc4d
KW
108 '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/',
109
40809656 110 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
b45f050a 111
6d24e9d4
KW
112 '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/',
113 '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/',
114
115 '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/',
116 '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/',
117
118 '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/',
119 '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/',
120
121 '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/',
122 '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/',
123
124 '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/',
125
126 '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/',
127
128 '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/',
129
130 '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/',
131
132 '/\p/' => 'Empty \p{} {#} m/\p{#}/',
133
134 '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/',
135 '/(?[[[:word]]])/' => "Unmatched ':' in POSIX class {#} m/(?[[[:word{#}]]])/",
136 '/(?[[:word]])/' => "Unmatched ':' in POSIX class {#} m/(?[[:word{#}]])/",
137 '/(?[[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[[:digit:{#} ])/",
138 '/(?[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[:digit:{#} ])/",
139 '/(?[[[::]]])/' => "POSIX class [::] unknown {#} m/(?[[[::]{#}]])/",
140 '/(?[[[:w:]]])/' => "POSIX class [:w:] unknown {#} m/(?[[[:w:]{#}]])/",
141 '/(?[[:w:]])/' => "POSIX class [:w:] unknown {#} m/(?[[:w:]{#}])/",
142 '/(?[a])/' => 'Unexpected character {#} m/(?[a{#}])/',
143 '/(?[\t])/l' => '(?[...]) not valid in locale {#} m/(?[{#}\t])/',
144 '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/',
145 '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/',
146 '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/',
147 '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/',
148 '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/',
149 '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/',
150 '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/',
151 '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/',
152 '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/',
153 '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/',
154 '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/',
155 '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/',
156 '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/',
157 '/(?[ \p{foo} ])/' => 'Property \'foo\' is unknown {#} m/(?[ \p{foo}{#} ])/',
158 '/(?[ \p{ foo = bar } ])/' => 'Property \'foo = bar\' is unknown {#} m/(?[ \p{ foo = bar }{#} ])/',
159 '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/',
3f4fde43
KW
160 '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/',
161 '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/',
162 '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/',
163 '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/',
164 '/(?[ \t + \e # This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # This was supposed to be a comment ])/',
6d24e9d4
KW
165 '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/',
166 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/',
167 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/',
168 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/',
169 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/',
170 'm/(?[[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in character class restricted to one character {#} m/(?[[\N{U+100.300{#}}]])/',
b5864679
KW
171 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/',
172 'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/',
6d24e9d4
KW
173 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/',
174 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/',
175 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/',
176 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/',
177 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/',
178 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/',
179 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/',
f1e1b256
YO
180 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/',
181 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/',
182 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/',
b45f050a 183);
902994e4 184# Tests involving a user-defined charnames translator are in pat_advanced.t
b45f050a 185
af01601c
KW
186# In the following arrays of warnings, the value can be an array of things to
187# expect. If the empty string, it means no warning should be raised.
188
b45f050a 189##
6fe2934b 190## Key-value pairs of code/error of code that should have non-fatal regexp warnings.
b45f050a 191##
cb79f740 192my @warning = (
6d24e9d4
KW
193 'm/\b*/' => '\b* matches null string many times {#} m/\b*{#}/',
194
195 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}/',
196
197 "m'[\\y]'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]/',
198
199 'm/[a-\d]/' => 'False [] range "a-\d" {#} m/[a-\d{#}]/',
200 'm/[\w-x]/' => 'False [] range "\w-" {#} m/[\w-{#}x]/',
201 'm/[a-\pM]/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]/',
202 'm/[\pM-x]/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]/',
203 "m'\\y'" => 'Unrecognized escape \y passed through {#} m/\y{#}/',
204 '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
205 '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/',
206 '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/',
207 '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/',
208 '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/',
6d24e9d4
KW
209 '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/',
210 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/',
211 '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/',
212 '/\q{/' => 'Unrecognized escape \q{ passed through {#} m/\q{{#}/',
213 '/(?=a){1,3}/' => 'Quantifier unexpected on zero-length expression {#} m/(?=a){1,3}{#}/',
688e0391 214 '/(a|b)(?=a){3}/' => 'Quantifier unexpected on zero-length expression {#} m/(a|b)(?=a){3}{#}/',
63fbd1cb
KW
215 '/\_/' => "",
216 '/[\_\0]/' => "",
217 '/[\07]/' => "",
218 '/[\006]/' => "",
219 '/[\0005]/' => "",
6d24e9d4
KW
220 '/[\8\9]/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]/',
221 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]/',
63fbd1cb 222 ],
6d24e9d4
KW
223 '/[:alpha:]/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}/',
224 '/[:zog:]/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:zog:]{#}/',
225 '/[.zog.]/' => 'POSIX syntax [. .] belongs inside character classes {#} m/[.zog.]{#}/',
63fbd1cb 226 '/[a-b]/' => "",
6d24e9d4
KW
227 '/[a-\d]/' => 'False [] range "a-\d" {#} m/[a-\d{#}]/',
228 '/[\d-b]/' => 'False [] range "\d-" {#} m/[\d-{#}b]/',
229 '/[\s-\d]/' => 'False [] range "\s-" {#} m/[\s-{#}\d]/',
230 '/[\d-\s]/' => 'False [] range "\d-" {#} m/[\d-{#}\s]/',
231 '/[a-[:digit:]]/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]/',
232 '/[[:digit:]-b]/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]/',
233 '/[[:alpha:]-[:digit:]]/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]/',
234 '/[[:digit:]-[:alpha:]]/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]/',
235 '/[a\zb]/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]/',
236 '/(?c)/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})/',
237 '/(?-c)/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})/',
238 '/(?g)/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})/',
239 '/(?-g)/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})/',
240 '/(?o)/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})/',
241 '/(?-o)/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})/',
242 '/(?g-o)/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)/',
243 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})/',
63fbd1cb 244 ],
6d24e9d4
KW
245 '/(?g-c)/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)/',
246 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})/',
63fbd1cb
KW
247 ],
248 # (?c) means (?g) error won't be thrown
6d24e9d4
KW
249 '/(?o-cg)/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)/',
250 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)/',
63fbd1cb 251 ],
6d24e9d4
KW
252 '/(?ogc)/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)/',
253 'Useless (?g) - use /g modifier {#} m/(?og{#}c)/',
254 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})/',
63fbd1cb 255 ],
6fe2934b
KW
256);
257
258my @experimental_regex_sets = (
6d24e9d4 259 '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/',
b45f050a
JF
260);
261
63fbd1cb 262my @deprecated = (
d7bb0749
KW
263 '/a\b{cde/' => '"\b{" is deprecated; use "\b\{" or "\b[{]" instead {#} m/a\{#}b{cde/',
264 '/a\B{cde/' => '"\B{" is deprecated; use "\B\{" or "\B[{]" instead {#} m/a\{#}B{cde/',
ff56e4f1 265 'use utf8; /(?x)\\85\85\\85/' => 'Escape literal pattern white space under /x {#} m/(?x)\\85\85{#}\\85/',
000947ad
KW
266 '/((?# This is a comment in the middle of a token)?:foo)/' => 'In \'(?...)\', splitting the initial \'(?\' is deprecated {#} m/((?# This is a comment in the middle of a token)?{#}:foo)/',
267 '/((?# This is a comment in the middle of a token)*FAIL)/' => 'In \'(*VERB...)\', splitting the initial \'(*\' is deprecated {#} m/((?# This is a comment in the middle of a token)*{#}FAIL)/',
63fbd1cb
KW
268);
269
cb79f740
NC
270while (my ($regex, $expect) = splice @death, 0, 2) {
271 my $expect = fixup_expect($expect);
3f4fde43 272 no warnings 'experimental::regex_sets';
40809656 273 # skip the utf8 test on EBCDIC since they do not die
cb79f740 274 next if $::IS_EBCDIC && $regex =~ /utf8/;
b45f050a 275
cb79f740
NC
276 warning_is(sub {
277 $_ = "x";
278 eval $regex;
40e98def
KW
279 like($@, qr/\Q$expect/, $regex);
280 }, undef, "... and died without any other warnings");
b45f050a
JF
281}
282
63fbd1cb 283foreach my $ref (\@warning, \@experimental_regex_sets, \@deprecated) {
6fe2934b
KW
284 my $warning_type = ($ref == \@warning)
285 ? 'regexp'
63fbd1cb 286 : ($ref == \@deprecated)
c2a42ab2 287 ? 'regexp, deprecated'
63fbd1cb 288 : 'experimental::regex_sets';
b42857f3 289 while (my ($regex, $expect) = splice @$ref, 0, 2) {
af01601c
KW
290 my @expect = fixup_expect($expect);
291 {
292 $_ = "x";
293 no warnings;
294 eval $regex;
295 }
296 if (is($@, "", "$regex did not die")) {
297 my @got = capture_warnings(sub {
298 $_ = "x";
299 eval $regex });
300 my $count = @expect;
301 if (! is(scalar @got, scalar @expect, "... and gave expected number ($count) of warnings")) {
302 if (@got < @expect) {
303 $count = @got;
304 note "Expected warnings not gotten:\n\t" . join "\n\t", @expect[$count .. $#expect];
305 }
306 else {
307 note "Unexpected warnings gotten:\n\t" . join("\n\t", @got[$count .. $#got]);
308 }
309 }
310 foreach my $i (0 .. $count - 1) {
b0b90d25
KW
311 if (! like($got[$i], qr/\Q$expect[$i]/, "... and gave expected warning")) {
312 chomp($got[$i]);
313 chomp($expect[$i]);
314 diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'");
315 }
316 else {
af01601c
KW
317 ok (0 == capture_warnings(sub {
318 $_ = "x";
6fe2934b 319 eval "no warnings '$warning_type'; $regex;" }
af01601c
KW
320 ),
321 "... and turning off '$warning_type' warnings suppressed it");
9a5996c9
FC
322 # Test that whether the warning is on by default is
323 # correct. Experimental and deprecated warnings are;
324 # others are not. This test relies on the fact that we
325 # are outside the scope of any ‘use warnings’.
326 local $^W;
327 my $on = 'on' x ($warning_type ne 'regexp');
328 ok !!$on ==
329 capture_warnings(sub { $_ = "x"; eval $regex }),
330 "... and the warning is " . ($on||'off')
331 . " by default";
af01601c
KW
332 }
333 }
b42857f3 334 }
6fe2934b
KW
335 }
336}
b45f050a 337
cb79f740 338done_testing();