HexDifferences.pm

filter: Statementstmt 100% 41 / 41 Branchbran 81.8% 18 / 22 Conditioncond 52.3% 11 / 21 MC/DCmcdc 23.0% 3 / 13 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 77.5% 83 / 107 CC 19 SCAR 22.9
CC
19
Cov
83%
eq_or_dump_diff
15.3
dumped_eq_dump_or_diff
7.4
BEGIN
1.0
CRAP 9.9
↑ Summary HexDifferences/HexDump.pm »
1 package Test::HexDifferences; ## no critic (TidyCode)
2
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 3 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 exports => [
8 qw(eq_or_dump_diff dumped_eq_dump_or_diff),
9 ],
10 groups => {
11 default => [ qw(eq_or_dump_diff dumped_eq_dump_or_diff) ],
12 },
13 3 };
14 3 ▶use Test::Builder::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Test::HexDifferences::HexDump qw(hex_dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Text::Diff qw(diff);
Subroutine BEGIN: called CC=1 SCAR=0.0
17
18 3 our $VERSION = '1.001';
19
20 3 my $builder = Test::Builder->new;
21
22 3 my %diff_arg_of = (
23 STYLE => 'Table',
24 INDEX_LABEL => 'Ln',
25 FILENAME_A => 'Got',
26 FILENAME_B => 'Expected',
27 );
28
29 4 ▶sub eq_or_dump_diff ($$;$$) { ## no critic (SubroutinePrototypes)
Subroutine eq_or_dump_diff: called CC=13 SCAR=27.3
Pod documented
30 4 my ($got, $expected, @more) = @_;
31
32 4 ▶ my $attr_ref
Branch: 1 branch
BranchTrueFalseTotal
@more && ref $more[0] eq 'HASH' ? : 0 4 4
Condition33%1/3
@more and ref $more[0] eq "HASH"
!ll&&!rl&&r
040
MC/DC0%0/2
@more and ref $more[0] eq "HASH"
@more ref $more[0] eq "HASH"
Truth table33%1/3
A and B
A= @moreB= ref $more[0] eq "HASH"
ABresult
0X0
100
111
33 = ( @more && ref $more[0] eq 'HASH' )
34 ? shift @more
35 : ();
36 4 ▶ my $both_undefined
Condition66%2/3
defined $got || defined $expected
l!l&&r!l&&!r
310
MC/DC0%0/2
defined $got || defined $expected
defined $got defined $expected
Truth table66%2/3
A || B
A= defined $gotB= defined $expected
ABresult
1X1
011
000
37 = ! defined $got
38 && ! defined $expected;
39 4 ▶ my $any_undefined
Condition100%3/3
defined $got && defined $expected
!ll&&!rl&&r
112
MC/DC100%2/2
defined $got && defined $expected
defined $got defined $expected
Truth table100%3/3
A && B
A= defined $gotB= defined $expected
ABresult
0X0
100
111
40 = ! defined $got
41 || ! defined $expected;
42 4 ▶ if ( $both_undefined || $any_undefined ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_undefined or $any_undefined) 2 2 4
Condition66%2/3
$both_undefined or $any_undefined
l!l&&r!l&&!r
022
MC/DC50%1/2
$both_undefined or $any_undefined
$both_undefined $any_undefined
Truth table66%2/3
A or B
A= $both_undefinedB= $any_undefined
ABresult
1X1
011
000
43 2 ▶ my $result
Condition33%2/6
$both_undefined || !$any_undefined && $got eq $expected
l!l&&r!l&&!r
002
not $any_undefined and $got eq $expected
!ll&&!rl&&r
200
MC/DC0%0/3
$both_undefined || !$any_undefined && $got eq $expected
$both_undefined not $any_undefined $got eq $expected
Truth table25%1/4
A || not(B) and C
A= $both_undefinedB= not $any_undefinedC= $got eq $expected
ABCresult
1XX1
0111
00X0
0100
44 = $both_undefined
45 || ! $any_undefined && $got eq $expected;
46 2 ▶ $got = defined $got ? $got : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $got ? : 1 1 2
47 2 ▶ $expected = defined $expected ? $expected : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $expected ? : 1 1 2
48 2 ▶ my $ok = $builder->ok($result, $more[0])
Branch: 1 branch
BranchTrueFalseTotal
my $ok = $builder->ok($result, $more[0]) or $builder->diag(diff(\$got, \$expected, \%diff_arg_of)) 0 2 2
49 or $builder->diag(
50 diff(
51 \$got,
52 \$expected,
53 \%diff_arg_of,
54 ),
55 );
56 2 return $ok;
57 }
58 2 ▶ my $ok = $builder->ok($got eq $expected, $more[0])
Branch: 1 branch
BranchTrueFalseTotal
my $ok = $builder->ok($got eq $expected, $more[0]) or $builder->diag(diff(\hex_dump($got, $attr_ref), \hex_dump($expected, $attr_ref), \%diff_arg_of)) 1 1 2
59 or $builder->diag(
60 diff(
61 \hex_dump($got, $attr_ref),
62 \hex_dump($expected, $attr_ref),
63 \%diff_arg_of,
64 ),
65 );
66
67 2 return $ok;
68 }
69
70 4 ▶sub dumped_eq_dump_or_diff ($$;$$) { ## no critic (SubroutinePrototypes)
Subroutine dumped_eq_dump_or_diff: called CC=7 SCAR=20.0
Pod documented
71 4 my ($got, $expected_dump, @more) = @_;
72
73 4 ▶ my $attr_ref
Branch: 1 branch
BranchTrueFalseTotal
@more && ref $more[0] eq 'HASH' ? : 0 4 4
Condition33%1/3
@more and ref $more[0] eq "HASH"
!ll&&!rl&&r
040
MC/DC0%0/2
@more and ref $more[0] eq "HASH"
@more ref $more[0] eq "HASH"
Truth table33%1/3
A and B
A= @moreB= ref $more[0] eq "HASH"
ABresult
0X0
100
111
74 = ( @more && ref $more[0] eq 'HASH' )
75 ? shift @more
76 : ();
77 4 ▶ $got = defined $got
Branch: 1 branch
BranchTrueFalseTotal
defined $got ? : 3 1 4
78 ? hex_dump($got, $attr_ref)
79 : 'undef';
80 4 ▶ $expected_dump = defined $expected_dump
Branch: 1 branch
BranchTrueFalseTotal
defined $expected_dump ? : 3 1 4
81 ? $expected_dump
82 : 'undef';
83 4 ▶ $expected_dump = defined $expected_dump ? $expected_dump : q{};
Branch: 1 branch
BranchTrueFalseTotal
defined $expected_dump ? : 4 0 4
84 4 ▶ my $ok = $builder->ok($got eq $expected_dump, $more[0])
Branch: 1 branch
BranchTrueFalseTotal
my $ok = $builder->ok($got eq $expected_dump, $more[0]) or $builder->diag(diff(\$got, \$expected_dump, \%diff_arg_of)) 1 3 4
85 or $builder->diag(
86 diff(
87 \$got,
88 \$expected_dump,
89 \%diff_arg_of,
90 ),
91 );
92
93 4 return $ok;
94 }
95
96 # $Id$
97
98 3 1;
99
100 __END__
↑ Summary HexDifferences/HexDump.pm »