Login
Second attempt to provide warnings when a useless "## no critic"
[gknop/Perl-Critic.git] / t / 03_useless_pragmas.t
1 #!perl
2
3 ##############################################################################
4 #     $URL$
5 #    $Date$
6 #   $Author$
7 # $Revision$
8 ##############################################################################
9
10 use 5.006001;
11 use strict;
12 use warnings;
13
14 #-----------------------------------------------------------------------------
15
16 our $VERSION = '1.093_01';
17
18 #-----------------------------------------------------------------------------
19
20 use Test::More (tests => 1);
21 use Perl::Critic::PolicyFactory (test => 1);
22 use Perl::Critic::Document;
23 use PPI::Document;
24
25 #-----------------------------------------------------------------------------
26
27 my $violation_free_code = <<'END_PERL';
28
29 $foo = 0;  ## this line is not disabled
30
31 ## no critic;    
32 $foo = 1;        
33 ## use critic;
34
35 $foo = 2; ## no critic;
36
37 $foo = 3; ## no critic (MagicNumbers)
38
39 sub foo {  ## no critic (ExcessComplexity, BuiltinHomonyms)
40     return 1;
41 }
42
43 sub bar {
44     ## use critic (NoisyQuotes); # runs to end of block
45     return 1;
46 }
47
48 $foo = 5;  ## this line is not disabled
49
50 ## no critic (TwoArgOpen, ProtectPrivateVars); # runs to end of file...
51
52 END_PERL
53
54 my $ppi_doc = PPI::Document->new(\$violation_free_code);
55 my $doc = Perl::Critic::Document->new($ppi_doc);
56
57 my @site_policies = Perl::Critic::PolicyFactory::site_policy_names();
58 $doc->mark_disabled_regions(@site_policies);
59
60 my @empty_violation_list = ();
61 my @got_warnings = $doc->useless_no_critic_warnings(@empty_violation_list);
62 is(scalar @got_warnings, 7, 'Got correct numer of useless-no-critic warnings.');
63
64 #-----------------------------------------------------------------------------