blib/lib/Test/Stream/Compare/Set.pm

filter: Statementstmt 98.5% 66 / 67 Branchbran 95.0% 19 / 20 Conditioncond 92.3% 12 / 13 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 15 / 15 Podpod 50.0% 4 / 8 totaltotal 93.8% 122 / 130 CC 17 SCAR 18.5
CC
17
Cov
97%
deltas
13.0
init
3.0
set_reduction
2.0
CRAP 6.4
« blib/lib/Test/Stream/Formatter/TAP.pm ↑ Summary blib/lib/Test/Stream/Mock.pm »
1 package Test::Stream::Compare::Set;
2 100 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 100 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 100 ▶use base 'Test::Stream::Compare';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 100 ▶use Test::Stream::HashBase accessors => [qw/checks _reduction/];
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 100 ▶use Test::Stream::Delta();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 100 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 100 ▶use Scalar::Util qw/reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 29 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
14 29 my $self = shift;
15  
16 29 ▶ my $reduction = delete $self->{reduction} || 'any';
Condition100%2/2
delete $self->{'reduction'} || 'any'
l!l
425
MC/DC100%1/1
delete $self->{'reduction'} || 'any'
delete $self->{'reduction'}
Truth table100%2/2
A
A= delete $self->{'reduction'}
Aresult
11
00
17  
18 29 ▶ $self->{+CHECKS} ||= [];
Condition100%2/2
$self->{"checks"} ||= []
l!l
1613
MC/DC100%1/1
$self->{"checks"} ||= []
$self->{"checks"}
Truth table100%2/2
A
A= $self->{"checks"}
Aresult
11
00
19  
20 29 $self->set_reduction($reduction);
21  
22 28 $self->SUPER::init();
23 }
24  
25 5 ▶sub name { '<CHECK-SET>' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
26 5 ▶sub operator { $_[0]->{+_REDUCTION} }
Subroutine operator: called CC=1 SCAR=0.0
Pod documented
27 4 ▶sub reduction { $_[0]->{+_REDUCTION} }
Subroutine reduction: called CC=1 SCAR=0.0
Pod undocumented
28  
29 100 my %VALID = (any => 1, all => 1, none => 1);
30 51 ▶sub set_reduction {
Subroutine set_reduction: called CC=2 SCAR=6.9
Pod undocumented
31 51 my $self = shift;
32 51 my ($redu) = @_;
33  
34 croak "'$redu' is not a valid set reduction"
35 51 ▶ unless $VALID{$redu};
Branch: 1 branch
BranchTrueFalseTotal
unless $VALID{$redu} 2 49 51
36  
37 49 $self->{+_REDUCTION} = $redu;
38 }
39  
40 26 ▶sub verify {
Subroutine verify: called CC=2 SCAR=6.9
Pod documented
41 26 my $self = shift;
42 26 my %params = @_;
43 26 ▶ return $params{exists} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$params{'exists'} ? : 25 1 26
44 }
45  
46 23 ▶sub add_check {
Subroutine add_check: called CC=1 SCAR=0.0
Pod undocumented
47 23 my $self = shift;
48 23 push @{$self->{+CHECKS}} => @_;
49 }
50  
51 39 ▶sub deltas {
Subroutine deltas: called CC=13 SCAR=25.7
Pod documented
52 39 my $self = shift;
53 39 my %params = @_;
54  
55 39 my $checks = $self->{+CHECKS};
56 39 my $reduction = $self->{+_REDUCTION};
57 39 my $convert = $params{convert};
58  
59 39 ▶ unless ($checks && @$checks) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($checks and @$checks) 8 31 39
Condition100%3/3
$checks and @$checks
!ll&&!rl&&r
4431
MC/DC100%2/2
$checks and @$checks
$checks @$checks
Truth table100%3/3
A and B
A= $checksB= @$checks
ABresult
0X0
100
111
60 8 my $file = $self->file;
61 8 my $lines = $self->lines;
62  
63 8 my $extra = "";
64 8 ▶ if ($file and $lines and @$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and $lines and @$lines) 4 4 8
Condition83%5/6
$file and $lines and @$lines
!ll&&!rl&&r
224
$file and $lines
!ll&&!rl&&r
206
MC/DC66%2/3
$file and $lines and @$lines
$file $lines @$lines
Truth table75%3/4
A and B and C
A= $fileB= $linesC= @$lines
ABCresult
0XX0
10X0
1100
1111
65 4 ▶ my $lns = (@$lines > 1 ? 'lines ' : 'line ' ) . join ', ', @$lines;
Branch: 1 branch
BranchTrueFalseTotal
@$lines > 1 ? : 2 2 4
66 4 $extra = " (Set defined in $file $lns)";
67 }
68  
69 8 die "No checks defined for set$extra\n";
70 }
71  
72 31 my @deltas;
73 31 my $i = 0;
74 31 for my $check (@$checks) {
75 69 my $c = $convert->($check);
76 69 my $id = [META => "Check " . $i++];
77 69 my @d = $c->run(%params, id => $id);
78  
79 69 ▶ if ($reduction eq 'any') {
Branch: 3 branches
BranchTrueFalseTotal
if ($reduction eq 'any') { } 37 32 69
elsif ($reduction eq 'all') { } 22 10 32
elsif ($reduction eq 'none') { } 10 0 10
80 37 ▶ return () unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 16 21 37
81 21 push @deltas => @d;
82 }
83 elsif ($reduction eq 'all') {
84 22 push @deltas => @d;
85 }
86 elsif ($reduction eq 'none') {
87 push @deltas => Test::Stream::Delta->new(
88 verified => 0,
89 id => $id,
90 got => $params{got},
91 10 ▶ check => $c,
Branch: 1 branch
BranchTrueFalseTotal
unless @d 2 8 10
92 ) unless @d;
93 }
94 else {
95 0 die "Invalid reduction: $reduction\n";
96 }
97 }
98  
99 15 return @deltas;
100 }
101  
102 100 1;
103  
104 __END__
« blib/lib/Test/Stream/Formatter/TAP.pm ↑ Summary blib/lib/Test/Stream/Mock.pm »