Login
Adjust expected stats, now that RequireVcsKeywords is gone.
[gknop/Perl-Critic.git] / t / 15_statistics.t
CommitLineData
d85cbb28
JRT
1#!perl
2
3##############################################################################
4# $URL$
31d0e808
JRT
5# $Date$
6# $Author$
7# $Revision$
d85cbb28
JRT
8##############################################################################
9
df6dee2b 10use 5.006001;
d85cbb28
JRT
11use strict;
12use warnings;
13
d85cbb28 14use English qw(-no_match_vars);
b185fa17 15
d85cbb28 16use Perl::Critic::PolicyFactory (-test => 1);
f3b652c3 17use Perl::Critic::Statistics;
d85cbb28
JRT
18use Perl::Critic::TestUtils;
19
f3b652c3 20use Test::More tests => 24;
b185fa17
ES
21
22#-----------------------------------------------------------------------------
23
8bb7c398 24our $VERSION = '1.118';
b185fa17
ES
25
26#-----------------------------------------------------------------------------
27
d85cbb28
JRT
28Perl::Critic::TestUtils::block_perlcriticrc();
29
30#-----------------------------------------------------------------------------
31
f3b652c3 32my $package = 'Perl::Critic::Statistics';
d85cbb28
JRT
33
34my @methods = qw(
35 average_sub_mccabe
b313a4e9 36 lines
d85cbb28
JRT
37 modules
38 new
d85cbb28
JRT
39 statements
40 subs
41 total_violations
ee9c1726
JRT
42 violations_by_policy
43 violations_by_severity
da1c78d8
ES
44 statements_other_than_subs
45 violations_per_file
46 violations_per_statement
d85cbb28
JRT
47 violations_per_line_of_code
48);
49
50for my $method ( @methods ) {
f3b652c3 51 can_ok( $package, $method );
d85cbb28
JRT
52}
53
54#-----------------------------------------------------------------------------
55
56my $code = <<'END_PERL';
57package Foo;
58
59use My::Module;
60$this = $that if $condition;
68a5f64a 61sub foo { return @list unless $condition };
d85cbb28
JRT
62END_PERL
63
64#-----------------------------------------------------------------------------
65
776c9cd4 66# Just don't get involved with Perl::Tidy.
7cf01c5e 67my $profile = { '-CodeLayout::RequireTidyCode' => {} };
da1c78d8
ES
68my $critic =
69 Perl::Critic->new(
70 -severity => 1,
71 -profile => $profile,
72 -theme => 'core',
73 );
2ce0b9ee
JRT
74my @violations = $critic->critique( \$code );
75
76#print @violations;
77#exit;
d85cbb28
JRT
78
79my %expected_stats = (
80 average_sub_mccabe => 2,
b313a4e9 81 lines => 5,
d85cbb28
JRT
82 modules => 1,
83 statements => 6,
da1c78d8 84 statements_other_than_subs => 5,
d85cbb28 85 subs => 1,
55a84089
JRT
86 total_violations => 7,
87 violations_per_file => 7,
88 violations_per_line_of_code => 1.4, # 7 violations / 5 lines
89 violations_per_statement => 1.4, # 7 violations / 5 lines
d85cbb28
JRT
90);
91
2ce0b9ee 92my $stats = $critic->statistics();
f3b652c3 93isa_ok($stats, $package);
2ce0b9ee 94
d85cbb28
JRT
95while ( my($method, $expected) = each %expected_stats) {
96 is( $stats->$method, $expected, "Statistics: $method");
97}
98
99#-----------------------------------------------------------------------------
100
9e7d390d 101# ensure we return true if this test is loaded by
34cc6052
ES
102# t/15_statistics.t_without_optional_dependencies.t
1031;
104
105###############################################################################
106# Local Variables:
107# mode: cperl
108# cperl-indent-level: 4
109# fill-column: 78
110# indent-tabs-mode: nil
111# c-indentation-style: bsd
112# End:
96fed375 113# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :