blib/lib/Test/Random.pm

filter: Statementstmt 90.9% 30 / 33 Branchbran 58.3% 7 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 86.2% 50 / 58 CC 7 SCAR 9.4
CC
7
Cov
83%
_test_started
4.8
_test_was_successful
2.1
END
2.1
CRAP 2.5
↑ Summary
1 package Test::Random;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION = '20130427';
8  
9 8 ▶my $Seed = defined $ENV{TEST_RANDOM_SEED} ? $ENV{TEST_RANDOM_SEED} : _get_seed();
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'TEST_RANDOM_SEED'} ? : 2 6 8
10  
11 # If something else calls srand() we're in trouble
12 8 srand $Seed;
13  
14 6 ▶sub _get_seed {
Subroutine _get_seed: called CC=1 SCAR=0.0
15 # Get a random number from 0 to the biggest integer Perl can handle
16 6 my $intbits = $Config{ivsize} * 8;
17 6 my $maxint = 2**($intbits-1);
18  
19 6 return rand($maxint);
20 }
21  
22 5 ▶sub _display_seed {
Subroutine _display_seed: called CC=2 SCAR=6.9
23 5 my $tb = shift;
24  
25 5 my $msg = sprintf "TEST_RANDOM_SEED=%d", $Seed;
26 5 my $ok = _test_was_successful($tb);
27 5 ▶ $ok ? $tb->note($msg) : $tb->diag($msg);
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 2 3 5
28  
29 5 return;
30 }
31  
32 5 ▶sub _test_was_successful {
Subroutine _test_was_successful: called CC=2 SCAR=7.6
33 5 my $tb = shift;
34  
35 5 ▶ if( $tb->can("history") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tb->can('history')) { } 0 5 5
36 0 return $tb->history->test_was_successful;
37 }
38 else {
39 5 return $tb->is_passing;
40 }
41 }
42  
43 8 ▶sub _test_started {
Subroutine _test_started: called CC=4 SCAR=15.6
44 8 my $tb = shift;
45  
46 8 ▶ if( $tb->can("history") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tb->can('history')) { } 0 8 8
47 0 ▶ return $tb->history->test_start ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$tb->history->test_start ? : 0 0 0
48 }
49 else {
50 8 ▶ return defined $tb->has_plan || $tb->summary;
Condition100%3/3
defined $tb->has_plan || $tb->summary
l!l&&r!l&&!r
413
MC/DC100%2/2
defined $tb->has_plan || $tb->summary
defined $tb->has_plan $tb->summary
Truth table100%3/3
A || B
A= defined $tb->has_planB= $tb->summary
ABresult
1X1
011
000
51 }
52 }
53  
54 2 ▶END {
Subroutine END: called CC=2 SCAR=7.6
55 2 require Test::Builder;
56 2 my $tb = Test::Builder->new;
57  
58 2 ▶ if( _test_started($tb) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_test_started($tb)) 0 2 2
59 0 _display_seed($tb);
60 }
61 }
62  
63 8 1;
64  
65 __END__
↑ Summary