Login
First attempt to warn users when they have an unecessary "## 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 use Test::More (tests => 1);
15 use Perl::Critic::PolicyFactory (test => 1);
16 use Perl::Critic::Document;
17 use PPI::Document;
18
19 #-----------------------------------------------------------------------------
20
21 my $violation_free_code = <<'END_PERL';
22
23 $foo = 0;  ## this line is not disabled
24
25 ## no critic;    #\
26 $foo = 1;        # |-> this block counts as 3 disabled lines
27 ## use critic;   #/
28
29 $foo = 2; ## no critic;
30
31 $foo = 3; ## no critic (MagicNumbers)
32
33 sub foo {  ## no critic (ExcessComplexity, BuiltinHomonyms)
34     return 1;
35 }
36
37 $foo = 5;  ## this line is not disabled
38
39 END_PERL
40
41 my $ppi_doc = PPI::Document->new(\$violation_free_code);
42 my $doc = Perl::Critic::Document->new($ppi_doc);
43
44 my @site_policies = Perl::Critic::PolicyFactory::site_policy_names();
45 $doc->mark_disabled_lines(@site_policies);
46
47 my @empty_violation_list = ();
48 my @got_warnings = $doc->useless_no_critic_warnings(@empty_violation_list);
49 is(scalar @got_warnings, 7, 'Got correct numer of useless-no-critic warnings.');
50
51 #-----------------------------------------------------------------------------