lib/ChordPro/Testing.pm

filter: Statementstmt 85.9% 116 / 135 Branchbran 70.4% 31 / 44 Conditioncond 46.8% 15 / 32 MC/DCmcdc 38.8% 7 / 18 Subroutinesub 95.4% 21 / 22 Podpod 0.0% 0 / 6 totaltotal 73.9% 190 / 257 CC 46 SCAR 28.9
CC
46
Cov
77%
cmp
72.0
fixchords
17.0
differ
15.8
CRAP 18.0
« lib/ChordPro/Paths.pm ↑ Summary lib/ChordPro/Delegate/SVG.pm »
1 #! perl
2  
3 91 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 91 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 91 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 91 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 91 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 91 ▶use lib "$FindBin::Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
10 91 ▶use lib "$FindBin::Bin/../lib/ChordPro/lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 91 binmode STDOUT => ':utf8';
13 91 binmode STDERR => ':utf8';
14  
15 package ChordPro::Testing;
16  
17 91 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 91 our @EXPORT = qw( $config );
19  
20 91 ▶use Test::More ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 91 ▶use Test::More::UTF8;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 91 ▶use ChordPro::Files;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 91 ▶use ChordPro::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 91 ▶use ChordPro::Paths;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 91 ▶use ChordPro::Chords;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 91 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
29 91 my $pkg = shift;
30  
31 # This is dirty...
32 91 ▶ -d "t" && chdir "t";
Branch: 1 branch
BranchTrueFalseTotal
-d "t" and chdir "t" 84 7 91
33  
34 91 $::running_under_test = 1;
35 91 Test::More->export_to_level(1);
36 91 $pkg->export_to_level( 1, undef, @EXPORT );
37 }
38  
39 138 ▶sub is_deeply {
Subroutine is_deeply: called CC=12 SCAR=24.9
Pod undocumented
40 138 my ( $got, $expect, $tag ) = @_;
41  
42 138 ▶ if ( ref($got) eq 'HASH' && ref($expect) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $got eq "HASH" and ref $expect eq "HASH") 107 31 138
Condition66%2/3
ref $got eq "HASH" and ref $expect eq "HASH"
!ll&&!rl&&r
310107
MC/DC50%1/2
ref $got eq "HASH" and ref $expect eq "HASH"
ref $got eq "HASH" ref $expect eq "HASH"
Truth table66%2/3
A and B
A= ref $got eq "HASH"B= ref $expect eq "HASH"
ABresult
0X0
100
111
43 107 ▶ fixchords($got) if $got->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $got->{"body"} 44 63 107
44  
45 107 for ( qw( config generate ) ) {
46 214 ▶ delete $got->{$_} unless exists $expect->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $expect->{$_} 214 0 214
47 }
48 107 ▶ if ( $got->{chordsinfo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->{"chordsinfo"}) 89 18 107
49 89 ▶ if ( !%{$got->{chordsinfo}} && !$expect->{chordsinfo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %{$got->{'chordsinfo'};} || $expect->{'chordsinfo'}) { } 51 38 89
Condition100%3/3
%{$got->{'chordsinfo'};} || $expect->{'chordsinfo'}
l!l&&r!l&&!r
32651
MC/DC100%2/2
%{$got->{'chordsinfo'};} || $expect->{'chordsinfo'}
%{$got->{'chordsinfo'};} $expect->{'chordsinfo'}
Truth table100%3/3
A || B
A= %{$got->{'chordsinfo'};}B= $expect->{'chordsinfo'}
ABresult
1X1
011
000
50 51 delete $got->{chordsinfo};
51 }
52 else {
53 38 foreach ( keys %{ $got->{chordsinfo} } ) {
54 104 $got->{chordsinfo}{$_} = $got->{chordsinfo}{$_}->name;
55 }
56 }
57 }
58 107 for ( qw( instrument user _key key_actual key_sound key_print
59 chords numchords
60 _configversion bookmark
61 ) ) {
62 1070 ▶ delete $got->{meta}->{$_} unless exists $expect->{meta}->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $expect->{"meta"}{$_} 1056 14 1070
63 }
64 }
65  
66 138 Test::More::is_deeply( $got, $expect, $tag );
67 }
68  
69 91 push( @EXPORT, 'is_deeply' );
70  
71 91 ▶sub testconfig {
Subroutine testconfig: called CC=1 SCAR=0.0
Pod undocumented
72 # May change later.
73 91 ChordPro::Config::configurator;
74 }
75  
76 91 push( @EXPORT, 'testconfig' );
77  
78 91 our $config = testconfig();
79  
80 91 ChordPro::Chords::add_config_chord
81 ( { name => "NC", base => 1, frets => [ (-1)x6 ], fingers => [] } );
82  
83 {
84 91 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 11 ▶sub getresource {
Subroutine getresource: called CC=1 SCAR=0.0
Pod undocumented
87 11 CP->findres($_[0]);
88 }
89 }
90  
91 91 push( @EXPORT, 'getresource' );
92  
93 0 ▶sub cmp {
Subroutine cmp: not called CC=8 SCAR=42.8
Pod undocumented
94 # Perl version of the 'cmp' program.
95 # Returns 1 if the files differ, 0 if the contents are equal.
96 0 my ($old, $new) = @_;
97 0 ▶ unless ( open (F1, $old) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open F1, $old) 0 0 0
98 0 print STDERR ("$old: $!\n");
99 0 return 1;
100 }
101 0 ▶ unless ( open (F2, $new) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open F2, $new) 0 0 0
102 0 print STDERR ("$new: $!\n");
103 0 return 1;
104 }
105 0 my ($buf1, $buf2);
106 0 my ($len1, $len2);
107 0 while ( 1 ) {
108 0 $len1 = sysread (F1, $buf1, 10240);
109 0 $len2 = sysread (F2, $buf2, 10240);
110 0 ▶ return 0 if $len1 == $len2 && $len1 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len1 == $len2 and $len1 == 0 0 0 0
Condition0%0/3
$len1 == $len2 and $len1 == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$len1 == $len2 and $len1 == 0
$len1 == $len2 $len1 == 0
Truth table0%0/3
A and B
A= $len1 == $len2B= $len1 == 0
ABresult
0X0
100
111
111 0 ▶ return 1 if $len1 != $len2 || ( $len1 && $buf1 ne $buf2 );
Branch: 1 branch
BranchTrueFalseTotal
if $len1 != $len2 or $len1 and $buf1 ne $buf2 0 0 0
Condition0%0/6
$len1 != $len2 or $len1 and $buf1 ne $buf2
l!l&&r!l&&!r
000
$len1 and $buf1 ne $buf2
!ll&&!rl&&r
000
MC/DC0%0/3
$len1 != $len2 or $len1 and $buf1 ne $buf2
$len1 != $len2 $len1 $buf1 ne $buf2
Truth table0%0/4
A or B and C
A= $len1 != $len2B= $len1C= $buf1 ne $buf2
ABCresult
1XX1
0111
00X0
0100
112 }
113 }
114  
115 84 ▶sub differ {
Subroutine differ: called CC=11 SCAR=27.6
Pod undocumented
116 84 my ($file1, $file2) = @_;
117 84 ▶ $file2 = "$file1" unless $file2;
Branch: 1 branch
BranchTrueFalseTotal
unless $file2 0 84 84
118 84 $file1 = "$file1";
119  
120 84 my @lines1 = @{ fs_load( $file1, { fail => 'hard' } ) };
121 84 my @lines2 = @{ fs_load( $file2, { fail => 'hard' } ) };
122 84 ▶ my $linesm = @lines1 > @lines2 ? @lines1 : @lines2;
Branch: 1 branch
BranchTrueFalseTotal
@lines1 > @lines2 ? : 0 84 84
123 84 my $todo = "";
124 84 ▶ if ( @lines1 > 0 && @lines2 > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines1 > 0 and @lines2 > 0) 84 0 84
Condition33%1/3
@lines1 > 0 and @lines2 > 0
!ll&&!rl&&r
0084
MC/DC0%0/2
@lines1 > 0 and @lines2 > 0
@lines1 > 0 @lines2 > 0
Truth table33%1/3
A and B
A= @lines1 > 0B= @lines2 > 0
ABresult
0X0
100
111
125 84 ▶ $todo = "TODO " if $lines1[0] =~ /\bTODO\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines1[0] =~ /\bTODO\b/ 1 83 84
126 }
127 84 ▶ for ( my $line = 0; $line < $linesm; $line++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line < $linesm) 2537 83 2620
128 2537 ▶ next if $lines1[$line] eq $lines2[$line];
Branch: 1 branch
BranchTrueFalseTotal
if $lines1[$line] eq $lines2[$line] 2536 1 2537
129 1 Test::More::diag("${todo}Files $file1 and $file2 differ at line ", 1+$line);
130 1 Test::More::diag(" < $lines1[$line]");
131 1 Test::More::diag(" > $lines2[$line]");
132 1 return !$todo;
133 }
134 83 ▶ return 0 if @lines1 == @lines2;
Branch: 1 branch
BranchTrueFalseTotal
if @lines1 == @lines2 83 0 83
135 0 $linesm++;
136 0 Test::More::diag("${todo}Files $file1 and $file2 differ at line ", 1+$linesm);
137 0 ▶ Test::More::diag(" < ", $lines1[$linesm] // "***missing***");
Condition0%0/2
$lines1[$linesm] // "***missing***"
l!l
00
MC/DC0%0/1
$lines1[$linesm] // "***missing***"
$lines1[$linesm]
Truth table0%0/2
A
A= $lines1[$linesm]
Aresult
11
00
138 0 ▶ Test::More::diag(" > ", $lines2[$linesm] // "***missing***");
Condition0%0/2
$lines2[$linesm] // "***missing***"
l!l
00
MC/DC0%0/1
$lines2[$linesm] // "***missing***"
$lines2[$linesm]
Truth table0%0/2
A
A= $lines2[$linesm]
Aresult
11
00
139 0 1;
140 }
141  
142 91 push( @EXPORT, 'differ' );
143  
144 44 ▶sub fixchords {
Subroutine fixchords: called CC=17 SCAR=28.3
Pod undocumented
145 44 my ( $s ) = @_;
146 44 ▶ for ( @{ $s->{body} // [] } ) {
Condition50%1/2
$s->{"body"} // []
l!l
440
MC/DC0%0/1
$s->{"body"} // []
$s->{"body"}
Truth table50%1/2
A
A= $s->{"body"}
Aresult
11
00
147 226 ▶ for ( @{ $_->{chords} // [] } ) {
Condition100%2/2
$_->{"chords"} // []
l!l
53173
MC/DC100%1/1
$_->{"chords"} // []
$_->{"chords"}
Truth table100%2/2
A
A= $_->{"chords"}
Aresult
11
00
148 191 ▶ $_ = $_->key if UNIVERSAL::can( $_, "key" );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_, "key") 157 34 191
149 }
150 226 ▶ for ( @{ $_->{chorus} // [] } ) {
Condition100%2/2
$_->{"chorus"} // []
l!l
14212
MC/DC100%1/1
$_->{"chorus"} // []
$_->{"chorus"}
Truth table100%2/2
A
A= $_->{"chorus"}
Aresult
11
00
151 28 ▶ for ( @{ $_->{chords} // [] } ) {
Condition100%2/2
$_->{"chords"} // []
l!l
1414
MC/DC100%1/1
$_->{"chords"} // []
$_->{"chords"}
Truth table100%2/2
A
A= $_->{"chords"}
Aresult
11
00
152 47 ▶ $_ = $_->key if UNIVERSAL::can( $_, "key" );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_, "key") 36 11 47
153 }
154 }
155 226 ▶ for ( @{ $_->{tokens} // [] } ) {
Condition100%2/2
$_->{"tokens"} // []
l!l
8218
MC/DC100%1/1
$_->{"tokens"} // []
$_->{"tokens"}
Truth table100%2/2
A
A= $_->{"tokens"}
Aresult
11
00
156 136 ▶ if ( $_->{class} eq "chord" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_->{'class'} eq 'chord') { } 31 105 136
elsif ($_->{'class'} eq 'chords') { } 1 104 105
157 31 for ( $_->{chord} ) {
158 31 $_ = $_->key;
159 }
160 }
161 elsif ( $_->{class} eq "chords" ) {
162 1 for ( @{ $_->{chords} } ) {
163 2 $_ = $_->key;
164 }
165 }
166 }
167 }
168 }
169  
170 91 push( @EXPORT, 'fixchords' );
171  
172 91 1;
« lib/ChordPro/Paths.pm ↑ Summary lib/ChordPro/Delegate/SVG.pm »