blib/lib/Test2/Compare/Base.pm

filter: Statementstmt 98.8% 85 / 86 Branchbran 87.5% 35 / 40 Conditioncond 80.0% 20 / 25 MC/DCmcdc 50.0% 8 / 16 Subroutinesub 100% 24 / 24 Podpod 66.6% 10 / 15 totaltotal 88.3% 182 / 206 CC 30 SCAR 19.3
CC
30
Cov
93%
run
16.2
lines
6.0
file
5.2
CRAP 6.9
« blib/lib/Test2/Plugin/SRand.pm ↑ Summary blib/lib/Test2/Compare/Hash.pm »
1 package Test2::Compare::Base;
2 176 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 176 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 176 our $VERSION = '1.302226';
6  
7 176 ▶use Carp qw/confess croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 176 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 176 ▶use Test2::Util::Sub qw/sub_info/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 176 ▶use Test2::Compare::Delta();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub MAX_CYCLES() { 75 }
14  
15 176 ▶use Test2::Util::HashBase qw{builder _file _lines _info called};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 176 ▶use Test2::Util::Ref qw/render_ref/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 {
19 176 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 176 *set_lines = \&set__lines;
21 176 *set_file = \&set__file;
22 }
23  
24 250 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
25 250 my $self = shift;
26 250 my $class = blessed($self);
27  
28 # Shallow copy is good enough for all the current compare types.
29 250 return bless({%$self}, $class);
30 }
31  
32 19480 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
33 19480 my $self = shift;
34 19480 ▶ $self->{+_LINES} = delete $self->{lines} if exists $self->{lines};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"lines"} 6794 12686 19480
35 19480 ▶ $self->{+_FILE} = delete $self->{file} if exists $self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"file"} 6794 12686 19480
36 }
37  
38 96 ▶sub file {
Subroutine file: called CC=5 SCAR=16.4
Pod undocumented
39 96 my $self = shift;
40 96 ▶ return $self->{+_FILE} if $self->{+_FILE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_file"} 13 83 96
41  
42 83 ▶ if ($self->{+BUILDER}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'builder'}) { } 56 27 83
elsif ($self->{'called'}) { } 0 27 27
43 56 ▶ $self->{+_INFO} ||= sub_info($self->{+BUILDER});
Condition66%2/3
$self->{"_info"} ||= sub_info($self->{"builder"})
l!l&&r!l&&!r
46100
MC/DC0%0/2
$self->{"_info"} ||= sub_info($self->{"builder"})
$self->{"_info"} sub_info($self->{"builder"})
Truth table66%2/3
A ||= B
A= $self->{"_info"}B= sub_info($self->{"builder"})
ABresult
1X1
011
000
44 56 return $self->{+_INFO}->{file};
45 }
46 elsif ($self->{+CALLED}) {
47 0 return $self->{+CALLED}->[1];
48 }
49  
50 27 return undef;
51 }
52  
53 445 ▶sub lines {
Subroutine lines: called CC=6 SCAR=18.0
Pod undocumented
54 445 my $self = shift;
55 445 ▶ return $self->{+_LINES} if $self->{+_LINES};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_lines"} 257 188 445
56  
57 188 ▶ if ($self->{+BUILDER}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"builder"}) 118 70 188
58 118 ▶ $self->{+_INFO} ||= sub_info($self->{+BUILDER});
Condition66%2/3
$self->{"_info"} ||= sub_info($self->{"builder"})
l!l&&r!l&&!r
74440
MC/DC0%0/2
$self->{"_info"} ||= sub_info($self->{"builder"})
$self->{"_info"} sub_info($self->{"builder"})
Truth table66%2/3
A ||= B
A= $self->{"_info"}B= sub_info($self->{"builder"})
ABresult
1X1
011
000
59 118 ▶ return $self->{+_INFO}->{lines} if @{$self->{+_INFO}->{lines}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"_info"}{"lines"};} 118 0 118
60 }
61 70 ▶ if ($self->{+CALLED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"called"}) 1 69 70
62 1 return [$self->{+CALLED}->[2]];
63 }
64 69 return [];
65 }
66  
67 2480 ▶sub delta_class { 'Test2::Compare::Delta' }
Subroutine delta_class: called CC=1 SCAR=0.0
Pod documented
68  
69 8177 ▶sub deltas { () }
Subroutine deltas: called CC=1 SCAR=0.0
Pod documented
70 296 ▶sub got_lines { () }
Subroutine got_lines: called CC=1 SCAR=0.0
Pod documented
71  
72 544 ▶sub verify_build { }
Subroutine verify_build: called CC=1 SCAR=0.0
Pod documented
73  
74 12 ▶sub throw_build_error {
Subroutine throw_build_error: called CC=4 SCAR=13.9
Pod documented
75 12 my $self = shift;
76 12 my ($msg) = @_;
77  
78 12 ▶ my $file = $self->file || 'unknown file';
Condition100%2/2
$self->file || 'unknown file'
l!l
111
MC/DC100%1/1
$self->file || 'unknown file'
$self->file
Truth table100%2/2
A
A= $self->file
Aresult
11
00
79 12 my $lines = $self->lines;
80 12 ▶ my $line = $lines && @$lines ? $lines->[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lines && @$lines ? : 11 1 12
Condition66%2/3
$lines and @$lines
!ll&&!rl&&r
0111
MC/DC50%1/2
$lines and @$lines
$lines @$lines
Truth table66%2/3
A and B
A= $linesB= @$lines
ABresult
0X0
100
111
81  
82 12 die "$msg at $file line $line.\n";
83 }
84  
85 441 ▶sub stringify_got { 0 }
Subroutine stringify_got: called CC=1 SCAR=0.0
Pod undocumented
86  
87 68 ▶sub operator { '' }
Subroutine operator: called CC=1 SCAR=0.0
Pod documented
88 1 ▶sub verify { confess "unimplemented" }
Subroutine verify: called CC=1 SCAR=0.0
Pod documented
89 1 ▶sub name { confess "unimplemented" }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
90  
91 320 ▶sub render {
Subroutine render: called CC=1 SCAR=0.0
Pod documented
92 320 my $self = shift;
93 320 return $self->name;
94 }
95  
96 14824 ▶sub run {
Subroutine run: called CC=16 SCAR=27.9
Pod documented
97 14824 my $self = shift;
98 14824 my %params = @_;
99  
100 14824 my $id = $params{id};
101 14824 ▶ my $convert = $params{convert} or confess "no convert sub provided";
Branch: 1 branch
BranchTrueFalseTotal
my $convert = $params{"convert"} or confess("no convert sub provided") 14824 0 14824
102 14824 ▶ my $seen = $params{seen} ||= {};
Condition50%1/2
$params{"seen"} ||= {}
l!l
148240
MC/DC0%0/1
$params{"seen"} ||= {}
$params{"seen"}
Truth table50%1/2
A
A= $params{"seen"}
Aresult
11
00
103  
104 $params{exists} = exists $params{got} ? 1 : 0
105 14824 ▶ unless exists $params{exists};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $params{"exists"} 1998 12826 14824
exists $params{'got'} ? : 1998 0 1998
106  
107 14824 my $exists = $params{exists};
108 14824 ▶ my $got = $exists ? $params{got} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 14770 54 14824
109  
110 14824 my $gotname = render_ref($got);
111  
112 # Prevent infinite cycles
113 14824 ▶ if (defined($got) && ref $got) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $got and ref $got) 4437 10387 14824
Condition100%3/3
defined $got and ref $got
!ll&&!rl&&r
307100804437
MC/DC100%2/2
defined $got and ref $got
defined $got ref $got
Truth table100%3/3
A and B
A= defined $gotB= ref $got
ABresult
0X0
100
111
114 die "Cycle detected in comparison, aborting"
115 4437 ▶ if $seen->{$gotname} && $seen->{$gotname} >= MAX_CYCLES;
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$gotname} and $seen->{$gotname} >= 75 0 4437 4437
Condition66%2/3
$seen->{$gotname} and $seen->{$gotname} >= 75
!ll&&!rl&&r
443160
MC/DC0%0/2
$seen->{$gotname} and $seen->{$gotname} >= 75
$seen->{$gotname} $seen->{$gotname} >= 75
Truth table66%2/3
A and B
A= $seen->{$gotname}B= $seen->{$gotname} >= 75
ABresult
0X0
100
111
116 4437 $seen->{$gotname}++;
117 }
118  
119 14824 my $ok = $self->verify(%params);
120 14824 ▶ my @deltas = $ok ? $self->deltas(%params) : ();
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 12475 2349 14824
121  
122 14824 ▶ $seen->{$gotname}-- if defined $got && ref $got;
Branch: 1 branch
BranchTrueFalseTotal
if defined $got and ref $got 4437 10387 14824
Condition100%3/3
defined $got and ref $got
!ll&&!rl&&r
307100804437
MC/DC100%2/2
defined $got and ref $got
defined $got ref $got
Truth table100%3/3
A and B
A= defined $gotB= ref $got
ABresult
0X0
100
111
123  
124 14824 ▶ return if $ok && !@deltas;
Branch: 1 branch
BranchTrueFalseTotal
if $ok and not @deltas 12389 2435 14824
Condition100%3/3
$ok and not @deltas
!ll&&!rl&&r
23498612389
MC/DC100%2/2
$ok and not @deltas
$ok not @deltas
Truth table100%3/3
A and not(B)
A= $okB= not @deltas
ABresult
0X0
100
111
125  
126 2435 ▶ return $self->delta_class->new(
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 2411 24 2435
127 verified => $ok,
128 id => $id,
129 got => $got,
130 check => $self,
131 children => \@deltas,
132 $exists ? () : (dne => 'got'),
133 );
134 }
135  
136 176 1;
137  
138 __END__
« blib/lib/Test2/Plugin/SRand.pm ↑ Summary blib/lib/Test2/Compare/Hash.pm »