line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
|
|
|
|
|
|
####################################################################### |
3
|
|
|
|
|
|
|
# $URL: http://perlcritic.tigris.org/svn/perlcritic/tags/Test-Perl-Critic-0.08/lib/Test/Perl/Critic.pm $ |
4
|
|
|
|
|
|
|
# $Date: 2006-11-05 18:46:37 -0800 (Sun, 05 Nov 2006) $ |
5
|
|
|
|
|
|
|
# $Author: thaljef $ |
6
|
|
|
|
|
|
|
# $Revision: 816 $ |
7
|
|
|
|
|
|
|
######################################################################## |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Test::Perl::Critic; |
10
|
1
|
|
|
1
|
|
520
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
11
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
12
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
13
|
1
|
|
|
1
|
|
805
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2584
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
1479
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
36
|
|
15
|
1
|
|
|
1
|
|
5605
|
use Test::Builder qw(); |
|
1
|
|
|
|
|
360257
|
|
|
1
|
|
|
|
|
25
|
|
16
|
1
|
|
|
1
|
|
12
|
use Perl::Critic qw(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
17
|
1
|
|
|
1
|
|
5
|
use Perl::Critic::Violation qw(); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
18
|
|
|
|
|
|
|
use Perl::Critic::Utils; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = 0.08; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $TEST = Test::Builder->new(); |
25
|
|
|
|
|
|
|
my %CRITIC_ARGS = (); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub import { |
30
|
0
|
|
|
0
|
|
0
|
|
31
|
0
|
|
|
|
|
0
|
my ( $self, %args ) = @_; |
32
|
|
|
|
|
|
|
my $caller = caller; |
33
|
1
|
|
|
1
|
|
935
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
495
|
|
34
|
0
|
|
|
|
|
0
|
no strict 'refs'; ## no critic |
|
0
|
|
|
|
|
0
|
|
35
|
0
|
|
|
|
|
0
|
*{ $caller . '::critic_ok' } = \&critic_ok; |
|
0
|
|
|
|
|
0
|
|
36
|
|
|
|
|
|
|
*{ $caller . '::all_critic_ok' } = \&all_critic_ok; |
37
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
$TEST->exported_to($caller); |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
# -format is supported for backward compatibility |
|
0
|
|
|
|
|
0
|
|
41
|
0
|
|
|
|
|
0
|
if( exists $args{-format} ){ $args{-verbose} = $args{-format}; } |
42
|
|
|
|
|
|
|
%CRITIC_ARGS = %args; |
43
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub critic_ok { |
50
|
1
|
|
|
1
|
1
|
4
|
|
51
|
1
|
50
|
|
|
|
6
|
my ( $file, $test_name ) = @_; |
52
|
1
|
50
|
|
|
|
31
|
croak q{no file specified} if not defined $file; |
53
|
1
|
|
33
|
|
|
14
|
croak qq{"$file" does not exist} if not -f $file; |
54
|
|
|
|
|
|
|
$test_name ||= qq{Test::Perl::Critic for "$file"}; |
55
|
1
|
|
|
|
|
2
|
|
56
|
1
|
|
|
|
|
3
|
my $critic = undef; |
57
|
1
|
|
|
|
|
3
|
my @violations = (); |
58
|
|
|
|
|
|
|
my $ok = 0; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
2
|
# Run Perl::Critic |
61
|
|
|
|
|
|
|
eval { |
62
|
1
|
|
|
|
|
13
|
# TODO: Should $critic be a global singleton? |
63
|
1
|
|
|
|
|
468687
|
$critic = Perl::Critic->new( %CRITIC_ARGS ); |
64
|
1
|
|
|
|
|
424819
|
@violations = $critic->critique( $file ); |
65
|
|
|
|
|
|
|
$ok = not scalar @violations; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
259
|
# Evaluate results |
69
|
|
|
|
|
|
|
$TEST->ok( $ok, $test_name ); |
70
|
|
|
|
|
|
|
|
71
|
1
|
50
|
|
|
|
7
|
|
|
|
50
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
if ($EVAL_ERROR) { # Trap exceptions from P::C |
73
|
0
|
|
|
|
|
0
|
$TEST->diag( "\n" ); # Just to get on a new line. |
74
|
0
|
|
|
|
|
0
|
$TEST->diag( qq{Perl::Critic had errors in "$file":} ); |
75
|
|
|
|
|
|
|
$TEST->diag( qq{\t$EVAL_ERROR} ); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
0
|
elsif ( not $ok ) { # Report Policy violations |
78
|
0
|
|
|
|
|
0
|
$TEST->diag( "\n" ); # Just to get on a new line. |
79
|
|
|
|
|
|
|
$TEST->diag( qq{Perl::Critic found these violations in "$file":} ); |
80
|
0
|
|
|
|
|
0
|
|
81
|
0
|
|
|
|
|
0
|
my $verbose = $critic->config->verbose(); |
82
|
0
|
|
|
|
|
0
|
Perl::Critic::Violation::set_format( $verbose ); |
|
0
|
|
|
|
|
0
|
|
83
|
|
|
|
|
|
|
for my $viol (@violations) { $TEST->diag("$viol") } |
84
|
|
|
|
|
|
|
} |
85
|
1
|
|
|
|
|
439
|
|
86
|
|
|
|
|
|
|
return $ok; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub all_critic_ok { |
92
|
1
|
50
|
|
1
|
1
|
12
|
|
93
|
1
|
|
|
|
|
5
|
my @dirs = @_ ? @_ : _starting_points(); |
94
|
1
|
|
|
|
|
3930
|
my @files = all_code_files( @dirs ); |
95
|
|
|
|
|
|
|
$TEST->plan( tests => scalar @files ); |
96
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
97
|
1
|
|
|
|
|
119
|
my $okays = grep { critic_ok($_) } @files; |
98
|
|
|
|
|
|
|
return $okays == @files; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
102
|
|
|
|
|
|
|
|
103
|
1
|
50
|
|
1
|
1
|
3
|
sub all_code_files { |
104
|
1
|
|
|
|
|
5
|
my @dirs = @_ ? @_ : _starting_points(); |
105
|
|
|
|
|
|
|
return Perl::Critic::Utils::all_perl_files(@dirs); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
109
|
|
|
|
|
|
|
|
110
|
1
|
50
|
|
1
|
|
34
|
sub _starting_points { |
111
|
|
|
|
|
|
|
return -e 'blib' ? 'blib' : 'lib'; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#line 372 |