| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 47 | 0 | ▶ | return $tb->history->test_start ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||
| 50 | 8 | ▶ | return defined $tb->has_plan || $tb->summary; | ||||||||||||||||||
|
Condition100%3/3
defined $tb->has_plan || $tb->summary
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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 59 | 0 | _display_seed($tb); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 8 | 1; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||