Perl/Lint/Policy/TestingAndDebugging/RequireTestLabels.pm

filter: Statementstmt 25.0% 19 / 76 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 47 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 1 totaltotal 12.0% 25 / 207 CC 43 SCAR 73.9
CC
43
Cov
11%
evaluate
1892.0
__ANON__
2.0
BEGIN
1.0
CRAP 1627.3
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitMagicNumbers.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireCheckedClose.pm »
1 package Perl::Lint::Policy::TestingAndDebugging::RequireTestLabels;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Test without a label',
10 EXPL => 'Add a label argument to all Test::More functions',
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=43 SCAR=75.5
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 my @target_test_module = ('Test::More');
17  
18 0 ▶ if (my $this_policies_arg = $args->{require_test_labels}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"require_test_labels"}) 0 0 0
19 0 ▶ push @target_test_module, split / /, ($this_policies_arg->{modules} || '');
Condition0%0/2
$this_policies_arg->{'modules'} || ''
l!l
00
MC/DC0%0/1
$this_policies_arg->{'modules'} || ''
$this_policies_arg->{'modules'}
Truth table0%0/2
A
A= $this_policies_arg->{'modules'}
Aresult
11
00
20 }
21  
22 0 my @violations;
23 0 my $is_loaded = 0;
24 0 my $token_num = scalar @$tokens;
25 0 ▶ for (my $i = 0; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
26 0 my $token = $tokens->[$i];
27 0 my $token_type = $token->{type};
28 0 my $token_data = $token->{data};
29  
30 # for checking Test::More is loaded
31 0 ▶ if ($token_type == USE_DECL || $token_type == REQUIRE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 93 or $token_type == 71) 0 0 0
Condition0%0/3
$token_type == 93 or $token_type == 71
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 93 or $token_type == 71
$token_type == 93 $token_type == 71
Truth table0%0/3
A or B
A= $token_type == 93B= $token_type == 71
ABresult
1X1
011
000
32 0 ▶ next if $is_loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $is_loaded 0 0 0
33  
34 0 my $used_module_name = '';
35 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
36 0 my $token = $tokens->[$i];
37 0 my $token_type = $token->{type};
38 0 ▶ if ($token_type == NAMESPACE || $token_type == NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 127 or $token_type == 126) { } 0 0 0
Condition0%0/3
$token_type == 127 or $token_type == 126
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 127 or $token_type == 126
$token_type == 127 $token_type == 126
Truth table0%0/3
A or B
A= $token_type == 127B= $token_type == 126
ABresult
1X1
011
000
39 0 $used_module_name .= $token->{data};
40 }
41 else {
42 0 last;
43 }
44 }
45  
46 0 ▶ if (any {$_ eq $used_module_name} @target_test_module) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $used_module_name; } , @target_test_module)) 0 0 0
47 0 $is_loaded = 1;
48 }
49 0 next;
50 }
51  
52 0 ▶ if ($token_type == KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 122) 0 0 0
53 0 ▶ if ($token_data eq 'pass' || $token_data eq 'fail') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "pass" or $token_data eq "fail") 0 0 0
Condition0%0/3
$token_data eq "pass" or $token_data eq "fail"
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_data eq "pass" or $token_data eq "fail"
$token_data eq "pass" $token_data eq "fail"
Truth table0%0/3
A or B
A= $token_data eq "pass"B= $token_data eq "fail"
ABresult
1X1
011
000
54 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{"type"} == 106 or $$tokens[$i + 1]{"type"} == 107 and $$tokens[$i + 2]{"type"} == 108) 0 0 0
Condition0%0/6
$$tokens[$i + 1]{"type"} == 106 or $$tokens[$i + 1]{"type"} == 107 and $$tokens[$i + 2]{"type"} == 108
l!l&&r!l&&!r
000
$$tokens[$i + 1]{"type"} == 107 and $$tokens[$i + 2]{"type"} == 108
!ll&&!rl&&r
000
MC/DC0%0/3
$$tokens[$i + 1]{"type"} == 106 or $$tokens[$i + 1]{"type"} == 107 and $$tokens[$i + 2]{"type"} == 108
$$tokens[$i + 1]{"type"} == 106 $$tokens[$i + 1]{"type"} == 107 $$tokens[$i + 2]{"type"} == 108
Truth table0%0/4
A or B and C
A= $$tokens[$i + 1]{"type"} == 106B= $$tokens[$i + 1]{"type"} == 107C= $$tokens[$i + 2]{"type"} == 108
ABCresult
1XX1
0111
00X0
0100
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 0 description => DESC,
65 explanation => EXPL,
66 policy => __PACKAGE__,
67 };
68 }
69 0 next;
70 }
71  
72 0 my $expected_commma_num = 0;
73 0 ▶ if ($token_data eq 'ok') {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_data eq 'ok') { } 0 0 0
elsif ($token_data eq 'cmp_ok') { } 0 0 0
elsif ($token_data eq 'is' or $token_data eq 'isnt' or $token_data eq 'like' or $token_data eq 'unlike' or $token_data eq 'is_deeply') { } 0 0 0
74 0 $expected_commma_num = 1;
75 }
76 elsif ($token_data eq 'cmp_ok') {
77 0 $expected_commma_num = 3;
78 }
79 ▶ elsif (
Condition0%0/12
$token_data eq "is" or $token_data eq "isnt" or $token_data eq "like" or $token_data eq "unlike" or $token_data eq "is_deeply"
l!l&&r!l&&!r
000
$token_data eq "is" or $token_data eq "isnt" or $token_data eq "like" or $token_data eq "unlike"
l!l&&r!l&&!r
000
$token_data eq "is" or $token_data eq "isnt" or $token_data eq "like"
l!l&&r!l&&!r
000
$token_data eq "is" or $token_data eq "isnt"
l!l&&r!l&&!r
000
MC/DC0%0/5
$token_data eq "is" or $token_data eq "isnt" or $token_data eq "like" or $token_data eq "unlike" or $token_data eq "is_deeply"
$token_data eq "is" $token_data eq "isnt" $token_data eq "like" $token_data eq "unlike" $token_data eq "is_deeply"
Truth table0%0/6
A or B or C or D or E
A= $token_data eq "is"B= $token_data eq "isnt"C= $token_data eq "like"D= $token_data eq "unlike"E= $token_data eq "is_deeply"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
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 0 $expected_commma_num = 2;
87 }
88  
89 0 ▶ if ($expected_commma_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected_commma_num) 0 0 0
90 0 my $left_paren_num = 0;
91 0 my $left_brace_num = 0;
92 0 my $left_bracket_num = 0;
93 0 my $comma_num = 0;
94  
95 0 ▶ $i++ if $tokens->[$i+1]->{type} == LEFT_PAREN;
Branch: 1 branch
BranchTrueFalseTotal
if $$tokens[$i + 1]{"type"} == 107 0 0 0
96  
97 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
98 0 my $token = $tokens->[$i];
99 0 my $token_type = $token->{type};
100 0 my $token_data = $token->{data};
101  
102 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 8 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 111) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 112) { } 0 0 0
elsif ($token_type == 104 and $left_paren_num <= 0 and $left_brace_num <= 0 and $left_bracket_num <= 0) { } 0 0 0
elsif ($token_type == 106 and $left_paren_num <= 0 and $left_brace_num <= 0 and $left_bracket_num <= 0) { } 0 0 0
103 0 $left_paren_num++;
104 }
105 elsif ($token_type == LEFT_BRACE) {
106 0 $left_brace_num++;
107 }
108 elsif ($token_type == LEFT_BRACKET) {
109 0 $left_bracket_num++;
110 }
111 elsif ($token_type == RIGHT_PAREN) {
112 0 $left_paren_num--;
113 }
114 elsif ($token_type == RIGHT_BRACE) {
115 0 $left_brace_num--;
116 }
117 elsif ($token_type == RIGHT_BRACKET) {
118 0 $left_bracket_num--;
119 }
120 ▶ elsif (
Condition0%0/9
$token_type == 104 and $left_paren_num <= 0 and $left_brace_num <= 0 and $left_bracket_num <= 0
!ll&&!rl&&r
000
$token_type == 104 and $left_paren_num <= 0 and $left_brace_num <= 0
!ll&&!rl&&r
000
$token_type == 104 and $left_paren_num <= 0
!ll&&!rl&&r
000
MC/DC0%0/4
$token_type == 104 and $left_paren_num <= 0 and $left_brace_num <= 0 and $left_bracket_num <= 0
$token_type == 104 $left_paren_num <= 0 $left_brace_num <= 0 $left_bracket_num <= 0
Truth table0%0/5
A and B and C and D
A= $token_type == 104B= $left_paren_num <= 0C= $left_brace_num <= 0D= $left_bracket_num <= 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
121 $token_type == COMMA &&
122 $left_paren_num <= 0 &&
123 $left_brace_num <= 0 &&
124 $left_bracket_num <= 0
125 ) {
126 0 $comma_num++;
127 }
128 ▶ elsif (
Condition0%0/9
$token_type == 106 and $left_paren_num <= 0 and $left_brace_num <= 0 and $left_bracket_num <= 0
!ll&&!rl&&r
000
$token_type == 106 and $left_paren_num <= 0 and $left_brace_num <= 0
!ll&&!rl&&r
000
$token_type == 106 and $left_paren_num <= 0
!ll&&!rl&&r
000
MC/DC0%0/4
$token_type == 106 and $left_paren_num <= 0 and $left_brace_num <= 0 and $left_bracket_num <= 0
$token_type == 106 $left_paren_num <= 0 $left_brace_num <= 0 $left_bracket_num <= 0
Truth table0%0/5
A and B and C and D
A= $token_type == 106B= $left_paren_num <= 0C= $left_brace_num <= 0D= $left_bracket_num <= 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
129 $token_type == SEMI_COLON &&
130 $left_paren_num <= 0 &&
131 $left_brace_num <= 0 &&
132 $left_bracket_num <= 0
133 ) {
134 0 ▶ if ($comma_num < $expected_commma_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comma_num < $expected_commma_num) 0 0 0
135 push @violations, {
136 filename => $file,
137 line => $token->{line},
138 0 description => DESC,
139 explanation => EXPL,
140 policy => __PACKAGE__,
141 };
142 }
143 0 last;
144 }
145 }
146 }
147 }
148 }
149  
150 0 ▶ return \@violations if $is_loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $is_loaded 0 0 0
151 0 return [];
152 }
153  
154 2 1;
155  
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitMagicNumbers.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireCheckedClose.pm »