Commit | Line | Data |
---|---|---|
faa35de4 JRT |
1 | #!perl |
2 | ||
e68db767 | 3 | ############################################################################## |
27c1472f JRT |
4 | # $URL$ |
5 | # $Date$ | |
6 | # $Author$ | |
7 | # $Revision$ | |
e68db767 | 8 | ############################################################################## |
27c1472f | 9 | |
df6dee2b | 10 | use 5.006001; |
59b05e08 JRT |
11 | use strict; |
12 | use warnings; | |
b9e520c1 JRT |
13 | |
14 | use Test::More (tests => 28); | |
3c5791fe | 15 | use Perl::Critic::PolicyFactory (-test => 1); |
59b05e08 | 16 | |
bf159007 | 17 | # common P::C testing tools |
1c2cd49f | 18 | use Perl::Critic::TestUtils qw(critique); |
b185fa17 ES |
19 | |
20 | #----------------------------------------------------------------------------- | |
21 | ||
173667ce | 22 | our $VERSION = '1.093_01'; |
b185fa17 ES |
23 | |
24 | #----------------------------------------------------------------------------- | |
25 | ||
1c2cd49f | 26 | Perl::Critic::TestUtils::block_perlcriticrc(); |
59b05e08 | 27 | |
dff08b70 | 28 | # Configure Critic not to load certain policies. This |
d50d85bf | 29 | # just makes it a little easier to create test cases |
22ae9686 | 30 | my $profile = { |
57aab077 JRT |
31 | '-CodeLayout::RequireTidyCode' => {}, |
32 | '-Documentation::PodSpelling' => {}, | |
33 | '-ErrorHandling::RequireCheckingReturnValueOfEval' => {}, | |
05e2d404 | 34 | '-Miscellanea::ProhibitUnrestrictedNoCritic' => {}, |
57aab077 JRT |
35 | '-Miscellanea::RequireRcsKeywords' => {}, |
36 | '-ValuesAndExpressions::ProhibitMagicNumbers' => {}, | |
dff08b70 JRT |
37 | }; |
38 | ||
39 | my $code = undef; | |
40 | ||
e68db767 | 41 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
42 | |
43 | $code = <<'END_PERL'; | |
44 | package FOO; | |
45 | use strict; | |
46 | use warnings; | |
47 | our $VERSION = 1.0; | |
48 | ||
49 | require 'some_library.pl'; ## no critic | |
50 | print $crap if $condition; ## no critic | |
aa353719 JRT |
51 | |
52 | 1; | |
59b05e08 JRT |
53 | END_PERL |
54 | ||
d6dc5ff8 ES |
55 | is( |
56 | critique( | |
57 | \$code, | |
58 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
59 | ), | |
60 | 0, | |
61 | 'inline no-critic' | |
62 | ); | |
59b05e08 | 63 | |
e68db767 | 64 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
65 | |
66 | $code = <<'END_PERL'; | |
67 | package FOO; | |
68 | use strict; | |
69 | use warnings; | |
70 | our $VERSION = 1.0; | |
71 | ||
72 | $foo = $bar; | |
73 | ||
74 | ## no critic | |
75 | ||
76 | require 'some_library.pl'; | |
77 | print $crap if $condition; | |
78 | ||
79 | ## use critic | |
80 | ||
81 | $baz = $nuts; | |
aa353719 | 82 | 1; |
59b05e08 JRT |
83 | END_PERL |
84 | ||
d6dc5ff8 ES |
85 | is( |
86 | critique( | |
87 | \$code, | |
88 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
89 | ), | |
90 | 0, | |
91 | 'region no-critic', | |
92 | ); | |
59b05e08 | 93 | |
e68db767 | 94 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
95 | |
96 | $code = <<'END_PERL'; | |
97 | package FOO; | |
98 | use strict; | |
99 | use warnings; | |
100 | our $VERSION = 1.0; | |
101 | ||
102 | for my $foo (@list) { | |
103 | ## no critic | |
104 | $long_int = 12345678; | |
105 | $oct_num = 033; | |
106 | } | |
107 | ||
108 | my $noisy = '!'; | |
aa353719 JRT |
109 | |
110 | 1; | |
59b05e08 JRT |
111 | END_PERL |
112 | ||
d6dc5ff8 ES |
113 | is( |
114 | critique( | |
115 | \$code, | |
116 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
117 | ), | |
118 | 1, | |
119 | 'scoped no-critic', | |
120 | ); | |
59b05e08 | 121 | |
e68db767 | 122 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
123 | |
124 | $code = <<'END_PERL'; | |
125 | package FOO; | |
126 | use strict; | |
127 | use warnings; | |
128 | our $VERSION = 1.0; | |
129 | ||
209eb6db JRT |
130 | { |
131 | ## no critic | |
132 | $long_int = 12345678; | |
133 | $oct_num = 033; | |
134 | } | |
135 | ||
136 | my $noisy = '!'; | |
137 | ||
138 | 1; | |
139 | END_PERL | |
140 | ||
d6dc5ff8 ES |
141 | is( |
142 | critique( | |
143 | \$code, | |
144 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
145 | ), | |
146 | 1, | |
147 | 'scoped no-critic', | |
148 | ); | |
209eb6db | 149 | |
e68db767 | 150 | #----------------------------------------------------------------------------- |
209eb6db JRT |
151 | |
152 | $code = <<'END_PERL'; | |
153 | package FOO; | |
154 | use strict; | |
155 | use warnings; | |
156 | our $VERSION = 1.0; | |
157 | ||
59b05e08 JRT |
158 | ## no critic |
159 | for my $foo (@list) { | |
160 | $long_int = 12345678; | |
161 | $oct_num = 033; | |
162 | } | |
163 | ||
164 | ## use critic | |
165 | my $noisy = '!'; | |
166 | ||
aa353719 | 167 | 1; |
59b05e08 JRT |
168 | END_PERL |
169 | ||
d6dc5ff8 ES |
170 | is( |
171 | critique( | |
172 | \$code, | |
173 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
174 | ), | |
175 | 1, | |
176 | 'region no-critic across a scope', | |
177 | ); | |
59b05e08 | 178 | |
e68db767 | 179 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
180 | |
181 | $code = <<'END_PERL'; | |
182 | package FOO; | |
183 | use strict; | |
184 | use warnings; | |
185 | our $VERSION = 1.0; | |
186 | ||
187 | for my $foo (@list) { | |
188 | ## no critic | |
189 | $long_int = 12345678; | |
190 | $oct_num = 033; | |
191 | ## use critic | |
192 | } | |
193 | ||
194 | my $noisy = '!'; | |
195 | my $empty = ''; | |
196 | ||
aa353719 | 197 | 1; |
59b05e08 JRT |
198 | END_PERL |
199 | ||
d6dc5ff8 ES |
200 | is( |
201 | critique( | |
202 | \$code, | |
203 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
204 | ), | |
205 | 2, | |
206 | 'scoped region no-critic', | |
207 | ); | |
59b05e08 | 208 | |
e68db767 | 209 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
210 | |
211 | $code = <<'END_PERL'; | |
212 | package FOO; | |
213 | use strict; | |
214 | use warnings; | |
215 | our $VERSION = 1.0; | |
216 | ||
217 | ## no critic | |
218 | for my $foo (@list) { | |
219 | $long_int = 12345678; | |
220 | $oct_num = 033; | |
221 | } | |
222 | ||
223 | my $noisy = '!'; | |
224 | my $empty = ''; | |
aa353719 JRT |
225 | |
226 | #No final '1;' | |
59b05e08 JRT |
227 | END_PERL |
228 | ||
d6dc5ff8 ES |
229 | is( |
230 | critique( | |
231 | \$code, | |
232 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
233 | ), | |
234 | 0, | |
235 | 'unterminated no-critic across a scope', | |
236 | ); | |
59b05e08 | 237 | |
e68db767 | 238 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
239 | |
240 | $code = <<'END_PERL'; | |
241 | package FOO; | |
242 | use strict; | |
243 | use warnings; | |
244 | our $VERSION = 1.0; | |
245 | ||
246 | $long_int = 12345678; ## no critic | |
247 | $oct_num = 033; ## no critic | |
248 | my $noisy = '!'; ## no critic | |
249 | my $empty = ''; ## no critic | |
250 | my $empty = ''; ## use critic | |
aa353719 JRT |
251 | |
252 | 1; | |
59b05e08 JRT |
253 | END_PERL |
254 | ||
d6dc5ff8 ES |
255 | is( |
256 | critique( | |
257 | \$code, | |
258 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
259 | ), | |
260 | 1, | |
261 | 'inline use-critic', | |
262 | ); | |
59b05e08 | 263 | |
e68db767 | 264 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
265 | |
266 | $code = <<'END_PERL'; | |
267 | package FOO; | |
268 | use strict; | |
269 | use warnings; | |
270 | our $VERSION = 1.0; | |
271 | ||
272 | $long_int = 12345678; ## no critic | |
273 | $oct_num = 033; ## no critic | |
274 | my $noisy = '!'; ## no critic | |
275 | my $empty = ''; ## no critic | |
276 | ||
277 | $long_int = 12345678; | |
278 | $oct_num = 033; | |
279 | my $noisy = '!'; | |
280 | my $empty = ''; | |
aa353719 JRT |
281 | |
282 | #No final '1;' | |
59b05e08 JRT |
283 | END_PERL |
284 | ||
d6dc5ff8 ES |
285 | is( |
286 | critique( | |
287 | \$code, | |
288 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
289 | ), | |
290 | 5, | |
291 | 'inline no-critic', | |
292 | ); | |
59b05e08 | 293 | |
e68db767 | 294 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
295 | |
296 | $code = <<'END_PERL'; | |
297 | package FOO; | |
298 | use strict; | |
299 | use warnings; | |
300 | our $VERSION = 1.0; | |
301 | ||
302 | $long_int = 12345678; ## no critic | |
303 | $oct_num = 033; ## no critic | |
304 | my $noisy = '!'; ## no critic | |
305 | my $empty = ''; ## no critic | |
306 | ||
aa353719 | 307 | ## no critic |
59b05e08 JRT |
308 | $long_int = 12345678; |
309 | $oct_num = 033; | |
310 | my $noisy = '!'; | |
311 | my $empty = ''; | |
aa353719 JRT |
312 | |
313 | #No final '1;' | |
59b05e08 JRT |
314 | END_PERL |
315 | ||
d6dc5ff8 ES |
316 | is( |
317 | critique( | |
318 | \$code, | |
319 | { | |
320 | -profile => $profile, | |
321 | -severity => 1, | |
322 | -theme => 'core', | |
323 | -force => 1, | |
324 | } | |
325 | ), | |
326 | 9, | |
327 | 'force option', | |
328 | ); | |
59b05e08 | 329 | |
e68db767 | 330 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
331 | |
332 | $code = <<'END_PERL'; | |
333 | package FOO; | |
334 | use strict; | |
335 | use warnings; | |
336 | our $VERSION = 1.0; | |
337 | ||
338 | for my $foo (@list) { | |
aa353719 | 339 | ## no critic |
59b05e08 JRT |
340 | $long_int = 12345678; |
341 | $oct_num = 033; | |
342 | } | |
343 | ||
aa353719 JRT |
344 | my $noisy = '!'; ## no critic |
345 | my $empty = ''; ## no critic | |
346 | ||
347 | 1; | |
59b05e08 JRT |
348 | END_PERL |
349 | ||
d6dc5ff8 ES |
350 | is( |
351 | critique( | |
352 | \$code, | |
353 | { | |
354 | -profile => $profile, | |
355 | -severity => 1, | |
356 | -theme => 'core', | |
357 | -force => 1, | |
358 | } | |
359 | ), | |
360 | 4, | |
361 | 'force option', | |
362 | ); | |
59b05e08 | 363 | |
e68db767 | 364 | #----------------------------------------------------------------------------- |
59b05e08 JRT |
365 | |
366 | $code = <<'END_PERL'; | |
367 | package FOO; | |
368 | use strict; | |
369 | use warnings; | |
370 | our $VERSION = 1.0; | |
371 | ||
372 | for my $foo (@list) { | |
aa353719 | 373 | ## no critic |
59b05e08 JRT |
374 | $long_int = 12345678; |
375 | $oct_num = 033; | |
376 | } | |
377 | ||
aa353719 | 378 | ## no critic |
59b05e08 JRT |
379 | my $noisy = '!'; |
380 | my $empty = ''; | |
aa353719 JRT |
381 | |
382 | #No final '1;' | |
59b05e08 JRT |
383 | END_PERL |
384 | ||
d6dc5ff8 ES |
385 | is( |
386 | critique( | |
387 | \$code, | |
388 | { | |
389 | -profile => $profile, | |
390 | -severity => 1, | |
391 | -theme => 'core', | |
392 | -force => 1, | |
393 | } | |
394 | ), | |
395 | 5, | |
396 | 'force option', | |
397 | ); | |
209eb6db | 398 | |
e68db767 | 399 | #----------------------------------------------------------------------------- |
209eb6db JRT |
400 | # Check that '## no critic' on the top of a block doesn't extend |
401 | # to all code within the block. See RT bug #15295 | |
402 | ||
403 | $code = <<'END_PERL'; | |
404 | package FOO; | |
405 | use strict; | |
406 | use warnings; | |
407 | our $VERSION = 1.0; | |
408 | ||
409 | for ($i;$i++;$i<$j) { ## no critic | |
410 | my $long_int = 12345678; | |
411 | my $oct_num = 033; | |
412 | } | |
413 | ||
414 | unless ( $condition1 | |
415 | && $condition2 ) { ## no critic | |
416 | my $noisy = '!'; | |
417 | my $empty = ''; | |
418 | } | |
419 | ||
420 | 1; | |
421 | END_PERL | |
422 | ||
d6dc5ff8 ES |
423 | is( |
424 | critique( | |
425 | \$code, | |
426 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
427 | ), | |
428 | 4, | |
429 | 'RT bug 15295', | |
430 | ); | |
209eb6db | 431 | |
e68db767 | 432 | #----------------------------------------------------------------------------- |
209eb6db JRT |
433 | # Check that '## no critic' on the top of a block doesn't extend |
434 | # to all code within the block. See RT bug #15295 | |
435 | ||
436 | $code = <<'END_PERL'; | |
437 | package FOO; | |
438 | use strict; | |
439 | use warnings; | |
440 | our $VERSION = 1.0; | |
441 | ||
442 | for ($i; $i++; $i<$j) { ## no critic | |
443 | my $long_int = 12345678; | |
444 | my $oct_num = 033; | |
445 | } | |
446 | ||
447 | #Between blocks now | |
448 | $Global::Variable = "foo"; #Package var; double-quotes | |
449 | ||
450 | unless ( $condition1 | |
451 | && $condition2 ) { ## no critic | |
452 | my $noisy = '!'; | |
453 | my $empty = ''; | |
454 | } | |
455 | ||
456 | 1; | |
457 | END_PERL | |
458 | ||
d6dc5ff8 ES |
459 | is( |
460 | critique( | |
461 | \$code, | |
462 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
463 | ), | |
464 | 6, | |
465 | 'RT bug 15295', | |
466 | ); | |
c70a9ff6 | 467 | |
e68db767 | 468 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
469 | |
470 | $code = <<'END_PERL'; | |
471 | package FOO; | |
472 | use strict; | |
473 | use warnings; | |
474 | our $VERSION = 1.0; | |
475 | ||
5c1bf20d JRT |
476 | sub grep { ## no critic; |
477 | return $foo; | |
478 | } | |
479 | ||
480 | sub grep { return $foo; } ## no critic | |
481 | 1; | |
482 | END_PERL | |
483 | ||
d6dc5ff8 ES |
484 | is( |
485 | critique( | |
486 | \$code, | |
487 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
488 | ), | |
489 | 0, | |
490 | 'no-critic on sub name', | |
491 | ); | |
5c1bf20d | 492 | |
e68db767 | 493 | #----------------------------------------------------------------------------- |
5c1bf20d JRT |
494 | |
495 | $code = <<'END_PERL'; | |
496 | package FOO; | |
497 | use strict; | |
498 | use warnings; | |
499 | our $VERSION = 1.0; | |
500 | ||
501 | sub grep { ## no critic; | |
502 | return undef; #Should find this! | |
503 | } | |
504 | ||
505 | 1; | |
506 | END_PERL | |
507 | ||
d6dc5ff8 ES |
508 | is( |
509 | critique( | |
510 | \$code, | |
511 | {-profile => $profile, -severity =>1, -theme => 'core'} | |
512 | ), | |
513 | 1, | |
514 | 'no-critic on sub name', | |
515 | ); | |
5c1bf20d | 516 | |
e68db767 | 517 | #----------------------------------------------------------------------------- |
5c1bf20d JRT |
518 | |
519 | $code = <<'END_PERL'; | |
520 | package FOO; | |
521 | use strict; | |
522 | use warnings; | |
523 | our $VERSION = 1.0; | |
524 | ||
c48094aa | 525 | ## no critic (NoisyQuotes) |
c70a9ff6 JRT |
526 | my $noisy = '!'; |
527 | my $empty = ''; | |
528 | eval $string; | |
529 | ||
530 | 1; | |
531 | END_PERL | |
532 | ||
d6dc5ff8 ES |
533 | is( |
534 | critique( | |
535 | \$code, | |
536 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
537 | ), | |
538 | 2, | |
539 | 'per-policy no-critic', | |
540 | ); | |
c70a9ff6 | 541 | |
e68db767 | 542 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
543 | |
544 | $code = <<'END_PERL'; | |
545 | package FOO; | |
546 | use strict; | |
547 | use warnings; | |
548 | our $VERSION = 1.0; | |
549 | ||
c48094aa | 550 | ## no critic (ValuesAndExpressions) |
c70a9ff6 JRT |
551 | my $noisy = '!'; |
552 | my $empty = ''; | |
553 | eval $string; | |
554 | ||
555 | 1; | |
556 | END_PERL | |
557 | ||
d6dc5ff8 ES |
558 | is( |
559 | critique( | |
560 | \$code, | |
561 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
562 | ), | |
563 | 1, | |
564 | 'per-policy no-critic', | |
565 | ); | |
c70a9ff6 | 566 | |
e68db767 | 567 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
568 | |
569 | $code = <<'END_PERL'; | |
570 | package FOO; | |
571 | use strict; | |
572 | use warnings; | |
573 | our $VERSION = 1.0; | |
574 | ||
c48094aa | 575 | ## no critic (Noisy, Empty) |
c70a9ff6 JRT |
576 | my $noisy = '!'; |
577 | my $empty = ''; | |
578 | eval $string; | |
579 | ||
580 | 1; | |
581 | END_PERL | |
582 | ||
d6dc5ff8 ES |
583 | is( |
584 | critique( | |
585 | \$code, | |
586 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
587 | ), | |
588 | 1, | |
589 | 'per-policy no-critic', | |
590 | ); | |
c70a9ff6 | 591 | |
e68db767 | 592 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
593 | |
594 | $code = <<'END_PERL'; | |
595 | package FOO; | |
596 | use strict; | |
597 | use warnings; | |
598 | our $VERSION = 1.0; | |
599 | ||
c48094aa | 600 | ## no critic (NOISY, EMPTY, EVAL) |
c70a9ff6 JRT |
601 | my $noisy = '!'; |
602 | my $empty = ''; | |
603 | eval $string; | |
604 | ||
605 | 1; | |
606 | END_PERL | |
607 | ||
d6dc5ff8 ES |
608 | is( |
609 | critique( | |
610 | \$code, | |
611 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
612 | ), | |
613 | 0, | |
614 | 'per-policy no-critic', | |
615 | ); | |
c70a9ff6 | 616 | |
e68db767 | 617 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
618 | |
619 | $code = <<'END_PERL'; | |
620 | package FOO; | |
621 | use strict; | |
622 | use warnings; | |
623 | our $VERSION = 1.0; | |
624 | ||
c48094aa | 625 | ## no critic (Noisy, Empty, Eval) |
c70a9ff6 JRT |
626 | my $noisy = '!'; |
627 | my $empty = ''; | |
628 | eval $string; | |
629 | ||
630 | ## use critic | |
631 | my $noisy = '!'; | |
632 | my $empty = ''; | |
633 | eval $string; | |
634 | ||
635 | 1; | |
636 | END_PERL | |
637 | ||
d6dc5ff8 ES |
638 | is( |
639 | critique( | |
640 | \$code, | |
641 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
642 | ), | |
643 | 3, | |
644 | 'per-policy no-critic', | |
645 | ); | |
c70a9ff6 | 646 | |
e68db767 | 647 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
648 | |
649 | $code = <<'END_PERL'; | |
650 | package FOO; | |
651 | use strict; | |
652 | use warnings; | |
653 | our $VERSION = 1.0; | |
654 | ||
c48094aa | 655 | ## no critic (Critic::Policy) |
c70a9ff6 JRT |
656 | my $noisy = '!'; |
657 | my $empty = ''; | |
658 | eval $string; | |
659 | ||
660 | 1; | |
661 | END_PERL | |
662 | ||
d6dc5ff8 ES |
663 | is( |
664 | critique( | |
665 | \$code, | |
666 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
667 | ), | |
668 | 0, | |
669 | 'per-policy no-critic', | |
670 | ); | |
c70a9ff6 | 671 | |
e68db767 | 672 | #----------------------------------------------------------------------------- |
c70a9ff6 JRT |
673 | |
674 | $code = <<'END_PERL'; | |
675 | package FOO; | |
676 | use strict; | |
677 | use warnings; | |
678 | our $VERSION = 1.0; | |
679 | ||
c48094aa | 680 | ## no critic (Foo::Bar, Baz, Boom) |
c70a9ff6 JRT |
681 | my $noisy = '!'; |
682 | my $empty = ''; | |
683 | eval $string; | |
684 | ||
685 | 1; | |
686 | END_PERL | |
687 | ||
d6dc5ff8 ES |
688 | is( |
689 | critique( | |
690 | \$code, | |
691 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
692 | ), | |
693 | 3, | |
694 | 'per-policy no-critic', | |
695 | ); | |
55ae7242 | 696 | |
e68db767 | 697 | #----------------------------------------------------------------------------- |
55ae7242 JRT |
698 | |
699 | $code = <<'END_PERL'; | |
700 | package FOO; | |
701 | use strict; | |
702 | use warnings; | |
703 | our $VERSION = 1.0; | |
704 | ||
c48094aa | 705 | ## no critic (Noisy) |
55ae7242 JRT |
706 | my $noisy = '!'; #Should not find this |
707 | my $empty = ''; #Should find this | |
708 | ||
709 | sub foo { | |
710 | ||
c48094aa | 711 | ## no critic (Empty) |
55ae7242 JRT |
712 | my $nosiy = '!'; #Should not find this |
713 | my $empty = ''; #Should not find this | |
714 | ## use critic; | |
715 | ||
716 | return 1; | |
717 | } | |
718 | ||
719 | my $nosiy = '!'; #Should not find this | |
720 | my $empty = ''; #Should find this | |
721 | ||
722 | 1; | |
723 | END_PERL | |
724 | ||
d6dc5ff8 ES |
725 | is( |
726 | critique( | |
727 | \$code, | |
728 | {-profile => $profile, -severity => 1, -theme => 'core'} | |
729 | ), | |
730 | 2, | |
731 | 'per-policy no-critic', | |
732 | ); | |
1bef6e21 | 733 | |
e68db767 | 734 | #----------------------------------------------------------------------------- |
c0137eab JRT |
735 | $code = <<'END_PERL'; |
736 | package FOO; | |
737 | ||
738 | use strict; | |
739 | use warnings; | |
740 | our $VERSION = 1.0; | |
741 | ||
c296c678 | 742 | # with parentheses |
c0137eab JRT |
743 | my $noisy = '!'; ##no critic (NoisyQuotes) |
744 | barf() unless $$ eq ''; ##no critic (Postfix,Empty,Punctuation) | |
745 | barf() unless $$ eq ''; ##no critic (Postfix , Empty , Punctuation) | |
746 | barf() unless $$ eq ''; ##no critic (Postfix Empty Punctuation) | |
747 | ||
3cab0bc9 | 748 | # qw() style |
c0137eab JRT |
749 | my $noisy = '!'; ##no critic qw(NoisyQuotes); |
750 | barf() unless $$ eq ''; ##no critic qw(Postfix,Empty,Punctuation) | |
751 | barf() unless $$ eq ''; ##no critic qw(Postfix , Empty , Punctuation) | |
752 | barf() unless $$ eq ''; ##no critic qw(Postfix Empty Punctuation) | |
753 | ||
c296c678 | 754 | # no parentheses |
3cab0bc9 JRT |
755 | my $noisy = '!'; ##no critic NoisyQuotes; |
756 | barf() unless $$ eq ''; ##no critic Postfix,Empty,Punctuation; | |
757 | barf() unless $$ eq ''; ##no critic Postfix , Empty , Punctuation; | |
758 | barf() unless $$ eq ''; ##no critic Postfix Empty Punctuation; | |
759 | ||
c0137eab JRT |
760 | 1; |
761 | END_PERL | |
762 | ||
d6dc5ff8 ES |
763 | is( |
764 | critique( | |
765 | \$code, | |
766 | {-profile => $profile, -severity => 1, -theme => 'core'}, | |
767 | ), | |
768 | 0, | |
769 | 'no critic: syntaxes', | |
770 | ); | |
c0137eab | 771 | |
e68db767 | 772 | #----------------------------------------------------------------------------- |
1bef6e21 JRT |
773 | # Most policies apply to a particular type of PPI::Element and usually |
774 | # only return one Violation at a time. But the next three cases | |
775 | # involve policies that apply to the whole document and can return | |
776 | # multiple violations at a time. These tests make sure that the 'no | |
777 | # critic' pragmas are effective with those Policies | |
e68db767 | 778 | #----------------------------------------------------------------------------- |
1bef6e21 JRT |
779 | |
780 | $code = <<'END_PERL'; | |
781 | package FOO; | |
782 | ||
783 | #Code before 'use strict' | |
784 | my $foo = 'baz'; ## no critic | |
c0137eab | 785 | my $bar = 42; # Should find this |
1bef6e21 JRT |
786 | |
787 | use strict; | |
788 | use warnings; | |
789 | our $VERSION = 1.0; | |
790 | ||
791 | 1; | |
792 | END_PERL | |
793 | ||
d6dc5ff8 ES |
794 | is( |
795 | critique( | |
796 | \$code, | |
797 | {-profile => $profile, -severity => 5, -theme => 'core'}, | |
798 | ), | |
799 | 1, | |
800 | 'no critic & RequireUseStrict', | |
801 | ); | |
1bef6e21 | 802 | |
e68db767 | 803 | #----------------------------------------------------------------------------- |
1bef6e21 JRT |
804 | |
805 | $code = <<'END_PERL'; | |
806 | package FOO; | |
c0137eab | 807 | use strict; |
1bef6e21 JRT |
808 | |
809 | #Code before 'use warnings' | |
810 | my $foo = 'baz'; ## no critic | |
811 | my $bar = 42; # Should find this | |
812 | ||
1bef6e21 JRT |
813 | use warnings; |
814 | our $VERSION = 1.0; | |
815 | ||
816 | 1; | |
817 | END_PERL | |
818 | ||
d6dc5ff8 ES |
819 | is( |
820 | critique( | |
821 | \$code, | |
822 | {-profile => $profile, -severity => 4, -theme => 'core'}, | |
823 | ), | |
824 | 1, | |
825 | 'no critic & RequireUseWarnings', | |
826 | ); | |
1bef6e21 | 827 | |
e68db767 | 828 | #----------------------------------------------------------------------------- |
1bef6e21 JRT |
829 | |
830 | $code = <<'END_PERL'; | |
55944022 JRT |
831 | use strict; ##no critic |
832 | use warnings; #should find this | |
833 | my $bar = 42; #this one will be squelched | |
1bef6e21 JRT |
834 | |
835 | package FOO; | |
836 | ||
1bef6e21 JRT |
837 | our $VERSION = 1.0; |
838 | ||
839 | 1; | |
840 | END_PERL | |
841 | ||
d6dc5ff8 ES |
842 | is( |
843 | critique( | |
844 | \$code, | |
845 | {-profile => $profile, -severity => 4, -theme => 'core'}, | |
846 | ), | |
847 | 1, | |
848 | 'no critic & RequireExplicitPackage', | |
849 | ); | |
737d3b65 | 850 | |
34cc6052 ES |
851 | #----------------------------------------------------------------------------- |
852 | ||
853 | # ensure we run true if this test is loaded by | |
854 | # t/03_pragmas.t_without_optional_dependencies.t | |
855 | 1; | |
856 | ||
55944022 | 857 | ############################################################################## |
737d3b65 CD |
858 | # Local Variables: |
859 | # mode: cperl | |
860 | # cperl-indent-level: 4 | |
861 | # fill-column: 78 | |
862 | # indent-tabs-mode: nil | |
863 | # c-indentation-style: bsd | |
864 | # End: | |
96fed375 | 865 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |