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) $
8 ##############################################################################
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;
19 Perl::Critic::TestUtils::block_perlcriticrc();
21 #-----------------------------------------------------------------------------
23 my $pkg = 'Perl::Critic::Statistics';
35 violations_by_severity
36 statements_other_than_subs
38 violations_per_statement
39 violations_per_line_of_code
42 for my $method ( @methods ) {
43 can_ok( $pkg, $method );
46 #-----------------------------------------------------------------------------
48 my $code = <<'END_PERL';
52 $this = $that if $condition;
53 sub foo { return @list unless $condition };
56 #-----------------------------------------------------------------------------
58 # User may not have Perl::Tidy installed...
59 my $profile = { '-CodeLayout::RequireTidyCode' => {} };
66 my @violations = $critic->critique( \$code );
71 my %expected_stats = (
72 average_sub_mccabe => 2,
76 statements_other_than_subs => 5,
78 total_violations => 10,
79 violations_per_file => 10,
80 violations_per_line_of_code => 2,
81 violations_per_statement => 2,
84 my $stats = $critic->statistics();
87 while ( my($method, $expected) = each %expected_stats) {
88 is( $stats->$method, $expected, "Statistics: $method");
91 #-----------------------------------------------------------------------------
93 # ensure we run true if this test is loaded by
94 # t/15_statistics.t_without_optional_dependencies.t
97 ###############################################################################
100 # cperl-indent-level: 4
102 # indent-tabs-mode: nil
103 # c-indentation-style: bsd
105 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :