line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Random; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
3697
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
219
|
|
4
|
6
|
|
|
6
|
|
43
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
183
|
|
5
|
6
|
|
|
6
|
|
30
|
use Config; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
2378
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '20130427'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $Seed = defined $ENV{TEST_RANDOM_SEED} ? $ENV{TEST_RANDOM_SEED} : _get_seed(); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# If something else calls srand() we're in trouble |
12
|
|
|
|
|
|
|
srand $Seed; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _get_seed { |
15
|
|
|
|
|
|
|
# Get a random number from 0 to the biggest integer Perl can handle |
16
|
6
|
|
|
6
|
|
5511
|
my $intbits = $Config{ivsize} * 8; |
17
|
6
|
|
|
|
|
23511
|
my $maxint = 2**($intbits-1); |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
|
|
231
|
return rand($maxint); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _display_seed { |
23
|
5
|
|
|
5
|
|
11
|
my $tb = shift; |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
31
|
my $msg = sprintf "TEST_RANDOM_SEED=%d", $Seed; |
26
|
5
|
|
|
|
|
20
|
my $ok = _test_was_successful($tb); |
27
|
5
|
100
|
|
|
|
56
|
$ok ? $tb->note($msg) : $tb->diag($msg); |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
339
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _test_was_successful { |
33
|
5
|
|
|
5
|
|
11
|
my $tb = shift; |
34
|
|
|
|
|
|
|
|
35
|
5
|
50
|
|
|
|
29
|
if( $tb->can("history") ) { |
36
|
0
|
|
|
|
|
0
|
return $tb->history->test_was_successful; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
5
|
|
|
|
|
24
|
return $tb->is_passing; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _test_started { |
44
|
6
|
|
|
6
|
|
16
|
my $tb = shift; |
45
|
|
|
|
|
|
|
|
46
|
6
|
50
|
|
|
|
67
|
if( $tb->can("history") ) { |
47
|
0
|
0
|
|
|
|
0
|
return $tb->history->test_start ? 1 : 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
6
|
|
100
|
|
|
30
|
return defined $tb->has_plan || $tb->summary; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
END { |
55
|
|
|
|
|
|
|
require Test::Builder; |
56
|
|
|
|
|
|
|
my $tb = Test::Builder->new; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if( _test_started($tb) ) { |
59
|
|
|
|
|
|
|
_display_seed($tb); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |