blib/lib/App/TestOnTap/Config.pm

filter: Statementstmt 100% 136 / 136 Branchbran 86.1% 31 / 36 Conditioncond 85.7% 6 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 26 / 26 Podpod 0.0% 0 / 15 totaltotal 89.7% 201 / 224 SCAR 33.3
CC
28
Cov
97%
__readCfgFile
23.1
new
3.0
skip
2.0
CRAP 28.0
« blib/lib/App/TestOnTap/ParallelGroupManager.pm ↑ Summary blib/lib/App/TestOnTap/WorkDirManager.pm »
1 package App::TestOnTap::Config;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use App::TestOnTap::Util qw(slashify ensureArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use App::TestOnTap::OrderStrategy;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use App::TestOnTap::ExecMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use App::TestOnTap::ParallelGroupManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 19 ▶use Config::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use Grep::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use UUID::Tiny qw(:std);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # CTOR
17 #
18 sub new
19 {
20 28 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
21 28 my $suiteRoot = shift;
22 28 my $userCfgFile = shift;
23 28 my $ignoreDeps = shift;
24  
25 28 ▶ my $configFile = slashify(File::Spec->rel2abs($userCfgFile || "$suiteRoot/" . getName()));
Condition66%2/3
$userCfgFile || "$suiteRoot/" . getName()
l!l&&r!l&&!r
3250
MC/DC0%0/2
$userCfgFile || "$suiteRoot/" . getName()
$userCfgFile "$suiteRoot/" . getName()
Truth table66%2/3
A || B
A= $userCfgFileB= "$suiteRoot/" . getName()
ABresult
1X1
011
000
26 28 ▶ die("Missing configuration file '$configFile'\n") unless -f $configFile;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $configFile 1 27 28
27  
28 27 my $self = bless({}, $class);
29 27 $self->__readCfgFile($configFile, $ignoreDeps);
30  
31 27 return $self;
32 }
33  
34 # read the raw Config::Std file and fill in
35 # data fields
36 #
37 sub __readCfgFile
38 {
39 27 ▶ my $self = shift;
Subroutine __readCfgFile: called CC=23 SCAR=31.4
40 27 my $configFile = shift;
41 27 my $ignoreDeps = shift;
42
43 27 read_config($configFile, my $cfg);
44
45 # this looks weird, I know - see https://rt.cpan.org/Public/Bug/Display.html?id=56862
46 #
47 # I seem to hit the problem with "Warning: Name "Config::Std::Hash::DEMOLISH" used only once..."
48 # when running a Par::Packer binary but not when as a 'normal' script.
49 #
50 # The below incantation seem to get rid of that, at least for now. Let's see if it reappears...
51 #
52 27 my $dummy = *Config::Std::Hash::DEMOLISH;
53 27 $dummy = *Config::Std::Hash::DEMOLISH;
54
55 # pick the necessities from the blank section
56 #
57 27 ▶ my $blankSection = $cfg->{''} || {};
Condition100%2/2
$cfg->{''} || {}
l!l
1512
MC/DC100%1/1
$cfg->{''} || {}
$cfg->{''}
Truth table100%2/2
A
A= $cfg->{''}
Aresult
11
00
58  
59 # a valid uuid is required
60 #
61 27 ▶ my $id = $blankSection->{id} || '';
Condition100%2/2
$blankSection->{'id'} || ''
l!l
1512
MC/DC100%1/1
$blankSection->{'id'} || ''
$blankSection->{'id'}
Truth table100%2/2
A
A= $blankSection->{'id'}
Aresult
11
00
62 27 ▶ if (!$id)
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 12 15 27
63 {
64 12 $id = create_uuid_as_string();
65 12 warn("WARNING: No id found, using generated '$id'!\n");
66 12 $blankSection->{id} = $id;
67 }
68 27 ▶ die("Invalid/missing suite id: '$id'") unless $id =~ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ 0 27 27
69 27 $self->{id} = $id;
70
71 # an optional filter to skip parts while scanning suite root
72 #
73 # ensure it's in text form - an array is simply joined using newlines
74 #
75 27 my $skip = $blankSection->{skip};
76 27 ▶ if (defined($skip))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $skip) 2 25 27
77 {
78 2 ▶ $skip = join("\n", @$skip) if ref($skip) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $skip eq "ARRAY" 0 2 2
79 2 $skip = Grep::Query->new($skip);
80 }
81 27 $self->{skip} = $skip;
82  
83 # an optional filter to check if a test can run in parallel (with any other test)
84 #
85 # ensure it's in text form - an array is simply joined using newlines
86 #
87 27 my $parallelizable = $blankSection->{parallelizable};
88 27 ▶ if (defined($parallelizable))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parallelizable) 2 25 27
89 {
90 2 ▶ $parallelizable = join("\n", @$parallelizable) if ref($parallelizable) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $parallelizable eq "ARRAY" 0 2 2
91 2 $parallelizable = Grep::Query->new($parallelizable);
92 }
93 27 $self->{parallelizable} = $parallelizable;
94  
95 # read the optional order strategy
96 #
97 27 ▶ $self->{orderstrategy} = App::TestOnTap::OrderStrategy->new($blankSection->{order}) if $blankSection->{order};
Branch: 1 branch
BranchTrueFalseTotal
if $blankSection->{"order"} 2 25 27
98
99 # read the preprocess (optional) command
100 #
101 27 $self->{preprocesscmd} = ensureArray($blankSection->{preprocess});
102
103 # read the postprocess (optional) command
104 #
105 27 $self->{postprocesscmd} = ensureArray($blankSection->{postprocess});
106  
107 # set up optional ParallelGroup's
108 #
109 27 $self->{parallelgroupmanager} = App::TestOnTap::ParallelGroupManager->new($cfg);
110  
111 # set up the execmap, possibly as a delegate from a user defined one
112 #
113 27 $self->{execmap} = App::TestOnTap::ExecMap->new($cfg);
114  
115 27 my %depRules;
116 27 ▶ if (!$ignoreDeps)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ignoreDeps) 26 1 27
117 {
118 # find all dependency sections
119 #
120 26 my $depRx = qr(^\s*DEPENDENCY\s+(.+?)\s*$);
121 26 foreach my $depRuleSectionName (grep(/$depRx/, keys(%$cfg)))
122 {
123 5 $depRuleSectionName =~ /$depRx/;
124 5 my $depRuleName = $1;
125
126 # all dep sections requires match/dependson Grep::Query queries
127 # in case they're written as arrays, just join using newlines
128 #
129 5 foreach my $key (qw( match dependson ))
130 {
131 10 my $value = $cfg->{$depRuleSectionName}->{$key};
132 10 ▶ die("Missing key '$key' in dependency rule section '$depRuleName'\n") unless defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 10 10
133 10 ▶ $value = join("\n", @$value) if ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 10 10
134 10 $depRules{$depRuleName}->{$key} = Grep::Query->new($value);
135 }
136
137 # check for unknown keys...
138 #
139 5 my %validSectionKeys = map { $_ => 1 } qw(match dependson);
140 5 foreach my $key (keys(%{$cfg->{$depRuleSectionName}}))
141 {
142 11 ▶ warn("WARNING: Unknown key '$key' in section '[$depRuleSectionName]'\n") unless exists($validSectionKeys{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $validSectionKeys{$key} 1 10 11
143 }
144 }
145 }
146 27 $self->{deprules} = \%depRules;
147
148 # finally check the config for unknown sections/keys...
149 #
150 27 my @validSections = (qr/^$/, qr/^DEPENDENCY\s/, qr/^EXECMAP\s+[^\s]+\s*$/, qr/^PARALLELGROUP\s+[^\s]+\s*$/);
151 27 foreach my $section (sort(keys(%$cfg)))
152 {
153 37 my $knownSection = 0;
154 37 foreach my $secToMatch (@validSections)
155 {
156 51 ▶ if ($section =~ /$secToMatch/)
Branch: 1 branch
BranchTrueFalseTotal
if ($section =~ /$secToMatch/) 36 15 51
157 {
158 36 $knownSection = 1;
159 36 last;
160 }
161 }
162 37 ▶ warn("WARNING: Unknown section: '[$section]'\n") unless $knownSection;
Branch: 1 branch
BranchTrueFalseTotal
unless $knownSection 1 36 37
163 }
164  
165 27 my %validBlankSectionKeys = map { $_ => 1 } qw(id skip preprocess postprocess parallelizable order execmap);
166 27 foreach my $key (sort(keys(%$blankSection)))
167 {
168 38 ▶ warn("WARNING: Unknown key '$key' in default section\n") unless exists($validBlankSectionKeys{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $validBlankSectionKeys{$key} 1 37 38
169 }
170
171 27 $self->{rawcfg} = { %$cfg };
172 }
173  
174 sub getId
175 {
176 25 ▶ my $self = shift;
Subroutine getId: called CC=1 SCAR=0.0
Pod undocumented
177
178 25 return $self->{id};
179 }
180  
181 sub skip
182 {
183 58 ▶ my $self = shift;
Subroutine skip: called CC=2 SCAR=6.9
Pod undocumented
184 58 my $test = shift;
185
186 return
187 $self->{skip}
188 58 ▶ ? $self->{skip}->qgrep($test)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'skip'} ? : 4 54 58
189 : 0;
190 }
191  
192 sub getName
193 {
194 # works as both class/instance/sub...
195 #
196 110 ▶ return 'config.testontap';
Subroutine getName: called CC=1 SCAR=0.0
Pod undocumented
197 }
198  
199 sub getOrderStrategy
200 {
201 43 ▶ my $self = shift;
Subroutine getOrderStrategy: called CC=1 SCAR=0.0
Pod undocumented
202
203 43 return $self->{orderstrategy};
204 }
205  
206 sub getPreprocessCmd
207 {
208 27 ▶ my $self = shift;
Subroutine getPreprocessCmd: called CC=1 SCAR=0.0
Pod undocumented
209
210 27 return $self->{preprocesscmd};
211 }
212  
213 sub getPostprocessCmd
214 {
215 26 ▶ my $self = shift;
Subroutine getPostprocessCmd: called CC=1 SCAR=0.0
Pod undocumented
216
217 26 return $self->{postprocesscmd};
218 }
219  
220 sub hasParallelizableRule
221 {
222 2 ▶ my $self = shift;
Subroutine hasParallelizableRule: called CC=2 SCAR=6.9
Pod undocumented
223
224 2 ▶ return $self->{parallelizable} ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parallelizable'} ? : 1 1 2
225 }
226  
227 sub parallelizable
228 {
229 83 ▶ my $self = shift;
Subroutine parallelizable: called CC=2 SCAR=6.9
Pod undocumented
230 83 my $test = shift;
231
232 return
233 $self->{parallelizable}
234 83 ▶ ? $self->{parallelizable}->qgrep($test)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parallelizable'} ? : 6 77 83
235 : 0;
236 }
237  
238 sub hasExecMapping
239 {
240 56 ▶ my $self = shift;
Subroutine hasExecMapping: called CC=1 SCAR=0.0
Pod undocumented
241 56 my $testName = shift;
242  
243 56 return $self->{execmap}->hasMapping($testName);
244 }
245  
246 sub getExecMapping
247 {
248 48 ▶ my $self = shift;
Subroutine getExecMapping: called CC=1 SCAR=0.0
Pod undocumented
249 48 my $testName = shift;
250  
251 48 return $self->{execmap}->getMapping($testName);
252 }
253  
254 sub getRawCfg
255 {
256 25 ▶ my $self = shift;
Subroutine getRawCfg: called CC=1 SCAR=0.0
Pod undocumented
257  
258 25 return $self->{rawcfg};
259 }
260  
261 sub getDependencyRuleNames
262 {
263 27 ▶ my $self = shift;
Subroutine getDependencyRuleNames: called CC=1 SCAR=0.0
Pod undocumented
264
265 27 return keys(%{$self->{deprules}});
266 }
267  
268 sub getMatchesAndDependenciesForRule
269 {
270 5 ▶ my $self = shift;
Subroutine getMatchesAndDependenciesForRule: called CC=1 SCAR=0.0
Pod undocumented
271 5 my $depRuleName = shift;
272 5 my $tests = shift;
273
274 5 my @matches = $self->{deprules}->{$depRuleName}->{match}->qgrep(@$tests);
275 5 my @dependencies = $self->{deprules}->{$depRuleName}->{dependson}->qgrep(@$tests);
276
277 5 return (\@matches, \@dependencies);
278 }
279  
280 sub getParallelGroupManager
281 {
282 55 ▶ my $self = shift;
Subroutine getParallelGroupManager: called CC=1 SCAR=0.0
Pod undocumented
283 55 my $testName = shift;
284  
285 55 return $self->{parallelgroupmanager};
286 }
287  
288 19 1;
« blib/lib/App/TestOnTap/ParallelGroupManager.pm ↑ Summary blib/lib/App/TestOnTap/WorkDirManager.pm »