| 1 | package Test2::Plugin::SRand; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 163 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 163 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 163 | our $VERSION = '1.302226'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 163 | ▶ | use Carp qw/carp/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 163 | ▶ | use Test2::API qw{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | context | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | test2_add_callback_post_load | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | test2_add_callback_exit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | test2_stack | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 163 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 163 | my $ADDED_HOOK = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 163 | my $SEED; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $FROM; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | sub seed { $SEED } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seed: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | sub from { $FROM } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 169 | ▶ | sub import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=10 SCAR=23.5
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 169 | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 169 | ▶ | carp "SRand loaded multiple times, re-seeding rand" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | if defined $SEED; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 169 | ▶ | if (@_ == 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ($SEED) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | $FROM = 'import arg'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ▶ | elsif (@_ == 2 and $_[0] eq 'seed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
@_ == 2 and $_[0] eq "seed"
MC/DC50%1/2
@_ == 2 and $_[0] eq "seed"
@_ == 2
$_[0] eq "seed"
Truth table66%2/3
A and B
A= @_ == 2B= $_[0] eq "seed"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $SEED = $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $FROM = 'import arg'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | elsif(exists $ENV{T2_RAND_SEED}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $SEED = $ENV{T2_RAND_SEED}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $FROM = 'environment variable'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 165 | my @ltime = localtime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Yes, this would be an awful seed if you actually wanted randomness. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # The idea here is that we want "random" behavior to be predictable | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # within a given day. This allows you to reproduce failures that may or | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # may not happen due to randomness. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 165 | $SEED = sprintf('%04d%02d%02d', 1900 + $ltime[5], 1 + $ltime[4], $ltime[3]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 165 | $FROM = 'local date'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 169 | ▶ | $SEED = 0 unless $SEED; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 169 | srand($SEED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 169 | ▶ | if ($ENV{HARNESS_IS_VERBOSE} || !$ENV{HARNESS_ACTIVE}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$ENV{"HARNESS_IS_VERBOSE"} or not $ENV{"HARNESS_ACTIVE"}
MC/DC50%1/2
$ENV{"HARNESS_IS_VERBOSE"} or not $ENV{"HARNESS_ACTIVE"}
$ENV{"HARNESS_IS_VERBOSE"}
not $ENV{"HARNESS_ACTIVE"}
Truth table66%2/3
A or not(B)
A= $ENV{"HARNESS_IS_VERBOSE"}B= not $ENV{"HARNESS_ACTIVE"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # If the harness is verbose then just display the message for all to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # see. It is nice info and they already asked for noisy output. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | test2_add_callback_post_load(sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | test2_stack()->top; # Ensure we have at least 1 hub. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | my ($hub) = test2_stack()->all; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | $hub->send( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | Test2::Event::Note->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__, 'SRAND']), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | message => "Seeded srand with seed '$SEED' from $FROM.", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | elsif (!$ADDED_HOOK++) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # The seed can be important for debugging, so if anything is wrong we | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # should output the seed message as a diagnostics message. This must be | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # done at the very end, even later than a hub hook. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | test2_add_callback_exit( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 117 | ▶ | sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=21.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 117 | my ($ctx, $real, $new) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 117 | ▶ | $ctx->diag("Seeded srand with seed '$SEED' from $FROM.") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$real or $new and $$new or not $ctx->hub->is_passing
$real or $new and $$new
$new and $$new
MC/DC0%0/4
$real or $new and $$new or not $ctx->hub->is_passing
$real
$new
$$new
not $ctx->hub->is_passing
Truth table16%1/6
A or B and C or not(D)
A= $realB= $newC= $$newD= not $ctx->hub->is_passing
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | if $real | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | || ($new && $$new) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | || !$ctx->hub->is_passing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 163 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 163 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||