Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / 15_statistics.t
1 #!perl
2
3 ##############################################################################
4 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/15_statistics.t $
5 #     $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $
6 #   $Author: clonezone $
7 # $Revision: 2416 $
8 ##############################################################################
9
10 use 5.006001;
11 use strict;
12 use warnings;
13
14 use Test::More (tests => 25);
15 use English qw(-no_match_vars);
16 use Perl::Critic::PolicyFactory (-test => 1);
17 use Perl::Critic::TestUtils;
18
19 Perl::Critic::TestUtils::block_perlcriticrc();
20
21 #-----------------------------------------------------------------------------
22
23 my $pkg = 'Perl::Critic::Statistics';
24 use_ok( $pkg );
25
26 my @methods = qw(
27     average_sub_mccabe
28     lines
29     modules
30     new
31     statements
32     subs
33     total_violations
34     violations_by_policy
35     violations_by_severity
36     statements_other_than_subs
37     violations_per_file
38     violations_per_statement
39     violations_per_line_of_code
40 );
41
42 for my $method ( @methods ) {
43     can_ok( $pkg, $method );
44 }
45
46 #-----------------------------------------------------------------------------
47
48 my $code = <<'END_PERL';
49 package Foo;
50
51 use My::Module;
52 $this = $that if $condition;
53 sub foo { return @list unless $condition };
54 END_PERL
55
56 #-----------------------------------------------------------------------------
57
58 # User may not have Perl::Tidy installed...
59 my $profile = { '-CodeLayout::RequireTidyCode' => {} };
60 my $critic =
61     Perl::Critic->new(
62         -severity => 1,
63         -profile => $profile,
64         -theme => 'core',
65     );
66 my @violations = $critic->critique( \$code );
67
68 #print @violations;
69 #exit;
70
71 my %expected_stats = (
72     average_sub_mccabe            => 2,
73     lines                         => 5,
74     modules                       => 1,
75     statements                    => 6,
76     statements_other_than_subs    => 5,
77     subs                          => 1,
78     total_violations              => 10,
79     violations_per_file           => 10,
80     violations_per_line_of_code   => 2,
81     violations_per_statement      => 2,
82 );
83
84 my $stats = $critic->statistics();
85 isa_ok($stats, $pkg);
86
87 while ( my($method, $expected) = each %expected_stats) {
88     is( $stats->$method, $expected, "Statistics: $method");
89 }
90
91 #-----------------------------------------------------------------------------
92
93 # ensure we run true if this test is loaded by
94 # t/15_statistics.t_without_optional_dependencies.t
95 1;
96
97 ###############################################################################
98 # Local Variables:
99 #   mode: cperl
100 #   cperl-indent-level: 4
101 #   fill-column: 78
102 #   indent-tabs-mode: nil
103 #   c-indentation-style: bsd
104 # End:
105 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :