This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move t/lib/warnings/regcomp to t/re/reg_mesg.t
[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) {
36 $element =~ s/{\#}/<-- HERE/;
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(
7253e4e3 51 '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in 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
7253e4e3 57 '/(?@)/' => 'Sequence (?@...) not implemented in regex; marked by {#} in m/(?@{#})/',
b45f050a 58
9da1dd8f 59 '/(?{ 1/' => 'Missing right curly or square bracket',
b45f050a 60
7253e4e3 61 '/(?(1x))/' => 'Switch condition not recognized in regex; marked by {#} in m/(?(1x{#}))/',
b45f050a 62
7253e4e3 63 '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches in regex; marked by {#} in m/(?(1)x|y|{#}z)/',
b45f050a 64
7253e4e3 65 '/(?(x)y|x)/' => 'Unknown switch condition (?(x) in regex; marked by {#} in m/(?({#}x)y|x)/',
b45f050a 66
7253e4e3 67 '/(?/' => 'Sequence (? incomplete in regex; marked by {#} in m/(?{#}/',
b45f050a 68
7253e4e3 69 '/(?;x/' => 'Sequence (?;...) not recognized in regex; marked by {#} in m/(?;{#}x/',
1f4f6bf1 70 '/(?<;x/' => 'Group name must start with a non-digit word character in regex; marked by {#} in m/(?<;{#}x/',
cc74c5bd
ST
71 '/(?\ix/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}ix/',
72 '/(?\mx/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}mx/',
73 '/(?\:x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}:x/',
74 '/(?\=x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}=x/',
75 '/(?\!x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}!x/',
76 '/(?\<=x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}<=x/',
77 '/(?\<!x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}<!x/',
78 '/(?\>x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}>x/',
9de15fec
KW
79 '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i:foo)/',
80 '/(?^-i)foo/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i)foo/',
81 '/(?^d:foo)/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#}:foo)/',
82 '/(?^d)foo/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#})foo/',
0c96c706
KW
83 '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive in regex; marked by {#} in m/(?^lu{#}:foo)/',
84 '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive in regex; marked by {#} in m/(?^lu{#})foo/',
85'/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive in regex; marked by {#} in m/(?da{#}:foo)/',
86'/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice in regex; marked by {#} in m/(?lil{#}:foo)/',
87'/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice in regex; marked by {#} in m/(?aaia{#}:foo)/',
9442e3b8 88'/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" in regex; marked by {#} in m/(?i-l{#}:foo)/',
cc74c5bd 89
7253e4e3 90 '/((x)/' => 'Unmatched ( in regex; marked by {#} in m/({#}(x)/',
b45f050a 91
7253e4e3 92 "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 in regex; marked by {#} in m/x{{#}$inf_p1}/",
b45f050a 93
b45f050a 94
7253e4e3 95 '/x**/' => 'Nested quantifiers in regex; marked by {#} in m/x**{#}/',
b45f050a 96
7253e4e3 97 '/x[/' => 'Unmatched [ in regex; marked by {#} in m/x[{#}/',
b45f050a 98
7253e4e3 99 '/*/', => 'Quantifier follows nothing in regex; marked by {#} in m/*{#}/',
b45f050a 100
7253e4e3 101 '/\p{x/' => 'Missing right brace on \p{} in regex; marked by {#} in m/\p{{#}x/',
b45f050a 102
169da838 103 '/[\p{x]/' => 'Missing right brace on \p{} in regex; marked by {#} in m/[\p{{#}x]/',
b45f050a 104
7253e4e3 105 '/(x)\2/' => 'Reference to nonexistent group in regex; marked by {#} in m/(x)\2{#}/',
b45f050a 106
40809656 107 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
b45f050a 108
b8de99ca
KW
109 '/\x{1/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{1{#}/',
110 '/\x{X/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{{#}X/',
b45f050a 111
169da838 112 '/[\x{X]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{{#}X]/',
b8de99ca 113 '/[\x{A]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{A{#}]/',
b45f050a 114
b8de99ca
KW
115 '/\o{1/' => 'Missing right brace on \o{ in regex; marked by {#} in m/\o{1{#}/',
116 '/\o{X/' => 'Missing right brace on \o{ in regex; marked by {#} in m/\o{{#}X/',
9ffc7554
KW
117
118 '/[\o{X]/' => 'Missing right brace on \o{ in regex; marked by {#} in m/[\o{{#}X]/',
b8de99ca 119 '/[\o{7]/' => 'Missing right brace on \o{ in regex; marked by {#} in m/[\o{7{#}]/',
9ffc7554 120
7253e4e3 121 '/[[:barf:]]/' => 'POSIX class [:barf:] unknown in regex; marked by {#} in m/[[:barf:]{#}]/',
b45f050a 122
7253e4e3 123 '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=barf=]{#}]/',
b45f050a 124
7253e4e3 125 '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions in regex; marked by {#} in m/[[.barf.]{#}]/',
b42857f3 126
7253e4e3 127 '/[z-a]/' => 'Invalid [] range "z-a" in regex; marked by {#} in m/[z-a{#}]/',
5528c7ba
RGS
128
129 '/\p/' => 'Empty \p{} in regex; marked by {#} in m/\p{#}/',
130
131 '/\P{}/' => 'Empty \P{} in regex; marked by {#} in m/\P{{#}}/',
3f4fde43
KW
132 '/(?[[[:word]]])/' => "Unmatched ':' in POSIX class in regex; marked by {#} in m/(?[[[:word{#}]]])/",
133 '/(?[[:word]])/' => "Unmatched ':' in POSIX class in regex; marked by {#} in m/(?[[:word{#}]])/",
134 '/(?[[[:digit: ])/' => "Unmatched '[' in POSIX class in regex; marked by {#} in m/(?[[[:digit:{#} ])/",
135 '/(?[[:digit: ])/' => "Unmatched '[' in POSIX class in regex; marked by {#} in m/(?[[:digit:{#} ])/",
136 '/(?[[[::]]])/' => "POSIX class [::] unknown in regex; marked by {#} in m/(?[[[::]{#}]])/",
137 '/(?[[[:w:]]])/' => "POSIX class [:w:] unknown in regex; marked by {#} in m/(?[[[:w:]{#}]])/",
138 '/(?[[:w:]])/' => "POSIX class [:w:] unknown in regex; marked by {#} in m/(?[[:w:]{#}])/",
139 '/(?[a])/' => 'Unexpected character in regex; marked by {#} in m/(?[a{#}])/',
140 '/(?[\t])/l' => '(?[...]) not valid in locale in regex; marked by {#} in m/(?[{#}\t])/',
141 '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand in regex; marked by {#} in m/(?[ +{#} \t ])/',
142 '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand in regex; marked by {#} in m/(?[ \cK - ( +{#} \t ) ])/',
143 '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator in regex; marked by {#} in m/(?[ \cK ({#} \t ) ])/',
144 '/(?[ \cK \t ])/' => 'Operand with no preceding operator in regex; marked by {#} in m/(?[ \cK \t{#} ])/',
145 '/(?[ \0004 ])/' => 'Need exactly 3 octal digits in regex; marked by {#} in m/(?[ \0004 {#}])/',
146 '/(?[ \05 ])/' => 'Need exactly 3 octal digits in regex; marked by {#} in m/(?[ \05 {#}])/',
147 '/(?[ \o{1038} ])/' => 'Non-octal character in regex; marked by {#} in m/(?[ \o{1038{#}} ])/',
148 '/(?[ \o{} ])/' => 'Number with no digits in regex; marked by {#} in m/(?[ \o{}{#} ])/',
149 '/(?[ \x{defg} ])/' => 'Non-hex character in regex; marked by {#} in m/(?[ \x{defg{#}} ])/',
150 '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters in regex; marked by {#} in m/(?[ \xabc{#}def ])/',
151 '/(?[ \x{} ])/' => 'Number with no digits in regex; marked by {#} in m/(?[ \x{}{#} ])/',
152 '/(?[ \cK + ) ])/' => 'Unexpected \')\' in regex; marked by {#} in m/(?[ \cK + ){#} ])/',
153 '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' in regex; marked by {#} in m/(?[ \cK + {#}])/',
154 '/(?[ \p{foo} ])/' => 'Property \'foo\' is unknown in regex; marked by {#} in m/(?[ \p{foo}{#} ])/',
155 '/(?[ \p{ foo = bar } ])/' => 'Property \'foo = bar\' is unknown in regex; marked by {#} in m/(?[ \p{ foo = bar }{#} ])/',
156 '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class in regex; marked by {#} in m/(?[ \8{#} ])/',
157 '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/',
158 '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/',
159 '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/',
160 '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/',
161 '/(?[ \t + \e # This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # This was supposed to be a comment ])/',
162 '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' in regex; marked by {#} in m/(?[ {#}])/',
163 'm/(?[[a-\d]])/' => 'False [] range "a-\d" in regex; marked by {#} in m/(?[[a-\d{#}]])/',
164 'm/(?[[\w-x]])/' => 'False [] range "\w-" in regex; marked by {#} in m/(?[[\w-{#}x]])/',
165 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" in regex; marked by {#} in m/(?[[a-\pM{#}]])/',
166 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" in regex; marked by {#} in m/(?[[\pM-{#}x]])/',
902994e4 167 'm/(?[[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in character class restricted to one character in regex; marked by {#} in m/(?[[\N{U+100.300{#}}]])/',
63fbd1cb
KW
168 'm/\o{/' => 'Missing right brace on \o{ in regex; marked by {#} in m/\o{{#}/',
169 'm/\o/' => 'Missing braces on \o{} in regex; marked by {#} in m/\o{#}/',
170 'm/\o{}/' => 'Number with no digits in regex; marked by {#} in m/\o{}{#}/',
171 'm/[\o{]/' => 'Missing right brace on \o{ in regex; marked by {#} in m/[\o{{#}]/',
172 'm/[\o]/' => 'Missing braces on \o{} in regex; marked by {#} in m/[\o{#}]/',
173 'm/[\o{}]/' => 'Number with no digits in regex; marked by {#} in m/[\o{}{#}]/',
174 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i:foo)/',
b45f050a 175);
902994e4 176# Tests involving a user-defined charnames translator are in pat_advanced.t
b45f050a 177
af01601c
KW
178# In the following arrays of warnings, the value can be an array of things to
179# expect. If the empty string, it means no warning should be raised.
180
b45f050a 181##
6fe2934b 182## Key-value pairs of code/error of code that should have non-fatal regexp warnings.
b45f050a 183##
cb79f740 184my @warning = (
7253e4e3 185 'm/\b*/' => '\b* matches null string many times in regex; marked by {#} in m/\b*{#}/',
b45f050a 186
7253e4e3 187 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:blank:]{#}/',
b45f050a 188
7253e4e3 189 "m'[\\y]'" => 'Unrecognized escape \y in character class passed through in regex; marked by {#} in m/[\y{#}]/',
b45f050a 190
7253e4e3
RK
191 'm/[a-\d]/' => 'False [] range "a-\d" in regex; marked by {#} in m/[a-\d{#}]/',
192 'm/[\w-x]/' => 'False [] range "\w-" in regex; marked by {#} in m/[\w-{#}x]/',
f81125e2
JP
193 'm/[a-\pM]/' => 'False [] range "a-\pM" in regex; marked by {#} in m/[a-\pM{#}]/',
194 'm/[\pM-x]/' => 'False [] range "\pM-" in regex; marked by {#} in m/[\pM-{#}x]/',
7253e4e3 195 "m'\\y'" => 'Unrecognized escape \y passed through in regex; marked by {#} in m/\y{#}/',
31c15ce5 196 '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match in regex; marked by {#} in m/x{3,1}{#}/',
5e0a247b
KW
197 '/\08/' => '\'\08\' resolved to \'\o{0}8\' in regex; marked by {#} in m/\08{#}/',
198 '/\018/' => '\'\018\' resolved to \'\o{1}8\' in regex; marked by {#} in m/\018{#}/',
199 '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' in regex; marked by {#} in m/[\08{#}]/',
200 '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' in regex; marked by {#} in m/[\018{#}]/',
63fbd1cb
KW
201 '/\87/' => 'Unrecognized escape \8 passed through in regex; marked by {#} in m/\8{#}7/',
202 '/a\87/' => 'Unrecognized escape \8 passed through in regex; marked by {#} in m/a\8{#}7/',
203 '/a\97/' => 'Unrecognized escape \9 passed through in regex; marked by {#} in m/a\9{#}7/',
204 '/(?=a)*/' => '(?=a)* matches null string many times in regex; marked by {#} in m/(?=a)*{#}/',
205 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through in regex; marked by {#} in m/a\m{#}/',
206 '/\q/' => 'Unrecognized escape \q passed through in regex; marked by {#} in m/\q{#}/',
207 '/\q{/' => 'Unrecognized escape \q{ passed through in regex; marked by {#} in m/\q{{#}/',
208 '/(?=a){1,3}/' => 'Quantifier unexpected on zero-length expression in regex; marked by {#} in m/(?=a){1,3}{#}/',
209 '/\_/' => "",
210 '/[\_\0]/' => "",
211 '/[\07]/' => "",
212 '/[\006]/' => "",
213 '/[\0005]/' => "",
214 '/[\8\9]/' => ['Unrecognized escape \8 in character class passed through in regex; marked by {#} in m/[\8{#}\9]/',
215 'Unrecognized escape \9 in character class passed through in regex; marked by {#} in m/[\8\9{#}]/',
216 ],
217 '/[:alpha:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:alpha:]{#}/',
218 '/[:zog:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:zog:]{#}/',
219 '/[.zog.]/' => 'POSIX syntax [. .] belongs inside character classes in regex; marked by {#} in m/[.zog.]{#}/',
220 '/[a-b]/' => "",
221 '/[a-\d]/' => 'False [] range "a-\d" in regex; marked by {#} in m/[a-\d{#}]/',
222 '/[\d-b]/' => 'False [] range "\d-" in regex; marked by {#} in m/[\d-{#}b]/',
223 '/[\s-\d]/' => 'False [] range "\s-" in regex; marked by {#} in m/[\s-{#}\d]/',
224 '/[\d-\s]/' => 'False [] range "\d-" in regex; marked by {#} in m/[\d-{#}\s]/',
225 '/[a-[:digit:]]/' => 'False [] range "a-[:digit:]" in regex; marked by {#} in m/[a-[:digit:]{#}]/',
226 '/[[:digit:]-b]/' => 'False [] range "[:digit:]-" in regex; marked by {#} in m/[[:digit:]-{#}b]/',
227 '/[[:alpha:]-[:digit:]]/' => 'False [] range "[:alpha:]-" in regex; marked by {#} in m/[[:alpha:]-{#}[:digit:]]/',
228 '/[[:digit:]-[:alpha:]]/' => 'False [] range "[:digit:]-" in regex; marked by {#} in m/[[:digit:]-{#}[:alpha:]]/',
229 '/[a\zb]/' => 'Unrecognized escape \z in character class passed through in regex; marked by {#} in m/[a\z{#}b]/',
230 '/(?c)/' => 'Useless (?c) - use /gc modifier in regex; marked by {#} in m/(?c{#})/',
231 '/(?-c)/' => 'Useless (?-c) - don\'t use /gc modifier in regex; marked by {#} in m/(?-c{#})/',
232 '/(?g)/' => 'Useless (?g) - use /g modifier in regex; marked by {#} in m/(?g{#})/',
233 '/(?-g)/' => 'Useless (?-g) - don\'t use /g modifier in regex; marked by {#} in m/(?-g{#})/',
234 '/(?o)/' => 'Useless (?o) - use /o modifier in regex; marked by {#} in m/(?o{#})/',
235 '/(?-o)/' => 'Useless (?-o) - don\'t use /o modifier in regex; marked by {#} in m/(?-o{#})/',
236 '/(?g-o)/' => [ 'Useless (?g) - use /g modifier in regex; marked by {#} in m/(?g{#}-o)/',
237 'Useless (?-o) - don\'t use /o modifier in regex; marked by {#} in m/(?g-o{#})/',
238 ],
239 '/(?g-c)/' => [ 'Useless (?g) - use /g modifier in regex; marked by {#} in m/(?g{#}-c)/',
240 'Useless (?-c) - don\'t use /gc modifier in regex; marked by {#} in m/(?g-c{#})/',
241 ],
242 # (?c) means (?g) error won't be thrown
243 '/(?o-cg)/' => [ 'Useless (?o) - use /o modifier in regex; marked by {#} in m/(?o{#}-cg)/',
244 'Useless (?-c) - don\'t use /gc modifier in regex; marked by {#} in m/(?o-c{#}g)/',
245 ],
246 '/(?ogc)/' => [ 'Useless (?o) - use /o modifier in regex; marked by {#} in m/(?o{#}gc)/',
247 'Useless (?g) - use /g modifier in regex; marked by {#} in m/(?og{#}c)/',
248 'Useless (?c) - use /gc modifier in regex; marked by {#} in m/(?ogc{#})/',
249 ],
6fe2934b
KW
250);
251
252my @experimental_regex_sets = (
3f4fde43 253 '/(?[ \t ])/' => 'The regex_sets feature is experimental in regex; marked by {#} in m/(?[{#} \t ])/',
b45f050a
JF
254);
255
63fbd1cb
KW
256my @deprecated = (
257 '/a\b{cde/' => '"\b{" is deprecated; use "\b\{" instead in regex; marked by {#} in m/a\{#}b{cde/',
258 '/a\B{cde/' => '"\B{" is deprecated; use "\B\{" instead in regex; marked by {#} in m/a\{#}B{cde/',
259);
260
cb79f740
NC
261while (my ($regex, $expect) = splice @death, 0, 2) {
262 my $expect = fixup_expect($expect);
3f4fde43 263 no warnings 'experimental::regex_sets';
40809656 264 # skip the utf8 test on EBCDIC since they do not die
cb79f740 265 next if $::IS_EBCDIC && $regex =~ /utf8/;
b45f050a 266
cb79f740
NC
267 warning_is(sub {
268 $_ = "x";
269 eval $regex;
40e98def
KW
270 like($@, qr/\Q$expect/, $regex);
271 }, undef, "... and died without any other warnings");
b45f050a
JF
272}
273
63fbd1cb 274foreach my $ref (\@warning, \@experimental_regex_sets, \@deprecated) {
6fe2934b
KW
275 my $warning_type = ($ref == \@warning)
276 ? 'regexp'
63fbd1cb
KW
277 : ($ref == \@deprecated)
278 ? 'deprecated'
279 : 'experimental::regex_sets';
b42857f3 280 while (my ($regex, $expect) = splice @$ref, 0, 2) {
af01601c
KW
281 my @expect = fixup_expect($expect);
282 {
283 $_ = "x";
284 no warnings;
285 eval $regex;
286 }
287 if (is($@, "", "$regex did not die")) {
288 my @got = capture_warnings(sub {
289 $_ = "x";
290 eval $regex });
291 my $count = @expect;
292 if (! is(scalar @got, scalar @expect, "... and gave expected number ($count) of warnings")) {
293 if (@got < @expect) {
294 $count = @got;
295 note "Expected warnings not gotten:\n\t" . join "\n\t", @expect[$count .. $#expect];
296 }
297 else {
298 note "Unexpected warnings gotten:\n\t" . join("\n\t", @got[$count .. $#got]);
299 }
300 }
301 foreach my $i (0 .. $count - 1) {
302 if (like($got[$i], qr/\Q$expect[$i]/, "... and gave expected warning[$i]")) {
303 ok (0 == capture_warnings(sub {
304 $_ = "x";
6fe2934b 305 eval "no warnings '$warning_type'; $regex;" }
af01601c
KW
306 ),
307 "... and turning off '$warning_type' warnings suppressed it");
308 }
309 }
b42857f3 310 }
6fe2934b
KW
311 }
312}
b45f050a 313
cb79f740 314done_testing();