Debian Codegraph @

t/RegularExpressions/ProhibitCaptureWithoutTest.run

raw
1 ## name use without regex
2 ## failures 3
3 ## cut
4 my $foo = $1;
5 my @matches = ($1, $2);
6
7 #-----------------------------------------------------------------------------
8
9 ## name void use without regex
10 ## failures 1
11 ## cut
12 $1
13
14 #-----------------------------------------------------------------------------
15
16 ## name regex but no check on success
17 ## failures 1
18 ## cut
19 'some string' =~ m/(s)/;
20 my $s = $1;
21
22 #-----------------------------------------------------------------------------
23
24 ## name inside a checkblock, but another regex overrides
25 ## failures 1
26 ## cut
27 if (m/(.)/) {
28 'some string' =~ m/(s)/;
29 my $s = $1;
30 }
31
32 #-----------------------------------------------------------------------------
33
34 ## name good passes
35 ## failures 0
36 ## cut
37 if ($str =~ m/(.)/) {
38 return $1;
39 }
40 elsif ($foo =~ s/(b)//) {
41 $bar = $1;
42 }
43
44 if ($str =~ m/(.)/) {
45 while (1) {
46 return $1;
47 }
48 }
49
50 while ($str =~ m/\G(.)/cg) {
51 print $1;
52 }
53
54 print $0; # not affected by policy
55 print $_; # not affected by policy
56 print $f1; # not affected by policy
57
58 my $result = $str =~ m/(.)/;
59 if ($result) {
60 return $1;
61 }
62
63 #-----------------------------------------------------------------------------
64
65 ## name ternary passes
66 ## failures 0
67 ## cut
68 print m/(.)/ ? $1 : 'undef';
69 print !m/(.)/ ? 'undef' : $1;
70 print s/(.)// ? $1 : 'undef';
71 print !s/(.)// ? 'undef' : $1;
72 $foo = m/(.)/ && $1;
73 $foo = !m/(.)/ || $1;
74 $foo = s/(.)// && $1;
75 $foo = !s/(.)// || $1;
76
77 #-----------------------------------------------------------------------------
78
79 ## name Regression for PPI::Statement::Expressions
80 ## failures 0
81 ## cut
82
83 if (m/(\d+)/xms) {
84 $foo = ($1);
85 }
86
87 #-----------------------------------------------------------------------------
88
89 ## name Regression for ternaries with structures
90 ## failures 0
91 ## cut
92
93 $str =~ m/(.)/xms ? foo($1) : die;
94 $str =~ m/(.)/xms ? [$1] : die;
95 $str =~ m/(.)/xms ? { match => $1 } : die;
96
97 #-----------------------------------------------------------------------------
98
99 ## name Failure to match throws exception - RT 36081.
100 ## failures 0
101 ## cut
102
103 m/(foo)/ or die;
104 print $1, "\n";
105 m/(foo)/ or croak;
106 print $1, "\n";
107 m/(foo)/ or confess;
108 print $1, "\n";
109 m/(foo)/ || die;
110 print $1, "\n";
111 m/(foo)/ || croak;
112 print $1, "\n";
113 m/(foo)/ || confess;
114 print $1, "\n";
115
116 #-----------------------------------------------------------------------------
117
118 ## name Failure to match throws exception (regex in outer block) - RT 36081.
119 ## failures 0
120 ## cut
121
122 m/(foo)/ or die;
123 {
124 print $1, "\n";
125 }
126
127 #-----------------------------------------------------------------------------
128
129 ## name Failure to match throws exception (regex in inner block) - RT 36081.
130 ## failures 1
131 ## cut
132
133 {
134 m/(foo)/ or die;
135 }
136 print $1, "\n";
137
138 #-----------------------------------------------------------------------------
139
140 ## name Boolean 'or' without known exception source is an error - RT 36081
141 ## failures 1
142 ## cut
143
144 m/(foo)/ or my_exception_source( 'bar' );
145 print $1, "\n";
146
147 #-----------------------------------------------------------------------------
148
149 ## name Recognize alternate exception sources if told about them - RT 36081
150 ## parms { exception_source => 'my_exception_source' }
151 ## failures 0
152 ## cut
153
154 m/(foo)/ or my_exception_source( 'bar' );
155 print $1, "\n";
156 m/(foo)/ or $self->my_exception_source( 'bar' );
157 print $1, "\n";
158
159 #-----------------------------------------------------------------------------
160
161 ## name Failure to match causes transfer of control - RT 36081.
162 ## failures 0
163 ## cut
164
165 m/(foo)/ or next;
166 print $1, "\n";
167 m/(foo)/ or last;
168 print $1, "\n";
169 m/(foo)/ or redo;
170 print $1, "\n";
171 m/(foo)/ or goto FOO;
172 print $1, "\n";
173 m/(foo)/ or return;
174 print $1, "\n";
175 m/(foo)/ || next;
176 print $1, "\n";
177 m/(foo)/ || last;
178 print $1, "\n";
179 m/(foo)/ || redo;
180 print $1, "\n";
181 m/(foo)/ || goto FOO;
182 print $1, "\n";
183 m/(foo)/ || return;
184 print $1, "\n";
185
186 #-----------------------------------------------------------------------------
187
188 ## name Failure to match causes transfer of control (regex in outer block) - RT 36081.
189 ## failures 0
190 ## cut
191
192 m/(foo)/ or return;
193 {
194 print $1, "\n";
195 }
196
197 #-----------------------------------------------------------------------------
198
199 ## name Failure to match causes transfer of control (regex in inner block) - RT 36081.
200 ## failures 1
201 ## cut
202
203 {
204 m/(foo)/ or return;
205 }
206 print $1, "\n";
207
208 #-----------------------------------------------------------------------------
209
210 ## name Failure to match does not cause transfer of control (regex in inner block) - RT 36081.
211 ## failures 1
212 ## cut
213
214 {
215 m/(foo)/;
216 }
217 print $1, "\n";
218
219 #-----------------------------------------------------------------------------
220
221 ## name goto that transfers around capture - RT 36081.
222 ## failures 0
223 ## cut
224
225 {
226 m/(foo)/ or goto BAR;
227 print $1, "\n";
228 BAR:
229 print "Baz\n";
230 }
231
232 {
233 BAR: m/(foo)/ or goto BAR;
234 print $1, "\n";
235 }
236
237 {
238 m/(foo)/ or goto &bar;
239 print $1, "\n";
240 }
241
242 #-----------------------------------------------------------------------------
243
244 ## name goto that does not transfer around capture - RT 36081.
245 ## failures 1
246 ## cut
247
248 {
249 m/(foo)/ or goto BAR;
250 BAR : print $1, "\n";
251 }
252
253 #-----------------------------------------------------------------------------
254
255 ## name goto that can not be disambiguated - RT 36081.
256 ## failures 1
257 ## cut
258
259 {
260 FOO: m/(foo)/ or goto (qw{FOO BAR BAZ})[$i];
261 BAR: print $1, "\n";
262 BAZ:
263 }
264
265 #-----------------------------------------------------------------------------
266
267 ## name regex in suffix control
268 ## failures 0
269 ## cut
270
271 die unless m/(foo)/;
272 print $1, "\n";
273 last unless m/(foo)/;
274 print $1, "\n";
275 die "Arrrgh" unless m/(foo)/;
276 print $1, "\n";
277
278 #-----------------------------------------------------------------------------
279
280 ## name regex in loop with capture in nested if
281 ## failures 0
282 ## cut
283
284 foreach (qw{foo bar baz}) {
285 next unless m/(foo)/;
286 if ($1) {
287 print "Foo!\n";
288 }
289 }
290
291 #-----------------------------------------------------------------------------
292
293 ## name regex in while, capture in loop
294 ## failures 0
295 ## cut
296
297 while (m/(foo)/) {
298 print $1, "\n";
299 }
300
301 #-----------------------------------------------------------------------------
302
303 ## name Regex followed by "and do {...}" RT #50910
304 ## failures 0
305 ## cut
306
307 m/^commit (.*)/xsm and do {
308 $commit = $1;
309 next;
310 };
311
312 #-----------------------------------------------------------------------------
313
314 ## name regex inside when(){} RT #36081
315 ## failures 0
316 ## cut
317
318 use 5.010;
319
320 given ( 'abc' ) {
321 when ( m/(a)/ ) {
322 say $1;
323 }
324 }
325
326 # Local Variables:
327 # mode: cperl
328 # cperl-indent-level: 4
329 # fill-column: 78
330 # indent-tabs-mode: nil
331 # c-indentation-style: bsd
332 # End:
333 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :