blib/lib/YATT/Lite/Test/XHFTest.pm

filter: Statementstmt 96.1% 124 / 129 Branchbran 80.5% 29 / 36 Conditioncond 60.7% 17 / 28 MC/DCmcdc 41.1% 7 / 17 Subroutinesub 100% 24 / 24 Podpod 10.0% 1 / 10 totaltotal 82.7% 202 / 244 CC 31 SCAR 18.2
CC
31
Cov
88%
fixup_item
15.7
as_vfs_data
5.3
convert_enc_array
4.0
CRAP 6.2
« blib/lib/YATT/Lite/VFS.pm ↑ Summary blib/lib/YATT/Lite/Test/TestFiles.pm »
1 package YATT::Lite::Test::XHFTest;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use YATT::Lite::MFields qw/_tests _numtests _yatt _global _file_list _file_dict
Subroutine BEGIN: called CC=1 SCAR=0.0
6 filename ext parser encoding
7 2 _prev_item _builder/;
8 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 sub MY () {__PACKAGE__}
10 2 ▶use YATT::Lite::Util qw(default dict_sort);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶sub default_ext {'yatt'}
Subroutine default_ext: called CC=1 SCAR=0.0
Pod undocumented
12 2 our @EXPORT_OK = qw(Item);
13  
14 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 {
17 sub Item () {'YATT::Lite::Test::XHFTest::Item'}
18 package YATT::Lite::Test::XHFTest::Item;
19 2 ▶ use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use YATT::Lite::Util qw(lexpand);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use YATT::Lite::MFields qw/global
Subroutine BEGIN: called CC=1 SCAR=0.0
22 parser
23  
24 _num
25 _realfile
26  
27 FILE
28 TITLE
29 BREAK
30 SKIP
31 TODO
32 PERL_MINVER
33  
34 WIDGET
35 RANDOM
36 IN
37 PARAM
38 OUT
39 ERROR
40 ERROR_BODY
41  
42 REQUIRE
43  
44 TAG
45 CON_CLASS
46 2 /;
47  
48 245 ▶ sub is_runnable { shift->ntests }
Subroutine is_runnable: called CC=1 SCAR=0.0
49 498 ▶ sub ntests {
Subroutine ntests: called CC=3 SCAR=11.0
50 498 my __PACKAGE__ $item = shift;
51 498 ▶ if ($item->{OUT}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($item->{'OUT'}) { } 366 132 498
elsif ($item->{'ERROR'}) { } 116 16 132
52 366 2;
53 } elsif ($item->{ERROR}) {
54 116 1;
55 } else {
56 16 0;
57 }
58 }
59 1 ▶ sub test_require {
Subroutine test_require: called CC=1 SCAR=0.0
60 1 my ($self, $reqlist) = @_;
61 1 grep {not eval qq{require $_}} lexpand($reqlist);
62 }
63  
64 }
65  
66 2 require YATT::Lite::XHF;
67 sub Parser () {'YATT::Lite::XHF'}
68  
69 1 ▶sub list_files {
Subroutine list_files: called CC=2 SCAR=7.1
Pod undocumented
70 1 my $pack = shift;
71 map {
72 1 ▶ ! -d $_ ? $_ : dict_sort <$_/*.xhf>;
Branch: 1 branch
BranchTrueFalseTotal
!(-d $_) ? : 18 0 18
73 } @_;
74 }
75  
76 18 ▶sub after_new {
Subroutine after_new: called CC=2 SCAR=7.2
Pod documented
77 18 my MY $self = shift;
78 18 $self->{_numtests} = 0;
79 18 $self->{_tests} = [];
80 18 ▶ $self->{ext} //= $self->default_ext;
Condition33%1/3
$self->{"ext"} //= $self->default_ext
l!l&&r!l&&!r
0180
MC/DC0%0/2
$self->{"ext"} //= $self->default_ext
$self->{"ext"} $self->default_ext
Truth table33%1/3
A //= B
A= $self->{"ext"}B= $self->default_ext
ABresult
1X1
011
000
81 18 $self;
82 }
83 18 ▶sub load {
Subroutine load: called CC=3 SCAR=11.0
Pod undocumented
84 18 my $pack = shift;
85 18 my Parser $parser = $pack->Parser->new(@_);
86 18 my MY $self = $pack->new($parser->cf_delegate(qw(filename))
87 , parser => $parser);
88 18 ▶ if (my @global = $parser->read(skip_comment => 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@global) = $parser->read("skip_comment", 0)) 6 12 18
89 6 $self->configure(@global);
90 6 $parser->configure($self->cf_delegate_defined(qw(encoding)));
91 }
92 18 ▶ while (my @config = $parser->read) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@config) = $parser->read) 245 18 263
93 245 $self->add_item($self->Item->new(@config));
94 }
95 18 $self;
96 }
97  
98 2 ▶sub convert_enc_array {
Subroutine convert_enc_array: called CC=4 SCAR=13.9
Pod undocumented
99 2 my ($self, $enc, $array) = @_;
100 2 foreach (@$array) {
101 5 ▶ unless (ref $_) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_) { } 1 4 5
if (do { ref $_ eq 'ARRAY' }) { } 1 0 1
102 4 $_ = decode($enc, $_)
103 } elsif (ref $_ eq 'ARRAY') {
104 1 $_ = $self->convert_enc_array($enc, $_);
105 } else {
106 # nop.
107 }
108 }
109 2 $array;
110 }
111  
112 18 ▶sub ntests {
Subroutine ntests: called CC=1 SCAR=0.0
Pod undocumented
113 18 my MY $self = shift; $self->{_numtests}
114 18 }
115 245 ▶sub add_item {
Subroutine add_item: called CC=2 SCAR=7.6
Pod undocumented
116 245 (my MY $self, my Item $item) = @_;
117 245 ▶ if ($item->{global}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"global"}) 0 245 245
118 0 $self->{_global} = $item->{global};
119 0 next;
120 }
121 245 push @{$self->{_tests}}, $self->fixup_item($item);
122 245 $self->{_numtests} += $item->ntests;
123 }
124  
125 245 ▶sub fixup_item {
Subroutine fixup_item: called CC=15 SCAR=27.6
Pod undocumented
126 245 (my MY $self, my Item $test) = @_;
127 245 my Item $prev = $self->{_prev_item};
128 245 ▶ $test->{FILE} ||= do {
Condition66%2/3
$test->{"FILE"} ||= do { if ($prev and $prev->{"FILE"} =~ /%d/) { $prev->{"FILE"}; } else { qq[f%d.$self->{"ext"}]; } }
l!l&&r!l&&!r
92360
MC/DC0%0/2
$test->{"FILE"} ||= do { if ($prev and $prev->{"FILE"} =~ /%d/) { $prev->{"FILE"}; } else { qq[f%d.$self->{"ext"}]; } }
$test->{"FILE"} do { if ($prev and $prev->{"FILE"} =~ /%d/) { $prev->{"FILE"}; } else { qq[f%d.$self->{"ext"}]; } }
Truth table66%2/3
A ||= B
A= $test->{"FILE"}B= do { if ($prev and $prev->{"FILE"} =~ /%d/) { $prev->{"FILE"}; } else { qq[f%d.$self->{"ext"}]; } }
ABresult
1X1
011
000
129 236 ▶ if ($prev && $prev->{FILE} =~ m{%d}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->{'FILE'} =~ /%d/) { } 216 20 236
Condition100%3/3
$prev and $prev->{"FILE"} =~ /%d/
!ll&&!rl&&r
182216
MC/DC100%2/2
$prev and $prev->{"FILE"} =~ /%d/
$prev $prev->{"FILE"} =~ /%d/
Truth table100%3/3
A and B
A= $prevB= $prev->{"FILE"} =~ /%d/
ABresult
0X0
100
111
130 $prev->{FILE}
131 216 } else {
132 20 "f%d.$self->{ext}"
133 }
134 };
135  
136 245 $test->{_realfile} = do {
137 245 ▶ if ($test->{IN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->{'IN'}) { } 208 37 245
138 2 ▶ no if $] >= 5.021002, warnings => qw/redundant/;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 208 ▶ sprintf($test->{FILE}, 1+@{$self->{_file_list} //= []})
Condition100%2/2
$self->{"_file_list"} //= []
l!l
19018
MC/DC100%1/1
$self->{"_file_list"} //= []
$self->{"_file_list"}
Truth table100%2/2
A
A= $self->{"_file_list"}
Aresult
11
00
140 } else {
141 $prev->{_realfile}
142 37 }
143 };
144  
145 245 ▶ $test->{WIDGET} ||= do {
Condition33%1/3
$test->{"WIDGET"} ||= do { my $widget = $test->{"_realfile"}; $widget =~ s/\.\w+$//; $widget =~ s[/][:]g; $widget }
l!l&&r!l&&!r
02450
MC/DC0%0/2
$test->{"WIDGET"} ||= do { my $widget = $test->{"_realfile"}; $widget =~ s/\.\w+$//; $widget =~ s[/][:]g; $widget }
$test->{"WIDGET"} do { my $widget = $test->{"_realfile"}; $widget =~ s/\.\w+$//; $widget =~ s[/][:]g; $widget }
Truth table33%1/3
A ||= B
A= $test->{"WIDGET"}B= do { my $widget = $test->{"_realfile"}; $widget =~ s/\.\w+$//; $widget =~ s[/][:]g; $widget }
ABresult
1X1
011
000
146 245 my $widget = $test->{_realfile};
147 245 $widget =~ s{\.\w+$}{};
148 245 $widget =~ s{/}{:}g;
149 245 $widget;
150 };
151  
152 245 ▶ if ($test->{IN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->{"IN"}) 208 37 245
153 208 ▶ if (my $conflict = $self->{_file_dict}{$test->{_realfile}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $conflict = $self->{"_file_dict"}{$test->{"_realfile"}}) 0 208 208
154 0 die "FILE name confliction in test $test";
155 }
156 208 $self->{_file_dict}{$test->{_realfile}} = $test;
157 208 push @{$self->{_file_list}}, $test->{_realfile};
158 }
159  
160 245 ▶ if ($test->{OUT} || $test->{ERROR}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->{"OUT"} or $test->{"ERROR"}) 237 8 245
Condition100%3/3
$test->{"OUT"} or $test->{"ERROR"}
l!l&&r!l&&!r
180578
MC/DC100%2/2
$test->{"OUT"} or $test->{"ERROR"}
$test->{"OUT"} $test->{"ERROR"}
Truth table100%3/3
A or B
A= $test->{"OUT"}B= $test->{"ERROR"}
ABresult
1X1
011
000
161 237 ▶ $test->{WIDGET} ||= $prev && $prev->{WIDGET};
Condition16%1/6
$test->{"WIDGET"} ||= $prev && $prev->{"WIDGET"}
l!l&&r!l&&!r
23700
$prev && $prev->{'WIDGET'}
!ll&&!rl&&r
000
MC/DC0%0/3
$test->{"WIDGET"} ||= $prev && $prev->{"WIDGET"}
$test->{"WIDGET"} $prev $prev->{'WIDGET'}
Truth table0%0/4
A ||= B && C
A= $test->{"WIDGET"}B= $prevC= $prev->{'WIDGET'}
ABCresult
1XX1
0111
00X0
0100
162 237 ▶ if (not $test->{TITLE} and $prev) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $test->{"TITLE"} and $prev) 24 213 237
Condition100%3/3
not $test->{"TITLE"} and $prev
!ll&&!rl&&r
212124
MC/DC100%2/2
not $test->{"TITLE"} and $prev
not $test->{"TITLE"} $prev
Truth table100%3/3
not(A) and B
A= not $test->{"TITLE"}B= $prev
ABresult
0X0
100
111
163 24 $test->{_num} = default($prev->{_num}, 0) + 1;
164 24 $test->{TITLE} = $prev->{TITLE};
165 }
166 237 $self->{_prev_item} = $test;
167 }
168  
169 245 $test;
170 }
171  
172 18 ▶sub as_vfs_data {
Subroutine as_vfs_data: called CC=5 SCAR=16.7
Pod undocumented
173 18 my MY $self = shift;
174 18 my (%result);
175 # 記述の順番どおりに作成
176 18 foreach my $fn (@{$self->{_file_list}}) {
177 208 my Item $item = $self->{_file_dict}{$fn};
178 208 my @path = split m|/|, $fn;
179 208 my $path_cursor = path_cursor(\%result, \@path);
180 208 ▶ $path[0] =~ s|\.(\w+)$||
Branch: 1 branch
BranchTrueFalseTotal
$path[0] =~ s/\.(\w+)$// or die "Can't handle filename as vfs key: $fn" 208 0 208
181 or die "Can't handle filename as vfs key: $fn";
182 208 my $ext = $1;
183 208 ▶ if (my $sub = $self->can("convert_$ext")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("convert_$ext")) { } 0 208 208
184 0 $sub->($self, $path_cursor, $item)
185 } else {
186 # XXX: 既に配列になってると困るよね。 rc 系を後回しにすれば大丈夫?
187 208 ▶ unless (defined $item->{IN}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $item->{"IN"}) 0 208 208
188 0 die "undef IN"
189 }
190 208 $path_cursor->[0]{$path[0]} = $item->{IN};
191 }
192 }
193 18 \%result;
194 }
195  
196 208 ▶sub path_cursor {
Subroutine path_cursor: called CC=3 SCAR=11.0
Pod undocumented
197 208 my ($top, $path) = @_;
198 # path を一個残して、vivify する。
199 # そこにいたる経路を cursor として返す。
200 208 my $cursor = [$top];
201 208 ▶ while (@$path > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$path > 1) 1 208 209
202 1 my $nm = shift @$path;
203 1 ▶ $cursor = [$cursor->[0]{$nm} ||= {}, $cursor];
Condition50%1/2
$cursor->[0]{$nm} ||= {}
l!l
01
MC/DC0%0/1
$cursor->[0]{$nm} ||= {}
$cursor->[0]{$nm}
Truth table50%1/2
A
A= $cursor->[0]{$nm}
Aresult
11
00
204 }
205 208 $cursor;
206 }
207  
208 2 1;
« blib/lib/YATT/Lite/VFS.pm ↑ Summary blib/lib/YATT/Lite/Test/TestFiles.pm »