line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::TestingAndDebugging::RequireTestLabels; |
2
|
133
|
|
|
133
|
|
69617
|
use strict; |
|
133
|
|
|
|
|
156
|
|
|
133
|
|
|
|
|
3105
|
|
3
|
133
|
|
|
133
|
|
390
|
use warnings; |
|
133
|
|
|
|
|
125
|
|
|
133
|
|
|
|
|
2851
|
|
4
|
133
|
|
|
133
|
|
435
|
use List::Util qw/any/; |
|
133
|
|
|
|
|
163
|
|
|
133
|
|
|
|
|
6273
|
|
5
|
133
|
|
|
133
|
|
784
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
157
|
|
|
133
|
|
|
|
|
58948
|
|
6
|
133
|
|
|
133
|
|
512
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
133
|
|
|
133
|
|
|
|
|
550
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
133
|
|
|
|
|
64700
|
DESC => 'Test without a label', |
10
|
|
|
|
|
|
|
EXPL => 'Add a label argument to all Test::More functions', |
11
|
133
|
|
|
133
|
|
6483
|
}; |
|
133
|
|
|
|
|
140
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub evaluate { |
14
|
8
|
|
|
8
|
0
|
14
|
my ($class, $file, $tokens, $src, $args) = @_; |
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
|
|
14
|
my @target_test_module = ('Test::More'); |
17
|
|
|
|
|
|
|
|
18
|
8
|
100
|
|
|
|
19
|
if (my $this_policies_arg = $args->{require_test_labels}) { |
19
|
2
|
|
50
|
|
|
11
|
push @target_test_module, split / /, ($this_policies_arg->{modules} || ''); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
|
|
7
|
my @violations; |
23
|
8
|
|
|
|
|
8
|
my $is_loaded = 0; |
24
|
8
|
|
|
|
|
11
|
my $token_num = scalar @$tokens; |
25
|
8
|
|
|
|
|
21
|
for (my $i = 0; $i < $token_num; $i++) { |
26
|
91
|
|
|
|
|
80
|
my $token = $tokens->[$i]; |
27
|
91
|
|
|
|
|
109
|
my $token_type = $token->{type}; |
28
|
91
|
|
|
|
|
66
|
my $token_data = $token->{data}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# for checking Test::More is loaded |
31
|
91
|
100
|
66
|
|
|
225
|
if ($token_type == USE_DECL || $token_type == REQUIRE_DECL) { |
32
|
6
|
50
|
|
|
|
13
|
next if $is_loaded; |
33
|
|
|
|
|
|
|
|
34
|
6
|
|
|
|
|
6
|
my $used_module_name = ''; |
35
|
6
|
|
|
|
|
13
|
for ($i++; $i < $token_num; $i++) { |
36
|
24
|
|
|
|
|
21
|
my $token = $tokens->[$i]; |
37
|
24
|
|
|
|
|
18
|
my $token_type = $token->{type}; |
38
|
24
|
100
|
100
|
|
|
55
|
if ($token_type == NAMESPACE || $token_type == NAMESPACE_RESOLVER) { |
39
|
18
|
|
|
|
|
30
|
$used_module_name .= $token->{data}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
6
|
|
|
|
|
10
|
last; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
6
|
100
|
|
10
|
|
53
|
if (any {$_ eq $used_module_name} @target_test_module) { |
|
10
|
|
|
|
|
18
|
|
47
|
5
|
|
|
|
|
7
|
$is_loaded = 1; |
48
|
|
|
|
|
|
|
} |
49
|
6
|
|
|
|
|
27
|
next; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
85
|
100
|
|
|
|
123
|
if ($token_type == KEY) { |
53
|
48
|
100
|
100
|
|
|
125
|
if ($token_data eq 'pass' || $token_data eq 'fail') { |
54
|
8
|
100
|
66
|
|
|
33
|
if ( |
|
|
|
66
|
|
|
|
|
55
|
|
|
|
|
|
|
$tokens->[$i+1]->{type} == SEMI_COLON || |
56
|
|
|
|
|
|
|
( |
57
|
|
|
|
|
|
|
$tokens->[$i+1]->{type} == LEFT_PAREN && |
58
|
|
|
|
|
|
|
$tokens->[$i+2]->{type} == RIGHT_PAREN |
59
|
|
|
|
|
|
|
) |
60
|
|
|
|
|
|
|
) { |
61
|
|
|
|
|
|
|
push @violations, { |
62
|
|
|
|
|
|
|
filename => $file, |
63
|
|
|
|
|
|
|
line => $token->{line}, |
64
|
6
|
|
|
|
|
12
|
description => DESC, |
65
|
|
|
|
|
|
|
explanation => EXPL, |
66
|
|
|
|
|
|
|
policy => __PACKAGE__, |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
} |
69
|
8
|
|
|
|
|
41
|
next; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
40
|
|
|
|
|
28
|
my $expected_commma_num = 0; |
73
|
40
|
100
|
100
|
|
|
165
|
if ($token_data eq 'ok') { |
|
|
100
|
100
|
|
|
|
|
|
|
50
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
74
|
11
|
|
|
|
|
9
|
$expected_commma_num = 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif ($token_data eq 'cmp_ok') { |
77
|
3
|
|
|
|
|
5
|
$expected_commma_num = 3; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif ( |
80
|
|
|
|
|
|
|
$token_data eq 'is' || |
81
|
|
|
|
|
|
|
$token_data eq 'isnt' || |
82
|
|
|
|
|
|
|
$token_data eq 'like' || |
83
|
|
|
|
|
|
|
$token_data eq 'unlike' || |
84
|
|
|
|
|
|
|
$token_data eq 'is_deeply' |
85
|
|
|
|
|
|
|
) { |
86
|
26
|
|
|
|
|
20
|
$expected_commma_num = 2; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
40
|
50
|
|
|
|
44
|
if ($expected_commma_num) { |
90
|
40
|
|
|
|
|
29
|
my $left_paren_num = 0; |
91
|
40
|
|
|
|
|
23
|
my $left_brace_num = 0; |
92
|
40
|
|
|
|
|
30
|
my $left_bracket_num = 0; |
93
|
40
|
|
|
|
|
22
|
my $comma_num = 0; |
94
|
|
|
|
|
|
|
|
95
|
40
|
100
|
|
|
|
64
|
$i++ if $tokens->[$i+1]->{type} == LEFT_PAREN; |
96
|
|
|
|
|
|
|
|
97
|
40
|
|
|
|
|
55
|
for ($i++; $i < $token_num; $i++) { |
98
|
257
|
|
|
|
|
172
|
my $token = $tokens->[$i]; |
99
|
257
|
|
|
|
|
165
|
my $token_type = $token->{type}; |
100
|
257
|
|
|
|
|
176
|
my $token_data = $token->{data}; |
101
|
|
|
|
|
|
|
|
102
|
257
|
100
|
66
|
|
|
1235
|
if ($token_type == LEFT_PAREN) { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
103
|
1
|
|
|
|
|
2
|
$left_paren_num++; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
106
|
10
|
|
|
|
|
13
|
$left_brace_num++; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACKET) { |
109
|
6
|
|
|
|
|
10
|
$left_bracket_num++; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
112
|
40
|
|
|
|
|
47
|
$left_paren_num--; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
115
|
10
|
|
|
|
|
15
|
$left_brace_num--; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACKET) { |
118
|
6
|
|
|
|
|
9
|
$left_bracket_num--; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
elsif ( |
121
|
|
|
|
|
|
|
$token_type == COMMA && |
122
|
|
|
|
|
|
|
$left_paren_num <= 0 && |
123
|
|
|
|
|
|
|
$left_brace_num <= 0 && |
124
|
|
|
|
|
|
|
$left_bracket_num <= 0 |
125
|
|
|
|
|
|
|
) { |
126
|
44
|
|
|
|
|
57
|
$comma_num++; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
elsif ( |
129
|
|
|
|
|
|
|
$token_type == SEMI_COLON && |
130
|
|
|
|
|
|
|
$left_paren_num <= 0 && |
131
|
|
|
|
|
|
|
$left_brace_num <= 0 && |
132
|
|
|
|
|
|
|
$left_bracket_num <= 0 |
133
|
|
|
|
|
|
|
) { |
134
|
40
|
100
|
|
|
|
55
|
if ($comma_num < $expected_commma_num) { |
135
|
|
|
|
|
|
|
push @violations, { |
136
|
|
|
|
|
|
|
filename => $file, |
137
|
|
|
|
|
|
|
line => $token->{line}, |
138
|
28
|
|
|
|
|
73
|
description => DESC, |
139
|
|
|
|
|
|
|
explanation => EXPL, |
140
|
|
|
|
|
|
|
policy => __PACKAGE__, |
141
|
|
|
|
|
|
|
}; |
142
|
|
|
|
|
|
|
} |
143
|
40
|
|
|
|
|
75
|
last; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
8
|
100
|
|
|
|
30
|
return \@violations if $is_loaded; |
151
|
3
|
|
|
|
|
17
|
return []; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
155
|
|
|
|
|
|
|
|