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/Partial/Gettext.pm ↑ Summary blib/lib/YATT/Lite/VFS.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 19 ▶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 283 ▶ sub is_runnable { shift->ntests }
Subroutine is_runnable: called CC=1 SCAR=0.0
49 574 ▶ sub ntests {
Subroutine ntests: called CC=3 SCAR=11.0
50 574 my __PACKAGE__ $item = shift;
51 574 ▶ if ($item->{OUT}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($item->{'OUT'}) { } 400 174 574
elsif ($item->{'ERROR'}) { } 158 16 174
52 400 2;
53 } elsif ($item->{ERROR}) {
54 158 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 $_) ? : 19 0 19
73 } @_;
74 }
75  
76 19 ▶sub after_new {
Subroutine after_new: called CC=2 SCAR=7.2
Pod documented
77 19 my MY $self = shift;
78 19 $self->{_numtests} = 0;
79 19 $self->{_tests} = [];
80 19 ▶ $self->{ext} //= $self->default_ext;
Condition33%1/3
$self->{"ext"} //= $self->default_ext
l!l&&r!l&&!r
0190
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 19 $self;
82 }
83 19 ▶sub load {
Subroutine load: called CC=3 SCAR=11.0
Pod undocumented
84 19 my $pack = shift;
85 19 my Parser $parser = $pack->Parser->new(@_);
86 19 my MY $self = $pack->new($parser->cf_delegate(qw(filename))
87 , parser => $parser);
88 19 ▶ if (my @global = $parser->read(skip_comment => 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@global) = $parser->read("skip_comment", 0)) 6 13 19
89 6 $self->configure(@global);
90 6 $parser->configure($self->cf_delegate_defined(qw(encoding)));
91 }
92 19 ▶ while (my @config = $parser->read) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@config) = $parser->read) 283 19 302
93 283 $self->add_item($self->Item->new(@config));
94 }
95 19 $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 19 ▶sub ntests {
Subroutine ntests: called CC=1 SCAR=0.0
Pod undocumented
113 19 my MY $self = shift; $self->{_numtests}
114 19 }
115 283 ▶sub add_item {
Subroutine add_item: called CC=2 SCAR=7.6
Pod undocumented
116 283 (my MY $self, my Item $item) = @_;
117 283 ▶ if ($item->{global}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"global"}) 0 283 283
118 0 $self->{_global} = $item->{global};
119 0 next;
120 }
121 283 push @{$self->{_tests}}, $self->fixup_item($item);
122 283 $self->{_numtests} += $item->ntests;
123 }
124  
125 283 ▶sub fixup_item {
Subroutine fixup_item: called CC=15 SCAR=27.6
Pod undocumented
126 283 (my MY $self, my Item $test) = @_;
127 283 my Item $prev = $self->{_prev_item};
128 283 ▶ $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
92740
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 274 ▶ if ($prev && $prev->{FILE} =~ m{%d}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->{'FILE'} =~ /%d/) { } 253 21 274
Condition100%3/3
$prev and $prev->{"FILE"} =~ /%d/
!ll&&!rl&&r
192253
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 253 } else {
132 21 "f%d.$self->{ext}"
133 }
134 };
135  
136 283 $test->{_realfile} = do {
137 283 ▶ if ($test->{IN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->{'IN'}) { } 246 37 283
138 2 ▶ no if $] >= 5.021002, warnings => qw/redundant/;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 246 ▶ sprintf($test->{FILE}, 1+@{$self->{_file_list} //= []})
Condition100%2/2
$self->{"_file_list"} //= []
l!l
22719
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 283 ▶ $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
02830
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 283 my $widget = $test->{_realfile};
147 283 $widget =~ s{\.\w+$}{};
148 283 $widget =~ s{/}{:}g;
149 283 $widget;
150 };
151  
152 283 ▶ if ($test->{IN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->{"IN"}) 246 37 283
153 246 ▶ if (my $conflict = $self->{_file_dict}{$test->{_realfile}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $conflict = $self->{"_file_dict"}{$test->{"_realfile"}}) 0 246 246
154 0 die "FILE name confliction in test $test";
155 }
156 246 $self->{_file_dict}{$test->{_realfile}} = $test;
157 246 push @{$self->{_file_list}}, $test->{_realfile};
158 }
159  
160 283 ▶ if ($test->{OUT} || $test->{ERROR}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->{"OUT"} or $test->{"ERROR"}) 275 8 283
Condition100%3/3
$test->{"OUT"} or $test->{"ERROR"}
l!l&&r!l&&!r
197788
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 275 ▶ $test->{WIDGET} ||= $prev && $prev->{WIDGET};
Condition16%1/6
$test->{"WIDGET"} ||= $prev && $prev->{"WIDGET"}
l!l&&r!l&&!r
27500
$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 275 ▶ if (not $test->{TITLE} and $prev) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $test->{"TITLE"} and $prev) 24 251 275
Condition100%3/3
not $test->{"TITLE"} and $prev
!ll&&!rl&&r
250124
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 275 $self->{_prev_item} = $test;
167 }
168  
169 283 $test;
170 }
171  
172 19 ▶sub as_vfs_data {
Subroutine as_vfs_data: called CC=5 SCAR=16.7
Pod undocumented
173 19 my MY $self = shift;
174 19 my (%result);
175 # 記述の順番どおりに作成
176 19 foreach my $fn (@{$self->{_file_list}}) {
177 246 my Item $item = $self->{_file_dict}{$fn};
178 246 my @path = split m|/|, $fn;
179 246 my $path_cursor = path_cursor(\%result, \@path);
180 246 ▶ $path[0] =~ s|\.(\w+)$||
Branch: 1 branch
BranchTrueFalseTotal
$path[0] =~ s/\.(\w+)$// or die "Can't handle filename as vfs key: $fn" 246 0 246
181 or die "Can't handle filename as vfs key: $fn";
182 246 my $ext = $1;
183 246 ▶ if (my $sub = $self->can("convert_$ext")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("convert_$ext")) { } 0 246 246
184 0 $sub->($self, $path_cursor, $item)
185 } else {
186 # XXX: 既に配列になってると困るよね。 rc 系を後回しにすれば大丈夫?
187 246 ▶ unless (defined $item->{IN}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $item->{"IN"}) 0 246 246
188 0 die "undef IN"
189 }
190 246 $path_cursor->[0]{$path[0]} = $item->{IN};
191 }
192 }
193 19 \%result;
194 }
195  
196 246 ▶sub path_cursor {
Subroutine path_cursor: called CC=3 SCAR=11.0
Pod undocumented
197 246 my ($top, $path) = @_;
198 # path を一個残して、vivify する。
199 # そこにいたる経路を cursor として返す。
200 246 my $cursor = [$top];
201 246 ▶ while (@$path > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$path > 1) 1 246 247
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 246 $cursor;
206 }
207  
208 2 1;
« blib/lib/YATT/Lite/Partial/Gettext.pm ↑ Summary blib/lib/YATT/Lite/VFS.pm »