Bio/Root/Test.pm

filter: Statementstmt 65.5% 122 / 186 Branchbran 42.8% 36 / 84 Conditioncond 25.0% 11 / 44 MC/DCmcdc 3.7% 1 / 27 Subroutinesub 80.0% 20 / 25 Podpod 100% 9 / 9 totaltotal 53.0% 199 / 375 CC 60 SCAR 33.1
CC
60
Cov
54%
_skip
65.2
_diag_found_warning
42.0
_canonical_got_warning
30.0
CRAP 27.3
« Bio/SeqFeature/PositionProxy.pm ↑ Summary Bio/Matrix/PSM/IO/transfac.pm »
1 package Bio::Root::Test;
2 209 $Bio::Root::Test::VERSION = '1.7.8';
3 209 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 209 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # According to Ovid, 'use base' can override signal handling, so use
7 # old-fashioned way. This should be a Test::Builder::Module subclass
8 # for consistency (as are any Test modules)
9 209 ▶use Test::Most;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 209 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 209 ▶use Test::Builder::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 209 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 209 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 209 our @ISA = qw(Test::Builder::Module);
16  
17 =head1 NAME
18  
19 Bio::Root::Test - common base for all BioPerl test scripts
20  
21 =head1 SYNOPSIS
22  
23 use lib '.'; # (for core package tests only)
24 use Bio::Root::Test;
25  
26 test_begin(-tests => 20,
27 -requires_modules => [qw(IO::String XML::Parser)],
28 -requires_networking => 1);
29  
30 my $do_network_tests = test_network();
31 my $output_debugging = test_debug();
32  
33 # Bio::Root::Test rewraps Test::Most, so one can carry out tests with
34 # Test::More, Test::Exception, Test::Warn, Test::Deep, Test::Diff syntax
35  
36 SKIP: {
37 # these tests need version 2.6 of Optional::Module to work
38 test_skip(-tests => 10, -requires_module => 'Optional::Module 2.6');
39 use_ok('Optional::Module');
40  
41 # 9 other optional tests that need Optional::Module
42 }
43  
44 SKIP: {
45 test_skip(-tests => 10, -requires_networking => 1);
46  
47 # 10 optional tests that require internet access (only makes sense in the
48 # context of a script that doesn't use -requires_networking in the call to
49 # &test_begin)
50 }
51  
52 # in unix terms, we want to test with a file t/data/input_file.txt
53 my $input_file = test_input_file('input_file.txt');
54  
55 # we want the name of a file we can write to, that will be automatically
56 # deleted when the test script finishes
57 my $output_file = test_output_file();
58  
59 # we want the name of a directory we can store files in, that will be
60 # automatically deleted when the test script finishes
61 my $output_dir = test_output_dir();
62  
63 =head1 DESCRIPTION
64  
65 This provides a common base for all BioPerl test scripts. It safely handles the
66 loading of Test::Most, itself a simple wrapper around several highly used test
67 modules: Test::More, Test::Exception, Test::Warn, Test::Deep, and Test::Diff. It
68 also presents an interface to common needs such as skipping all tests if
69 required modules aren't present or if network tests haven't been enabled. See
70 test_begin().
71  
72 In the same way, it allows you to skip just a subset of tests for those same
73 reasons, in addition to requiring certain executables and environment variables.
74 See test_skip().
75  
76 It also has two further methods that let you decide if network tests should be
77 run, and if debugging information should be printed. See test_network() and
78 test_debug().
79  
80 Finally, it presents a consistent way of getting the path to input and output
81 files. See test_input_file(), test_output_file() and test_output_dir().
82  
83 =head1 AUTHOR Sendu Bala
84  
85 Chris Fields
86  
87 =cut
88  
89 # TODO: Evil magic ahead; can we clean this up?
90  
91 {
92 209 my $Tester = Test::Builder->new;
93  
94 209 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 0 ▶ sub Test::Warn::_canonical_got_warning {
Subroutine _canonical_got_warning: not called CC=5 SCAR=34.0
97 0 my ( $called_from, $msg ) = @_;
98 0 ▶ my $warn_kind
Branch: 2 branches
BranchTrueFalseTotal
$called_from eq 'Carp' ? : 0 0 0
$called_from =~ /Bio::/ ? : 0 0 0
99 = $called_from eq 'Carp'
100 ? 'carped'
101 : ( $called_from =~ /Bio::/ ? 'Bioperl' : 'warn' );
102  
103 0 my $warning;
104 0 ▶ if ( $warn_kind eq 'Bioperl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warn_kind eq 'Bioperl') { } 0 0 0
105 0 ($warning)
106 = $msg
107 =~ /\n--------------------- WARNING ---------------------\nMSG: (.+)\n---------------------------------------------------\n$/m;
108 0 ▶ $warning ||= $msg; # shouldn't ever happen
Condition0%0/3
$warning ||= $msg
l!l&&r!l&&!r
000
MC/DC0%0/2
$warning ||= $msg
$warning $msg
Truth table0%0/3
A ||= B
A= $warningB= $msg
ABresult
1X1
011
000
109 } else {
110 0 my @warning_stack = split /\n/, $msg; # some stuff of uplevel is included
111 0 $warning = $warning_stack[0];
112 }
113  
114 0 return { $warn_kind => $warning }; # return only the real message
115 }
116  
117 0 ▶ sub Test::Warn::_diag_found_warning {
Subroutine _diag_found_warning: not called CC=6 SCAR=37.4
118 0 my @warns = @_;
119 0 foreach my $warn (@warns) {
120 0 ▶ if ( ref($warn) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $warn eq 'HASH') { } 0 0 0
121 0 ${$warn}{carped}
122 0 ▶ ? $Tester->diag("found carped warning: ${$warn}{carped}")
Branch: 1 branch
BranchTrueFalseTotal
do { $warn }->{'Bioperl'} ? : 0 0 0
123 : (
124 0 ▶ ${$warn}{Bioperl} ? $Tester->diag(
Branch: 1 branch
BranchTrueFalseTotal
do { $warn }->{'carped'} ? : 0 0 0
125 0 "found Bioperl warning: ${$warn}{Bioperl}")
126 0 : $Tester->diag("found warning: ${$warn}{warn}")
127 );
128 } else {
129 0 $Tester->diag("found warning: $warn");
130 }
131 }
132 0 ▶ $Tester->diag("didn't find a warning") unless @warns;
Branch: 1 branch
BranchTrueFalseTotal
unless @warns 0 0 0
133 }
134  
135 0 ▶ sub Test::Warn::_cmp_got_to_exp_warning {
Subroutine _cmp_got_to_exp_warning: not called CC=4 SCAR=30.0
136 0 my ( $got_kind, $got_msg ) = %{ shift() };
137 0 my ( $exp_kind, $exp_msg ) = %{ shift() };
138 0 ▶ return 0 if ( $got_kind eq 'warn' ) && ( $exp_kind eq 'carped' );
Branch: 1 branch
BranchTrueFalseTotal
if $got_kind eq "warn" and $exp_kind eq "carped" 0 0 0
Condition0%0/3
$got_kind eq "warn" and $exp_kind eq "carped"
!ll&&!rl&&r
000
MC/DC0%0/2
$got_kind eq "warn" and $exp_kind eq "carped"
$got_kind eq "warn" $exp_kind eq "carped"
Truth table0%0/3
A and B
A= $got_kind eq "warn"B= $exp_kind eq "carped"
ABresult
0X0
100
111
139  
140 0 my $cmp;
141 0 ▶ if ( $got_kind eq 'Bioperl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_kind eq 'Bioperl') { } 0 0 0
142 0 $cmp = $got_msg =~ /^\Q$exp_msg\E$/;
143 } else {
144 0 $cmp = $got_msg =~ /^\Q$exp_msg\E at \S+ line \d+\.?$/;
145 }
146  
147 0 return $cmp;
148 }
149 }
150  
151 209 our @EXPORT = (
152 @Test::Most::EXPORT,
153  
154 #@Bio::Root::Test::Warn::EXPORT,
155 # Test::Warn method wrappers
156  
157 # BioPerl-specific
158 qw(
159 test_begin
160 test_skip
161 test_output_file
162 test_output_dir
163 test_input_file
164 test_network
165 test_email
166 test_debug
167 float_is
168 )
169 );
170  
171 209 our $GLOBAL_FRAMEWORK = 'Test::Most';
172 209 our @TEMP_FILES;
173  
174 =head2 test_begin
175  
176 Title : test_begin
177 Usage : test_begin(-tests => 20);
178 Function: Begin your test script, setting up the plan (skip all tests, or run
179 them all)
180 Returns : True if tests should be run.
181 Args : -tests => int (REQUIRED, the number of tests that will
182 be run)
183 -requires_modules => [] (array ref of module names that are
184 required; if any don't load, all tests
185 will be skipped. To specify a required
186 version of a module, include the version
187 number after the module name, separated
188 by a space)
189 -requires_module => str (as above, but for just one module)
190 -requires_networking => 1|0 (default 0, if true all tests will be
191 skipped if network tests haven't been
192 enabled in Build.PL)
193 -requires_email => 1 (if true the desired number of tests will
194 be skipped if either network tests
195 haven't been enabled in Build.PL or an
196 email hasn't been entered)
197 -excludes_os => str (default none, if OS supplied, all tests
198 will skip if running on that OS (eg.
199 'mswin'))
200 -framework => str (default 'Test::Most', the Test module
201 to load. NB: experimental, avoid using)
202  
203 Note, supplying -tests => 0 is possible, allowing you to skip all
204 tests in the case that a test script is testing deprecated modules
205 that have yet to be removed from the distribution
206  
207 =cut
208  
209 208 ▶sub test_begin {
Subroutine test_begin: called CC=6 SCAR=20.8
Pod documented
210 208 my ( $skip_all, $tests, $framework ) = _skip(@_);
211 208 $GLOBAL_FRAMEWORK = $framework;
212  
213 208 ▶ if ( $framework eq 'Test::Most' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($framework eq 'Test::Most') { } 208 0 208
214  
215 # ideally we'd delay loading Test::Most until this point, but see BEGIN
216 # block
217  
218 208 ▶ if ($skip_all) {
Branch: 3 branches
BranchTrueFalseTotal
if ($skip_all) { } 8 200 208
elsif (defined $tests and $tests == 0) { } 0 200 200
elsif ($tests) { } 200 0 200
219 8 eval "plan skip_all => '$skip_all';";
220 ▶ } elsif ( defined $tests && $tests == 0 ) {
Condition33%1/3
defined $tests and $tests == 0
!ll&&!rl&&r
02000
MC/DC0%0/2
defined $tests and $tests == 0
defined $tests $tests == 0
Truth table33%1/3
A and B
A= defined $testsB= $tests == 0
ABresult
0X0
100
111
221 eval
222 0 "plan skip_all => 'These modules are now probably deprecated';";
223 } elsif ($tests) {
224 200 eval "plan tests => $tests;";
225 }
226  
227 200 return 1;
228 }
229  
230 # go ahead and add support for other frameworks here
231 else {
232 0 die "Only Test::Most is supported at the current time\n";
233 }
234  
235 0 return 0;
236 }
237  
238 =head2 test_skip
239  
240 Title : test_skip
241 Usage : SKIP: {
242 test_skip(-tests => 10,
243 -requires_module => 'Optional::Module 2.01');
244 # 10 tests that need v2.01 of Optional::Module
245 }
246 Function: Skip a subset of tests for one of several common reasons: missing one
247 or more optional modules, network tests haven't been enabled, a
248 required binary isn't present, or an environmental variable isn't set
249 Returns : n/a
250 Args : -tests => int (REQUIRED, the number of tests that are
251 to be skipped in the event one of the
252 following options isn't satisfied)
253 -requires_modules => [] (array ref of module names that are
254 required; if any don't load, the desired
255 number of tests will be skipped. To
256 specify a required version of a module,
257 include the version number after the
258 module name, separated by a space)
259 -requires_module => str (as above, but for just one module)
260 -requires_executable => Bio::Tools::Run::WrapperBase instance
261 (checks WrapperBase::executable for the
262 presence of a binary, skips if absent)
263 -requires_env => str (checks %ENV for a specific env. variable,
264 skips if absent)
265 -excludes_os => str (default none, if OS supplied, desired num
266 of tests will skip if running on that OS
267 (eg. 'mswin'))
268 -requires_networking => 1 (if true the desired number of tests will
269 be skipped if network tests haven't been
270 enabled in Build.PL)
271 -requires_email => 1 (if true the desired number of tests will
272 be skipped if either network tests
273 haven't been enabled in Build.PL or an
274 email hasn't been entered)
275  
276 =cut
277  
278 20 ▶sub test_skip {
Subroutine test_skip: called CC=4 SCAR=14.5
Pod documented
279 20 my ( $skip, $tests, $framework ) = _skip(@_);
280 20 ▶ $tests || die "-tests must be a number greater than 0";
Branch: 1 branch
BranchTrueFalseTotal
$tests or die "-tests must be a number greater than 0" 20 0 20
281  
282 20 ▶ if ( $framework eq 'Test::Most' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($framework eq 'Test::Most') { } 20 0 20
283 20 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 8 12 20
284 8 eval "skip('$skip', $tests);";
285 }
286 }
287  
288 # go ahead and add support for other frameworks here
289 else {
290 0 die "Only Test::Most is supported at the current time\n";
291 }
292 }
293  
294 =head2 test_output_file
295  
296 Title : test_output_file
297 Usage : my $output_file = test_output_file();
298 Function: Get the full path of a file suitable for writing to.
299 When your test script ends, the file will be automatically deleted.
300 Returns : string (file path)
301 Args : none
302  
303 =cut
304  
305 222 ▶sub test_output_file {
Subroutine test_output_file: called CC=2 SCAR=7.0
Pod documented
306 222 ▶ die "test_output_file takes no args\n" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 222 222
307  
308 # RT 48813
309 222 my $tmp = File::Temp->new();
310 222 push( @TEMP_FILES, $tmp );
311 222 close($tmp); # Windows needs this
312 222 return $tmp->filename;
313 }
314  
315 =head2 test_output_dir
316  
317 Title : test_output_dir
318 Usage : my $output_dir = test_output_dir();
319 Function: Get the full path of a directory suitable for storing temporary files
320 in.
321 When your test script ends, the directory and its contents will be
322 automatically deleted.
323 Returns : string (path)
324 Args : none
325  
326 =cut
327  
328 3 ▶sub test_output_dir {
Subroutine test_output_dir: called CC=2 SCAR=7.2
Pod documented
329 3 ▶ die "test_output_dir takes no args\n" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
330  
331 3 return tempdir( CLEANUP => 1 );
332 }
333  
334 =head2 test_input_file
335  
336 Title : test_input_file
337 Usage : my $input_file = test_input_file();
338 Function: Get the path of a desired input file stored in the standard location
339 (currently t/data), but correct for all platforms.
340 Returns : string (file path)
341 Args : list of strings (ie. at least the input filename, preceded by the
342 names of any subdirectories within t/data)
343 eg. for the file t/data/in.file pass 'in.file', for the file
344 t/data/subdir/in.file, pass ('subdir', 'in.file')
345  
346 =cut
347  
348 675 ▶sub test_input_file {
Subroutine test_input_file: called CC=1 SCAR=0.0
Pod documented
349 675 return File::Spec->catfile( 't', 'data', @_ );
350 }
351  
352 =head2 test_network
353  
354 Title : test_network
355 Usage : my $do_network_tests = test_network();
356 Function: Ask if network tests should be run.
357 Returns : boolean
358 Args : none
359  
360 =cut
361  
362 5 ▶sub test_network {
Subroutine test_network: called CC=4 SCAR=14.8
Pod documented
363 5 ▶ if ($ENV{AUTHOR_TESTING} || $ENV{RELEASE_TESTING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'AUTHOR_TESTING'} or $ENV{'RELEASE_TESTING'}) { } 0 5 5
Condition33%1/3
$ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"}
l!l&&r!l&&!r
005
MC/DC0%0/2
$ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"}
$ENV{"AUTHOR_TESTING"} $ENV{"RELEASE_TESTING"}
Truth table33%1/3
A or B
A= $ENV{"AUTHOR_TESTING"}B= $ENV{"RELEASE_TESTING"}
ABresult
1X1
011
000
364 0 return 1;
365 } else {
366 5 my $run_network_tests = 1;
367  
368 ## Test::RequiresInternet calls exit. We monkey patch it to
369 ## use die instead which allow us to catch it in an eval.
370 ## However, better solutions would be to have it call
371 ## 'Test::More::plan skip_all' and have this done only within
372 ## a subtest instead of a SKIP. Even better would be to have
373 ## this done upstream and have the test units call it
374 ## directly.
375 5 require Test::RequiresInternet;
376 5 my $original_skip_all = *Test::RequiresInternet::skip_all;
377 {
378 209 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
379 0 ▶ *Test::RequiresInternet::skip_all = sub { die @_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
380 }
381 eval {
382 5 Test::RequiresInternet->import();
383 5 1;
384 5 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { "Test::RequiresInternet"->import; 1 } } or do { $run_network_tests = 0 } 5 0 5
385 0 $run_network_tests = 0;
386 };
387 5 *Test::RequiresInternet::skip_all = $original_skip_all;
388  
389 5 return $run_network_tests;
390 }
391 }
392  
393 =head2 test_email
394  
395 Title : test_email
396 Usage : my $do_network_tests = test_email();
397 Function: Ask if email address provided
398 Returns : boolean
399 Args : none
400  
401 =cut
402  
403 0 ▶sub test_email {
Subroutine test_email: not called CC=3 SCAR=24.8
Pod documented
404 0 require Module::Build;
405 0 my $build = Module::Build->current();
406  
407 # this should not be settable unless the network tests work
408 return
409 $build->notes('email')
410 || $ENV{AUTHOR_TESTING}
411 0 ▶ || $ENV{RELEASE_TESTING};
Condition0%0/6
$build->notes('email') || $ENV{'AUTHOR_TESTING'} || $ENV{'RELEASE_TESTING'}
l!l&&r!l&&!r
000
$build->notes("email") or $ENV{"AUTHOR_TESTING"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$build->notes('email') || $ENV{'AUTHOR_TESTING'} || $ENV{'RELEASE_TESTING'}
$build->notes("email") $ENV{"AUTHOR_TESTING"} $ENV{'RELEASE_TESTING'}
Truth table0%0/4
A or B || C
A= $build->notes("email")B= $ENV{"AUTHOR_TESTING"}C= $ENV{'RELEASE_TESTING'}
ABCresult
1XX1
01X1
0011
0000
412 }
413  
414 =head2 test_debug
415  
416 Title : test_debug
417 Usage : my $output_debugging = test_debug();
418 Function: Ask if debugging information should be output.
419 Returns : boolean
420 Args : none
421  
422 =cut
423  
424 77 ▶sub test_debug {
Subroutine test_debug: called CC=2 SCAR=7.6
Pod documented
425 77 ▶ return $ENV{'BIOPERLDEBUG'} || 0;
Condition50%1/2
$ENV{'BIOPERLDEBUG'} || 0
l!l
077
MC/DC0%0/1
$ENV{'BIOPERLDEBUG'} || 0
$ENV{'BIOPERLDEBUG'}
Truth table50%1/2
A
A= $ENV{'BIOPERLDEBUG'}
Aresult
11
00
426 }
427  
428 =head2 float_is
429  
430 Title : float_is
431 Usage : float_is($val1, $val2);
432 Function: test two floating point values for equality
433 Returns : Boolean based on test (can use in combination with diag)
434 Args : two scalar values (floating point numbers) (required via prototype)
435 test message (optional)
436  
437 =cut
438  
439 84 ▶sub float_is ($$;$) {
Subroutine float_is: called CC=3 SCAR=11.0
Pod documented
440 84 my ( $val1, $val2, $message ) = @_;
441  
442 # catch any potential undefined values and directly compare
443 84 ▶ if ( ! defined $val1 || ! defined $val2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val1 && defined $val2) { } 4 80 84
Condition66%2/3
defined $val1 && defined $val2
!ll&&!rl&&r
4080
MC/DC50%1/2
defined $val1 && defined $val2
defined $val1 defined $val2
Truth table66%2/3
A && B
A= defined $val1B= defined $val2
ABresult
0X0
100
111
444 4 is( $val1, $val2, $message );
445 } else {
446 80 is( sprintf( "%g", $val1 ), sprintf( "%g", $val2 ), $message );
447 }
448 }
449  
450 =head2 _skip
451  
452 Decide if should skip and generate skip message
453 =cut
454  
455 228 ▶sub _skip {
Subroutine _skip: called CC=24 SCAR=41.8
456 228 my %args = @_;
457  
458 # handle input strictly
459 228 my $tests = $args{'-tests'};
460  
461 #(defined $tests && $tests =~ /^\d+$/) || die "-tests must be supplied and be an int\n";
462 228 delete $args{'-tests'};
463  
464 228 my $req_mods = $args{'-requires_modules'};
465 228 delete $args{'-requires_modules'};
466 228 my @req_mods;
467 228 ▶ if ($req_mods) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_mods) 31 197 228
468 31 ▶ ref($req_mods) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $req_mods eq "ARRAY" or die "-requires_modules takes an array ref\n" 31 0 31
469 || die "-requires_modules takes an array ref\n";
470 31 @req_mods = @{$req_mods};
471 }
472 228 my $req_mod = $args{'-requires_module'};
473 228 delete $args{'-requires_module'};
474 228 ▶ if ($req_mod) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_mod) 36 192 228
475 36 ▶ ref($req_mod) && die "-requires_module takes a string\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $req_mod and die "-requires_module takes a string\n" 0 36 36
476 36 push( @req_mods, $req_mod );
477 }
478  
479 228 my $req_net = $args{'-requires_networking'};
480 228 delete $args{'-requires_networking'};
481  
482 228 my $req_email = $args{'-requires_email'};
483 228 delete $args{'-requires_email'};
484  
485 228 my $req_env = $args{'-requires_env'};
486 228 delete $args{'-requires_env'};
487  
488 # strip any leading $ in case someone passes $FOO instead of 'FOO'
489 228 ▶ $req_env =~ s{^\$}{} if $req_env;
Branch: 1 branch
BranchTrueFalseTotal
if $req_env 0 228 228
490  
491 228 my $req_exe = $args{'-requires_executable'};
492 228 delete $args{'-requires_executable'};
493  
494 228 ▶ if ($req_exe
Branch: 1 branch
BranchTrueFalseTotal
if ($req_exe and not ref $req_exe && $req_exe->isa("Bio::Tools::Run::WrapperBase")) 0 228 228
Condition16%1/6
$req_exe and not ref $req_exe && $req_exe->isa("Bio::Tools::Run::WrapperBase")
!ll&&!rl&&r
22800
ref $req_exe && $req_exe->isa('Bio::Tools::Run::WrapperBase')
!ll&&!rl&&r
000
MC/DC0%0/3
$req_exe and not ref $req_exe && $req_exe->isa("Bio::Tools::Run::WrapperBase")
$req_exe ref $req_exe $req_exe->isa('Bio::Tools::Run::WrapperBase')
Truth table25%1/4
A and not(B && C)
A= $req_exeB= ref $req_exeC= $req_exe->isa('Bio::Tools::Run::WrapperBase')
ABCresult
0XX0
1110
10X1
1101
495 && ( ! ref($req_exe)
496 || ! $req_exe->isa('Bio::Tools::Run::WrapperBase') )
497 ) {
498 0 die
499 "-requires_exe takes an argument of type Bio::Tools::Run::WrapperBase";
500 }
501  
502 228 my $os = $args{'-excludes_os'};
503 228 delete $args{'-excludes_os'};
504  
505 228 ▶ my $framework = $args{'-framework'} || $GLOBAL_FRAMEWORK;
Condition33%1/3
$args{'-framework'} || $GLOBAL_FRAMEWORK
l!l&&r!l&&!r
02280
MC/DC0%0/2
$args{'-framework'} || $GLOBAL_FRAMEWORK
$args{'-framework'} $GLOBAL_FRAMEWORK
Truth table33%1/3
A || B
A= $args{'-framework'}B= $GLOBAL_FRAMEWORK
ABresult
1X1
011
000
506 228 delete $args{'-framework'};
507  
508 # catch user mistakes
509 228 ▶ while ( my ( $key, $val ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 228 228
510 0 die
511 "unknown argument '$key' supplied, did you mistake 'required...' for 'requires...'?\n";
512 }
513  
514 # test user requirements and return
515 228 ▶ if ($os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os) 0 228 228
516 0 ▶ if ( $^O =~ /$os/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /$os/i) 0 0 0
517 0 return ( 'Not compatible with your Operating System',
518 $tests, $framework );
519 }
520 }
521  
522 228 foreach my $mod (@req_mods) {
523 82 my $skip = _check_module($mod);
524 82 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 16 66 82
525 16 return ( $skip, $tests, $framework );
526 }
527 }
528  
529 212 ▶ if ( $req_net && ! test_network() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_net and not test_network()) 0 212 212
Condition66%2/3
$req_net and not test_network()
!ll&&!rl&&r
20750
MC/DC0%0/2
$req_net and not test_network()
$req_net not test_network()
Truth table66%2/3
A and not(B)
A= $req_netB= not test_network()
ABresult
0X0
100
111
530 0 return ( 'Network tests have not been requested', $tests,
531 $framework );
532 }
533  
534 212 ▶ if ( $req_email && ! test_email() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_email and not test_email()) 0 212 212
Condition33%1/3
$req_email and not test_email()
!ll&&!rl&&r
21200
MC/DC0%0/2
$req_email and not test_email()
$req_email not test_email()
Truth table33%1/3
A and not(B)
A= $req_emailB= not test_email()
ABresult
0X0
100
111
535 0 return ( 'Valid email not provided; required for tests',
536 $tests, $framework );
537 }
538  
539 212 ▶ if ($req_exe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_exe) 0 212 212
540 0 my $eval = eval { $req_exe->executable };
541 0 ▶ if ( $@ or not defined $eval ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $eval) 0 0 0
Condition0%0/3
$@ or not defined $eval
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not defined $eval
$@ not defined $eval
Truth table0%0/3
A or not(B)
A= $@B= not defined $eval
ABresult
1X1
011
000
542 0 my $msg
543 = 'Required executable for '
544 . ref($req_exe)
545 . ' is not present';
546 0 diag($msg);
547 0 return ( $msg, $tests, $framework );
548 }
549 }
550  
551 212 ▶ if ( $req_env && ! exists $ENV{$req_env} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_env and not exists $ENV{$req_env}) 0 212 212
Condition33%1/3
$req_env and not exists $ENV{$req_env}
!ll&&!rl&&r
21200
MC/DC0%0/2
$req_env and not exists $ENV{$req_env}
$req_env not exists $ENV{$req_env}
Truth table33%1/3
A and not(B)
A= $req_envB= not exists $ENV{$req_env}
ABresult
0X0
100
111
552 0 my $msg
553 = 'Required environment variable $' . $req_env . ' is not set';
554 0 diag($msg);
555 0 return ( $msg, $tests, $framework );
556 }
557  
558 212 return ( '', $tests, $framework );
559 }
560  
561 =head2 _check_module
562  
563 =cut
564  
565 82 ▶sub _check_module {
Subroutine _check_module: called CC=7 SCAR=25.7
566 82 my $mod = shift;
567  
568 82 my $desired_version;
569 82 ▶ if ( $mod =~ /(\S+)\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /(\S+)\s+(\S+)/) 0 82 82
570 0 $mod = $1;
571 0 $desired_version = $2;
572 }
573  
574 82 eval "require $mod;";
575  
576 82 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 16 66 82
elsif ($desired_version) { } 0 66 66
577 16 ▶ if ( $@ =~ /Can't locate/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /Can't locate/) { } 16 0 16
578 return
579 16 "The optional module $mod (or dependencies thereof) was not installed";
580 } else {
581 return
582 0 "The optional module $mod generated the following error: \n$@";
583 }
584 } elsif ($desired_version) {
585 209 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
586 0 ▶ unless ( defined ${"${mod}::VERSION"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined ${"${mod}::VERSION";}) { } 0 0 0
if (do { ${"${mod}::VERSION";} < $desired_version }) 0 0 0
587 return
588 0 "The optional module $mod didn't have a version, but we want v$desired_version";
589 0 } elsif ( ${"${mod}::VERSION"} < $desired_version ) {
590 return
591 0 "The optional module $mod was out of date (wanted v$desired_version)";
592 }
593 }
594  
595 66 return;
596 }
597  
598 209 1;
« Bio/SeqFeature/PositionProxy.pm ↑ Summary Bio/Matrix/PSM/IO/transfac.pm »