blib/lib/Test/YAML.pm

filter: Statementstmt 20.2% 31 / 153 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 18.1% 8 / 44 Podpod 0.0% 0 / 14 totaltotal 13.5% 39 / 288 CC 30 SCAR 32.0
CC
30
Cov
14%
roundtrip_nyn
110.0
count_roundtrip_nyn
56.0
_skip_yaml_tests
20.0
CRAP 24.5
↑ Summary
1 package Test::YAML;
2 1 our $VERSION = '1.07';
3  
4 1 ▶use Test::Base -Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $YAML = 'YAML';
7 1 our @EXPORT = qw(
8 no_diff
9 run_yaml_tests
10 run_roundtrip_nyn roundtrip_nyn
11 run_load_passes load_passes
12 dumper Load Dump LoadFile DumpFile
13 XXX
14 );
15  
16 1 delimiters('===', '+++');
17  
18 0 ▶sub Dump () { YAML(Dump => @_) }
Subroutine Dump: not called CC=1 SCAR=6.9
Pod undocumented
19 0 ▶sub Load () { YAML(Load => @_) }
Subroutine Load: not called CC=1 SCAR=6.9
Pod undocumented
20 0 ▶sub DumpFile () { YAML(DumpFile => @_) }
Subroutine DumpFile: not called CC=1 SCAR=6.9
Pod undocumented
21 0 ▶sub LoadFile () { YAML(LoadFile => @_) }
Subroutine LoadFile: not called CC=1 SCAR=6.9
Pod undocumented
22  
23 0 ▶sub YAML () {
Subroutine YAML: not called CC=2 SCAR=17.9
Pod undocumented
24 0 load_yaml_pm();
25 0 my $meth = shift;
26 0 ▶ my $code = $YAML->can($meth) or die "$YAML cannot do $meth";
Branch: 1 branch
BranchTrueFalseTotal
my $code = $Test::YAML::YAML->can($meth) or die "$Test::YAML::YAML cannot do $meth" 0 0 0
27 0 goto &$code;
28 }
29  
30 0 ▶sub load_yaml_pm {
Subroutine load_yaml_pm: not called CC=1 SCAR=6.9
Pod undocumented
31 0 my $file = "$YAML.pm";
32 0 $file =~ s{::}{/}g;
33 0 require $file;
34 }
35  
36 0 ▶sub run_yaml_tests() {
Subroutine run_yaml_tests: not called CC=1 SCAR=6.9
Pod undocumented
37 0 ▶ run {
Subroutine __ANON__: not called CC=3 SCAR=24.8
38 0 my $block = shift;
39 0 ▶ &{_get_function($block)}($block) unless
Branch: 1 branch
BranchTrueFalseTotal
unless _skip_tests_for_now($block) or _skip_yaml_tests($block) 0 0 0
Condition0%0/3
_skip_tests_for_now($block) or _skip_yaml_tests($block)
l!l&&r!l&&!r
000
MC/DC0%0/2
_skip_tests_for_now($block) or _skip_yaml_tests($block)
_skip_tests_for_now($block) _skip_yaml_tests($block)
Truth table0%0/3
A or B
A= _skip_tests_for_now($block)B= _skip_yaml_tests($block)
ABresult
1X1
011
000
40 _skip_tests_for_now($block) or
41 _skip_yaml_tests($block);
42 0 };
43 }
44  
45 0 ▶sub run_roundtrip_nyn() {
Subroutine run_roundtrip_nyn: not called CC=1 SCAR=6.9
Pod undocumented
46 0 my @options = @_;
47 0 ▶ run {
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 my $block = shift;
49 0 roundtrip_nyn($block, @options);
50 0 };
51 }
52  
53 0 ▶sub roundtrip_nyn() {
Subroutine roundtrip_nyn: not called CC=10 SCAR=47.0
Pod undocumented
54 0 my $block = shift;
55 0 ▶ my $option = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
56 die "'perl' data section required"
57 0 ▶ unless exists $block->{perl};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $block->{"perl"} 0 0 0
58 0 my @values = eval $block->perl;
59 0 ▶ die "roundtrip_nyn eval perl error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
60 0 ▶ my $config = $block->config || '';
Condition0%0/2
$block->config || ''
l!l
00
MC/DC0%0/1
$block->config || ''
$block->config
Truth table0%0/2
A
A= $block->config
Aresult
11
00
61 0 my $result = eval "$config; Dump(\@values)";
62 0 ▶ die "roundtrip_nyn YAML::Dump error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
63 0 ▶ if (exists $block->{yaml}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $block->{'yaml'}) { } 0 0 0
64 0 is $result, $block->yaml,
65 $block->description . ' (n->y)';
66 }
67 else {
68 0 pass $block->description . ' (n->y)';
69 }
70  
71 return if exists $block->{no_round_trip} or
72 0 ▶ not exists $block->{yaml};
Branch: 1 branch
BranchTrueFalseTotal
if exists $block->{"no_round_trip"} or not exists $block->{"yaml"} 0 0 0
Condition0%0/3
exists $block->{"no_round_trip"} or not exists $block->{"yaml"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $block->{"no_round_trip"} or not exists $block->{"yaml"}
exists $block->{"no_round_trip"} not exists $block->{"yaml"}
Truth table0%0/3
A or not(B)
A= exists $block->{"no_round_trip"}B= not exists $block->{"yaml"}
ABresult
1X1
011
000
73  
74 0 ▶ if ($option eq 'dumper') {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq 'dumper') { } 0 0 0
75 0 is dumper(Load($block->yaml)), dumper(@values),
76 $block->description . ' (y->n)';
77 }
78 else {
79 0 is_deeply [Load($block->yaml)], [@values],
80 $block->description . ' (y->n)';
81 }
82 }
83  
84 0 ▶sub count_roundtrip_nyn() {
Subroutine count_roundtrip_nyn: not called CC=7 SCAR=40.3
Pod undocumented
85 0 ▶ my $block = shift or die "Bad call to count_roundtrip_nyn";
Branch: 1 branch
BranchTrueFalseTotal
my $block = shift() or die "Bad call to count_roundtrip_nyn" 0 0 0
86 0 ▶ return 1 if exists $block->{skip_this_for_now};
Branch: 1 branch
BranchTrueFalseTotal
if exists $block->{"skip_this_for_now"} 0 0 0
87 0 my $count = 0;
88 0 ▶ $count++ if exists $block->{perl};
Branch: 1 branch
BranchTrueFalseTotal
if exists $block->{"perl"} 0 0 0
89 $count++ unless exists $block->{no_round_trip} or
90 0 ▶ not exists $block->{yaml};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $block->{"no_round_trip"} or not exists $block->{"yaml"} 0 0 0
Condition0%0/3
exists $block->{"no_round_trip"} or not exists $block->{"yaml"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $block->{"no_round_trip"} or not exists $block->{"yaml"}
exists $block->{"no_round_trip"} not exists $block->{"yaml"}
Truth table0%0/3
A or not(B)
A= exists $block->{"no_round_trip"}B= not exists $block->{"yaml"}
ABresult
1X1
011
000
91 0 ▶ die "Invalid test definition" unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
92 0 return $count;
93 }
94  
95 0 ▶sub run_load_passes() {
Subroutine run_load_passes: not called CC=1 SCAR=6.9
Pod undocumented
96 0 ▶ run {
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 0 my $block = shift;
98 0 my $yaml = $block->yaml;
99 0 eval { YAML(Load => $yaml) };
100 0 is("$@", "");
101 0 };
102 }
103  
104 0 ▶sub load_passes() {
Subroutine load_passes: not called CC=1 SCAR=6.9
Pod undocumented
105 0 my $block = shift;
106 0 my $yaml = $block->yaml;
107 0 eval { YAML(Load => $yaml) };
108 0 is "$@", "", $block->description;
109 }
110  
111 0 ▶sub count_load_passes() {1}
Subroutine count_load_passes: not called CC=1 SCAR=6.9
Pod undocumented
112  
113 0 ▶sub dumper() {
Subroutine dumper: not called CC=1 SCAR=6.9
Pod undocumented
114 0 require Data::Dumper;
115 0 $Data::Dumper::Sortkeys = 1;
116 0 $Data::Dumper::Terse = 1;
117 0 $Data::Dumper::Indent = 1;
118 0 return Data::Dumper::Dumper(@_);
119 }
120  
121 0 ▶sub _count_tests() {
Subroutine _count_tests: not called CC=2 SCAR=10.9
122 0 ▶ my $block = shift or die "Bad call to _count_tests";
Branch: 1 branch
BranchTrueFalseTotal
my $block = shift() or die "Bad call to _count_tests" 0 0 0
123 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
124 0 &{'count_' . _get_function_name($block)}($block);
125 }
126  
127 0 ▶sub _get_function_name() {
Subroutine _get_function_name: not called CC=2 SCAR=17.9
128 0 my $block = shift;
129 0 ▶ return $block->function || 'roundtrip_nyn';
Condition0%0/2
$block->function || 'roundtrip_nyn'
l!l
00
MC/DC0%0/1
$block->function || 'roundtrip_nyn'
$block->function
Truth table0%0/2
A
A= $block->function
Aresult
11
00
130 }
131  
132 0 ▶sub _get_function() {
Subroutine _get_function: not called CC=1 SCAR=1.2
133 0 my $block = shift;
134 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 0 \ &{_get_function_name($block)};
136 }
137  
138 0 ▶sub _skip_tests_for_now() {
Subroutine _skip_tests_for_now: not called CC=2 SCAR=17.9
139 0 my $block = shift;
140 0 ▶ if (exists $block->{skip_this_for_now}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $block->{"skip_this_for_now"}) 0 0 0
141 0 _skip_test(
142 $block->description,
143 _count_tests($block),
144 );
145 0 return 1;
146 }
147 0 return 0;
148 }
149  
150 0 ▶sub _skip_yaml_tests() {
Subroutine _skip_yaml_tests: not called CC=4 SCAR=30.0
151 0 my $block = shift;
152 0 ▶ if ($block->skip_unless_modules) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->skip_unless_modules) 0 0 0
153 0 my @modules = split /[\s\,]+/, $block->skip_unless_modules;
154 0 for my $module (@modules) {
155 0 eval "require $module";
156 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
157 0 _skip_test(
158 "This test requires the '$module' module",
159 _count_tests($block),
160 );
161 0 return 1;
162 }
163 }
164 }
165 0 return 0;
166 }
167  
168 0 ▶sub _skip_test() {
Subroutine _skip_test: not called CC=1 SCAR=6.9
169 0 my ($message, $count) = @_;
170 SKIP: {
171 0 skip($message, $count);
172 }
173 }
174  
175 #-------------------------------------------------------------------------------
176 package Test::YAML::Filter;
177  
178 1 ▶use Test::Base::Filter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 1 our @ISA = 'Test::Base::Filter';
181  
182 0 ▶sub yaml_dump {
Subroutine yaml_dump: not called CC=1 SCAR=6.9
183 0 Test::YAML::Dump(@_);
184 }
185  
186 0 ▶sub yaml_load {
Subroutine yaml_load: not called CC=1 SCAR=6.9
187 0 Test::YAML::Load(@_);
188 }
189  
190 0 ▶sub Dump { goto &Test::YAML::Dump }
Subroutine Dump: not called CC=1 SCAR=6.9
191 0 ▶sub Load { goto &Test::YAML::Load }
Subroutine Load: not called CC=1 SCAR=6.9
192 0 ▶sub DumpFile { goto &Test::YAML::DumpFile }
Subroutine DumpFile: not called CC=1 SCAR=6.9
193 0 ▶sub LoadFile { goto &Test::YAML::LoadFile }
Subroutine LoadFile: not called CC=1 SCAR=6.9
194  
195 0 ▶sub yaml_load_or_fail {
Subroutine yaml_load_or_fail: not called CC=2 SCAR=17.9
196 0 my ($result, $error, $warning) =
197 $self->_yaml_load_result_error_warning(@_);
198 0 ▶ return $error || $result;
Condition0%0/3
$error || $result
l!l&&r!l&&!r
000
MC/DC0%0/2
$error || $result
$error $result
Truth table0%0/3
A || B
A= $errorB= $result
ABresult
1X1
011
000
199 }
200  
201 0 ▶sub yaml_load_error_or_warning {
Subroutine yaml_load_error_or_warning: not called CC=3 SCAR=24.8
202 0 my ($result, $error, $warning) =
203 $self->_yaml_load_result_error_warning(@_);
204 0 ▶ return $error || $warning || '';
Condition0%0/5
$error || $warning || ''
l!l
00
$error or $warning
l!l&&r!l&&!r
000
MC/DC0%0/2
$error || $warning || ''
$error $warning
Truth table0%0/3
A or B
A= $errorB= $warning
ABresult
1X1
011
000
205 }
206  
207 0 ▶sub perl_eval_error_or_warning {
Subroutine perl_eval_error_or_warning: not called CC=3 SCAR=24.8
208 0 my ($result, $error, $warning) =
209 $self->_perl_eval_result_error_warning(@_);
210 0 ▶ return $error || $warning || '';
Condition0%0/5
$error || $warning || ''
l!l
00
$error or $warning
l!l&&r!l&&!r
000
MC/DC0%0/2
$error || $warning || ''
$error $warning
Truth table0%0/3
A or B
A= $errorB= $warning
ABresult
1X1
011
000
211 }
212  
213 0 ▶sub _yaml_load_result_error_warning {
Subroutine _yaml_load_result_error_warning: not called CC=1 SCAR=6.9
214 0 $self->assert_scalar(@_);
215 0 my $yaml = shift;
216 0 my $warning = '';
217 0 ▶ local $SIG{__WARN__} = sub { $warning = join '', @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
218 0 my $result = eval {
219 0 $self->yaml_load($yaml);
220 };
221 0 return ($result, $@, $warning);
222 }
223  
224 0 ▶sub _perl_eval_result_error_warning {
Subroutine _perl_eval_result_error_warning: not called CC=1 SCAR=6.9
225 0 $self->assert_scalar(@_);
226 0 my $perl = shift;
227 0 my $warning = '';
228 0 ▶ local $SIG{__WARN__} = sub { $warning = join '', @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
229 0 my $result = eval $perl;
230 0 return ($result, $@, $warning);
231 }
232  
233 1 1;
↑ Summary