blib/lib/App/TestOnTap/Args.pm

filter: Statementstmt 78.7% 167 / 212 Branchbran 46.5% 40 / 86 Conditioncond 65.6% 21 / 32 MC/DCmcdc 45.0% 9 / 20 Subroutinesub 95.1% 39 / 41 Podpod 0.0% 0 / 19 totaltotal 67.3% 276 / 410 SCAR 50.3
CC
57
Cov
69%
__findSuiteRoot
183.3
__parseArgv
69.8
useHarness
2.0
CRAP 152.9
« blib/lib/App/TestOnTap/PackInfo.pm ↑ Summary blib/lib/App/TestOnTap/Util.pm »
1 # Parses a commandline packaged as a list (e.g. normally just pass @ARGV)
2 # and processes it into real objects for later use by various functions
3 # in the testontap universe
4 #
5 package App::TestOnTap::Args;
6  
7 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 19 ▶use App::TestOnTap::Util qw(slashify expandAts $IS_WINDOWS);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use App::TestOnTap::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use App::TestOnTap::Preprocess;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use App::TestOnTap::WorkDirManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use App::TestOnTap::OrderStrategy;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use App::TestOnTap::PackInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 19 ▶use Archive::Zip qw(:ERROR_CODES);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 19 ▶use Getopt::Long qw(GetOptionsFromArray :config require_order no_ignore_case bundling);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 19 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶use Pod::Simple::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use Grep::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 19 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 19 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 19 ▶use UUID::Tiny qw(:std);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 19 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # CTOR
29 #
30 sub new
31 {
32 29 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
33 29 my $version = shift;
34  
35 29 my $self = bless( { id => create_uuid_as_string() }, $class);
36 29 $self->__parseArgv($version, @_);
37  
38 27 return $self;
39 }
40  
41 sub __parseArgv
42 {
43 29 ▶ my $self = shift;
Subroutine __parseArgv: called CC=41 SCAR=42.5
44 29 my $version = shift;
45 29 my @argv = @_;
46
47 29 my %rawOpts =
48 (
49 usage => 0,
50 help => 0,
51 manual => 0,
52 version => 0,
53 configuration => undef, # no alternate config
54 define => {}, # arbitrary key=value defines
55 skip => undef, # no skip filter
56 include => undef, # no include filter
57 jobs => 1, # run only one job at a time (no parallelism)
58 order => undef, # have no particular strategy for test order
59 timer => 0, # don't show timing output
60 workdirectory => undef, # explicit directory to use
61 savedirectory => undef, # don't save results (unless -archive is used)
62 archive => 0, # don't save results as archive
63 v => 0, # don't let through output from tests
64 harness => 1, # use the normal test harness
65 merge => undef, # ask the harness to merge stdout/stderr of tests
66 dryrun => 0, # don't actually run tests
67
68 # hidden
69 #
70 _help => 0,
71 _pp => 0,
72 _pp_script => undef,
73 _pp_info => 0,
74 _ignore_dependencies => 0,
75 );
76
77 29 my @specs =
78 (
79 'usage|?',
80 'help|h',
81 'manual',
82 'version',
83 'configuration|cfg=s',
84 'define|D=s%',
85 'skip=s',
86 'include=s',
87 'jobs=i',
88 'order=s',
89 'timer!',
90 'workdirectory=s',
91 'savedirectory=s',
92 'archive',
93 'v|verbose+',
94 'harness!',
95 'merge!',
96 'dryrun!',
97
98 # hidden
99 #
100 '_help',
101 '_pp',
102 '_pp_script=s',
103 '_pp_info',
104 '_ignore_dependencies',
105 );
106  
107 29 my $_argsPodName = 'App/TestOnTap/_Args._pod';
108 29 my $_argsPodInput = Pod::Simple::Search->find($_argsPodName);
109 29 my $argsPodName = 'App/TestOnTap/Args.pod';
110 29 my $argsPodInput = Pod::Simple::Search->find($argsPodName);
111 29 my $manualPodName = 'App/TestOnTap.pod';
112 29 my $manualPodInput = Pod::Simple::Search->find($manualPodName);
113
114 # for consistent error handling below, trap getopts problems
115 #
116 eval
117 29 {
118 29 @argv = expandAts('.', @argv);
119 29 $self->{fullargv} = [ @argv ];
120 29 ▶ local $SIG{__WARN__} = sub { die(@_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
121 29 GetOptionsFromArray(\@argv, \%rawOpts, @specs)
122 };
123 29 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 29 29
124 {
125 0 pod2usage(-input => $argsPodInput, -message => "Failure parsing options:\n $@", -exitval => 255, -verbose => 0);
126 }
127  
128 # simple copies
129 #
130 29 $self->{$_} = $rawOpts{$_} foreach (qw(v archive timer harness dryrun));
131 29 $self->{defines} = $rawOpts{define};
132  
133 # help with the hidden flags...
134 #
135  
136 29 ▶ pod2usage(-input => $_argsPodInput, -exitval => 0, -verbose => 2, -noperldoc => 1) if $rawOpts{_help};
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"_help"} 0 29 29
137  
138 # for the special selection of using --_pp* turn over to packinfo
139 #
140 29 my %packHelperOpts;
141 29 foreach my $opt (keys(%rawOpts))
142 {
143 667 ▶ $packHelperOpts{$opt} = $rawOpts{$opt} if ($opt =~ /^_pp(_.+)?/ && $rawOpts{$opt});
Branch: 1 branch
BranchTrueFalseTotal
if $opt =~ /^_pp(_.+)?/ and $rawOpts{$opt} 0 667 667
Condition66%2/3
$opt =~ /^_pp(_.+)?/ and $rawOpts{$opt}
!ll&&!rl&&r
580870
MC/DC0%0/2
$opt =~ /^_pp(_.+)?/ and $rawOpts{$opt}
$opt =~ /^_pp(_.+)?/ $rawOpts{$opt}
Truth table66%2/3
A and B
A= $opt =~ /^_pp(_.+)?/B= $rawOpts{$opt}
ABresult
0X0
100
111
144 }
145 29 ▶ if (keys(%packHelperOpts))
Branch: 1 branch
BranchTrueFalseTotal
if (keys %packHelperOpts) 0 29 29
146 {
147 0 $packHelperOpts{verbose} = $rawOpts{v};
148 0 App::TestOnTap::PackInfo::handle
149 (
150 \%packHelperOpts,
151 $version,
152 $_argsPodName, $_argsPodInput,
153 $argsPodName, $argsPodInput,
154 $manualPodName, $manualPodInput
155 );
156 0 die("INTERNAL ERROR");
157 }
158  
159 # if any of the doc switches made, display the pod
160 #
161 29 ▶ pod2usage(-input => $manualPodInput, -exitval => 0, -verbose => 2, -noperldoc => 1) if $rawOpts{manual};
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"manual"} 0 29 29
162 29 ▶ pod2usage(-input => $argsPodInput, -exitval => 0, -verbose => 2, -noperldoc => 1) if $rawOpts{help};
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"help"} 0 29 29
163 29 ▶ pod2usage(-input => $argsPodInput, -exitval => 0, -verbose => 0) if $rawOpts{usage};
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"usage"} 0 29 29
164 29 ▶ pod2usage(-message => (slashify($0) . " version $version"), -exitval => 0, -verbose => 99, -sections => '_') if $rawOpts{version};
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"version"} 0 29 29
165  
166 # use the user skip or include filter for pruning the list of tests later
167 #
168 eval
169 29 {
170 29 ▶ if (defined($rawOpts{skip}) || defined($rawOpts{include}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rawOpts{"skip"} or defined $rawOpts{"include"}) 3 26 29
Condition100%3/3
defined $rawOpts{"skip"} or defined $rawOpts{"include"}
l!l&&r!l&&!r
2126
MC/DC100%2/2
defined $rawOpts{"skip"} or defined $rawOpts{"include"}
defined $rawOpts{"skip"} defined $rawOpts{"include"}
Truth table100%3/3
A or B
A= defined $rawOpts{"skip"}B= defined $rawOpts{"include"}
ABresult
1X1
011
000
171 {
172 3 ▶ die("The options --skip and --include are mutually exclusive\n") if (defined($rawOpts{skip}) && defined($rawOpts{include}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $rawOpts{"skip"} and defined $rawOpts{"include"} 1 2 3
Condition100%3/3
defined $rawOpts{"skip"} and defined $rawOpts{"include"}
!ll&&!rl&&r
111
MC/DC100%2/2
defined $rawOpts{"skip"} and defined $rawOpts{"include"}
defined $rawOpts{"skip"} defined $rawOpts{"include"}
Truth table100%3/3
A and B
A= defined $rawOpts{"skip"}B= defined $rawOpts{"include"}
ABresult
0X0
100
111
173 2 ▶ if ($rawOpts{skip})
Branch: 1 branch
BranchTrueFalseTotal
if ($rawOpts{'skip'}) { } 1 1 2
174 {
175 # try to compile the query first, to trigger any syntax problem now
176 #
177 1 Grep::Query->new($rawOpts{skip});
178
179 # since we later want to select *included* files,
180 # we nefariously reverse the expression given
181 #
182 1 $self->{include} = Grep::Query->new("NOT ( $rawOpts{skip} )");
183 }
184 else
185 {
186 1 $self->{include} = Grep::Query->new($rawOpts{include});
187 }
188 }
189 };
190 29 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 28 29
191 {
192 1 $! = 255;
193 1 die("Failure creating filter:\n $@");
194 }
195  
196 # make sure we have a valid jobs value
197 #
198 my $maxJobs = $ENV{_TESTONTAP_MAX_JOBS}
199 ? 0 + $ENV{_TESTONTAP_MAX_JOBS}
200 28 ▶ : $IS_WINDOWS
Branch: 2 branches
BranchTrueFalseTotal
$ENV{'_TESTONTAP_MAX_JOBS'} ? : 0 28 28
$App::TestOnTap::Args::IS_WINDOWS ? : 0 28 28
201 ? 60 # read about max being 64, leave room
202 : ~0; # max int, e.g. almost 'infinite'
203
204 28 ▶ if ($rawOpts{jobs} > $maxJobs)
Branch: 1 branch
BranchTrueFalseTotal
if ($rawOpts{"jobs"} > $maxJobs) 0 28 28
205 {
206 0 $rawOpts{jobs} = $maxJobs;
207 0 warn("WARNING: Maximum jobs restricted, resetting to '--jobs $maxJobs' \n");
208 }
209 28 ▶ pod2usage(-message => "Invalid -jobs value: '$rawOpts{jobs}'", -exitval => 255, -verbose => 0) if $rawOpts{jobs} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"jobs"} < 1 0 28 28
210 28 $self->{jobs} = $rawOpts{jobs};
211
212 # verify known order strategies
213 #
214 28 ▶ $self->{orderstrategy} = App::TestOnTap::OrderStrategy->new($rawOpts{order}) if $rawOpts{order};
Branch: 1 branch
BranchTrueFalseTotal
if $rawOpts{"order"} 4 24 28
215
216 # set up savedir, if given - or, if archive is given fall back to current dir
217 #
218 28 ▶ if (defined($rawOpts{savedirectory}) || $rawOpts{archive})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rawOpts{"savedirectory"} or $rawOpts{"archive"}) 2 26 28
Condition66%2/3
defined $rawOpts{"savedirectory"} or $rawOpts{"archive"}
l!l&&r!l&&!r
2026
MC/DC50%1/2
defined $rawOpts{"savedirectory"} or $rawOpts{"archive"}
defined $rawOpts{"savedirectory"} $rawOpts{"archive"}
Truth table66%2/3
A or B
A= defined $rawOpts{"savedirectory"}B= $rawOpts{"archive"}
ABresult
1X1
011
000
219 {
220 eval
221 2 {
222 2 ▶ $self->{savedirectory} = slashify(File::Spec->rel2abs($rawOpts{savedirectory} || '.'));
Condition50%1/2
$rawOpts{'savedirectory'} || '.'
l!l
20
MC/DC0%0/1
$rawOpts{'savedirectory'} || '.'
$rawOpts{'savedirectory'}
Truth table50%1/2
A
A= $rawOpts{'savedirectory'}
Aresult
11
00
223 2 ▶ die("The -savedirectory '$self->{savedirectory}' exists but is not a directory\n") if (-e $self->{savedirectory} && !-d $self->{savedirectory});
Branch: 1 branch
BranchTrueFalseTotal
if -e $self->{"savedirectory"} and not -d $self->{"savedirectory"} 0 2 2
Condition33%1/3
-e $self->{"savedirectory"} and not -d $self->{"savedirectory"}
!ll&&!rl&&r
020
MC/DC0%0/2
-e $self->{"savedirectory"} and not -d $self->{"savedirectory"}
-e $self->{"savedirectory"} not -d $self->{"savedirectory"}
Truth table33%1/3
A and not(B)
A= -e $self->{"savedirectory"}B= not -d $self->{"savedirectory"}
ABresult
0X0
100
111
224 2 ▶ if (!-e $self->{savedirectory})
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->{"savedirectory"}) 0 2 2
225 {
226 0 ▶ mkpath($self->{savedirectory}) or die("Failed to create -savedirectory '$self->{savedirectory}': $!\n");
Branch: 1 branch
BranchTrueFalseTotal
mkpath($self->{"savedirectory"}) or die qq[Failed to create -savedirectory '$self->{"savedirectory"}': $!\n] 0 0 0
227 }
228 };
229 2 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
230 {
231 0 $! = 255;
232 0 die("Failure setting up the save directory:\n $@");
233 }
234 }
235  
236 # make sure we have the suite root and that it exists as directory
237 #
238 eval
239 28 {
240 28 ▶ die("No suite root provided!\n") unless @argv;
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 0 28 28
241 28 $self->{suiteroot} = $self->__findSuiteRoot(shift(@argv));
242 };
243 28 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 28 28
244 {
245 0 $! = 255;
246 0 die("Failure getting suite root directory:\n $@");
247 }
248  
249 # we want a config in the suite root
250 #
251 eval
252 28 {
253 28 $self->{config} = App::TestOnTap::Config->new($self->{suiteroot}, $rawOpts{configuration}, $rawOpts{_ignore_dependencies});
254 };
255 28 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 27 28
256 {
257 1 $! = 255;
258 1 die("Failure handling config in '$self->{suiteroot}':\n $@");
259 }
260  
261 # set up the workdir manager
262 #
263 eval
264 27 {
265 27 $self->{workdirmgr} = App::TestOnTap::WorkDirManager->new($self, $rawOpts{workdirectory}, $self->{suiteroot});
266 };
267 27 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 27 27
268 {
269 0 $! = 255;
270 0 die("Failure setting up the working directory:\n $@");
271 };
272  
273 # final sanity checks
274 #
275 27 ▶ if ($self->{jobs} > 1 && !$self->{config}->hasParallelizableRule())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"jobs"} > 1 and not $self->{"config"}->hasParallelizableRule) 1 26 27
Condition100%3/3
$self->{"jobs"} > 1 and not $self->{"config"}->hasParallelizableRule
!ll&&!rl&&r
2511
MC/DC100%2/2
$self->{"jobs"} > 1 and not $self->{"config"}->hasParallelizableRule
$self->{"jobs"} > 1 not $self->{"config"}->hasParallelizableRule
Truth table100%3/3
A and not(B)
A= $self->{"jobs"} > 1B= not $self->{"config"}->hasParallelizableRule
ABresult
0X0
100
111
276 {
277 1 warn("WARNING: No 'parallelizable' rule found ('--jobs $self->{jobs}' has no effect); all tests will run serially!\n");
278 }
279  
280 # unless merge is explicitly set:
281 # * default to merge if the results are saved in any way (to force stderr to the tap files)
282 # * otherwise default to no merge
283 #
284 $self->{merge} =
285 defined($rawOpts{merge})
286 ? $rawOpts{merge}
287 27 ▶ : ($rawOpts{workdirectory} || $rawOpts{savedirectory} || $rawOpts{archive}) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $rawOpts{'merge'} ? : 0 27 27
$rawOpts{'workdirectory'} || $rawOpts{'savedirectory'} || $rawOpts{'archive'} ? : 2 25 27
Condition66%4/6
$rawOpts{"workdirectory"} or $rawOpts{"savedirectory"} or $rawOpts{"archive"}
l!l&&r!l&&!r
2025
$rawOpts{"workdirectory"} or $rawOpts{"savedirectory"}
l!l&&r!l&&!r
0225
MC/DC33%1/3
$rawOpts{"workdirectory"} or $rawOpts{"savedirectory"} or $rawOpts{"archive"}
$rawOpts{"workdirectory"} $rawOpts{"savedirectory"} $rawOpts{"archive"}
Truth table50%2/4
A or B or C
A= $rawOpts{"workdirectory"}B= $rawOpts{"savedirectory"}C= $rawOpts{"archive"}
ABCresult
1XX1
01X1
0011
0000
288  
289 # run preprocessing
290 #
291 27 $self->{preprocess} = App::TestOnTap::Preprocess->new($self->{config}->getPreprocessCmd(), $self, { %ENV }, \@argv);
292 }
293  
294 sub getFullArgv
295 {
296 25 ▶ my $self = shift;
Subroutine getFullArgv: called CC=1 SCAR=0.0
Pod undocumented
297
298 25 return $self->{fullargv};
299 }
300  
301 sub getArgv
302 {
303 48 ▶ my $self = shift;
Subroutine getArgv: called CC=1 SCAR=0.0
Pod undocumented
304  
305 48 return $self->{preprocess}->getArgv();
306 }
307  
308 sub getId
309 {
310 50 ▶ my $self = shift;
Subroutine getId: called CC=1 SCAR=0.0
Pod undocumented
311
312 50 return $self->{id};
313 }
314  
315 sub getJobs
316 {
317 79 ▶ my $self = shift;
Subroutine getJobs: called CC=1 SCAR=0.0
Pod undocumented
318
319 79 return $self->{jobs};
320 }
321  
322 sub getOrderStrategy
323 {
324 55 ▶ my $self = shift;
Subroutine getOrderStrategy: called CC=1 SCAR=0.0
Pod undocumented
325
326 55 return $self->{orderstrategy};
327 }
328  
329 sub getPreprocess
330 {
331 27 ▶ my $self = shift;
Subroutine getPreprocess: called CC=1 SCAR=0.0
Pod undocumented
332
333 27 return $self->{preprocess};
334 }
335  
336 sub getTimer
337 {
338 27 ▶ my $self = shift;
Subroutine getTimer: called CC=1 SCAR=0.0
Pod undocumented
339
340 27 return $self->{timer};
341 }
342  
343 sub getArchive
344 {
345 2 ▶ my $self = shift;
Subroutine getArchive: called CC=1 SCAR=0.0
Pod undocumented
346
347 2 return $self->{archive};
348 }
349  
350 sub getDefines
351 {
352 25 ▶ my $self = shift;
Subroutine getDefines: called CC=1 SCAR=0.0
Pod undocumented
353
354 25 return $self->{defines};
355 }
356  
357 sub getVerbose
358 {
359 27 ▶ my $self = shift;
Subroutine getVerbose: called CC=1 SCAR=0.0
Pod undocumented
360
361 27 return $self->{v};
362 }
363  
364 sub getMerge
365 {
366 27 ▶ my $self = shift;
Subroutine getMerge: called CC=1 SCAR=0.0
Pod undocumented
367
368 27 return $self->{merge};
369 }
370  
371 sub getSuiteRoot
372 {
373 127 ▶ my $self = shift;
Subroutine getSuiteRoot: called CC=1 SCAR=0.0
Pod undocumented
374
375 127 return $self->{suiteroot};
376 }
377  
378 sub getSaveDir
379 {
380 26 ▶ my $self = shift;
Subroutine getSaveDir: called CC=1 SCAR=0.0
Pod undocumented
381
382 26 return $self->{savedirectory};
383 }
384  
385 sub getWorkDirManager
386 {
387 365 ▶ my $self = shift;
Subroutine getWorkDirManager: called CC=1 SCAR=0.0
Pod undocumented
388
389 365 return $self->{workdirmgr};
390 }
391  
392 sub getConfig
393 {
394 364 ▶ my $self = shift;
Subroutine getConfig: called CC=1 SCAR=0.0
Pod undocumented
395
396 364 return $self->{config};
397 }
398  
399 sub useHarness
400 {
401 26 ▶ my $self = shift;
Subroutine useHarness: called CC=2 SCAR=7.1
Pod undocumented
402
403 26 ▶ return $self->{harness} && !$self->doDryRun();
Condition66%2/3
$self->{'harness'} && !$self->doDryRun
!ll&&!rl&&r
1025
MC/DC50%1/2
$self->{'harness'} && !$self->doDryRun
$self->{'harness'} !$self->doDryRun
Truth table66%2/3
A && not(B)
A= $self->{'harness'}B= !$self->doDryRun
ABresult
0X0
100
111
404 }
405  
406 sub doDryRun
407 {
408 31 ▶ my $self = shift;
Subroutine doDryRun: called CC=1 SCAR=0.0
Pod undocumented
409
410 31 return $self->{dryrun};
411 }
412  
413 sub include
414 {
415 26 ▶ my $self = shift;
Subroutine include: called CC=2 SCAR=6.9
Pod undocumented
416 26 my $tests = shift;
417
418 return
419 $self->{include}
420 26 ▶ ? [ $self->{include}->qgrep(@$tests) ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{'include'} ? : 2 24 26
421 : undef;
422 }
423  
424 # PRIVATE
425 #
426  
427 sub __findSuiteRoot
428 {
429 28 ▶ my $self = shift;
Subroutine __findSuiteRoot: called CC=15 SCAR=52.1
430 28 my $suiteroot = shift;
431  
432 28 ▶ if (-d $suiteroot)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $suiteroot) { } 28 0 28
433 {
434 28 $suiteroot = slashify(File::Spec->rel2abs($suiteroot));
435 }
436 else
437 {
438 0 ▶ die("Not a directory or zip archive: '$suiteroot'\n") unless $suiteroot =~ /\.zip$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $suiteroot =~ /\.zip$/i 0 0 0
439 0 my $zipfile = $suiteroot;
440 0 my $tmpdir = slashify(tempdir("testontap-XXXX", TMPDIR => 1, CLEANUP => 1));
441  
442 0 ▶ if (!-f $suiteroot)
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $suiteroot) 0 0 0
443 {
444 # maybe it's a url?
445 # need to dl it before unpacking
446 #
447 0 my $localzip = slashify("$tmpdir/local.zip");
448 0 ▶ print "Downloading '$suiteroot' => $localzip...\n" if $self->{v};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"v"} 0 0 0
449 0 my $ua = LWP::UserAgent->new();
450 0 $ua->ssl_opts(verify_hostname => 0);
451 0 my $response = $ua->get($suiteroot, ':content_file' => $localzip);
452 0 ▶ if ($response->is_error() || !-f $localzip)
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_error or not -f $localzip) 0 0 0
Condition0%0/3
$response->is_error or not -f $localzip
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->is_error or not -f $localzip
$response->is_error not -f $localzip
Truth table0%0/3
A or not(B)
A= $response->is_errorB= not -f $localzip
ABresult
1X1
011
000
453 {
454 0 my $rc = $response->code();
455 0 die("Treated '$suiteroot' as URL - failed to download : $rc\n");
456 }
457 0 $zipfile = $localzip;
458 }
459
460 0 ▶ print "Unpacking '$zipfile'...\n" if $self->{v};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"v"} 0 0 0
461 0 my $zipErr;
462 0 ▶ Archive::Zip::setErrorHandler(sub { $zipErr = $_[0]; chomp($zipErr) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
463 0 my $zip = Archive::Zip->new($zipfile);
464 0 ▶ die("Error when unpacking '$zipfile': $zipErr\n") if $zipErr;
Branch: 1 branch
BranchTrueFalseTotal
if $zipErr 0 0 0
465 0 my @memberNames = $zip->memberNames();
466 0 ▶ die("The zip archive '$suiteroot' is empty\n") unless @memberNames;
Branch: 1 branch
BranchTrueFalseTotal
unless @memberNames 0 0 0
467 0 my @rootEntries = grep(m#^[^/]+/?$#, @memberNames);
468 0 ▶ die("The zip archive '$suiteroot' has more than one root entry\n") if scalar(@rootEntries) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @rootEntries > 1 0 0 0
469 0 my $testSuiteDir = $rootEntries[0];
470 0 ▶ die("The zip archive '$suiteroot' must have a test suite directory as root entry\n") unless $testSuiteDir =~ m#/$#;
Branch: 1 branch
BranchTrueFalseTotal
unless $testSuiteDir =~ m[/$] 0 0 0
471 0 my $cfgFile = $testSuiteDir . App::TestOnTap::Config::getName();
472 0 ▶ die("The zip archive '$suiteroot' must have a '$cfgFile' entry\n") unless grep(/^\Q$cfgFile\E$/, @memberNames);
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^\Q$cfgFile\E$/, @memberNames 0 0 0
473 0 ▶ die("Failed to extract '$suiteroot': $!\n") unless $zip->extractTree('', $tmpdir) == AZ_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $zip->extractTree("", $tmpdir) == 0 0 0 0
474 0 $suiteroot = slashify(File::Spec->rel2abs("$tmpdir/$testSuiteDir"));
475 0 ▶ print "Unpacked '$suiteroot'\n" if $self->{v};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"v"} 0 0 0
476 }
477
478 28 return $suiteroot;
479 }
480  
481 19 1;
« blib/lib/App/TestOnTap/PackInfo.pm ↑ Summary blib/lib/App/TestOnTap/Util.pm »