| 1 | package CHI::Test::Util; | ||||||||||||||||||||||||||||||||
| 2 | 19 | $CHI::Test::Util::VERSION = '0.60'; | |||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use Date::Parse; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 19 | our @EXPORT_OK = | |||||||||||||||||||||||||||||||
| 11 | qw(activate_test_logger is_between cmp_bool random_string skip_until); | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | sub activate_test_logger { | ||||||||||||||||||||||||||||||||
| 14 | 33 | ▶ | my $log = Log::Any->get_logger( category => 'CHI' ); | ||||||||||||||||||||||||||||||
|
Subroutine
activate_test_logger: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 15 | 33 | $log->clear(); | |||||||||||||||||||||||||||||||
| 16 | 33 | return $log; | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | sub is_between { | ||||||||||||||||||||||||||||||||
| 20 | 589 | ▶ | my ( $value, $min, $max, $desc ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
is_between: called CC=3 SCAR=13.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 589 | my $tb = Test::Builder->new(); | |||||||||||||||||||||||||||||||
| 23 | 589 | ▶ | if ( $value >= $min && $value <= $max ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value >= $min and $value <= $max
MC/DC0%0/2
$value >= $min and $value <= $max
$value >= $min
$value <= $max
Truth table33%1/3
A and B
A= $value >= $minB= $value <= $max
| |||||||||||||||||||||||||||||||||
| 24 | 589 | $tb->ok( 1, $desc ); | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||||||||||||||
| 27 | 0 | $tb->diag("$value is not between $min and $max"); | |||||||||||||||||||||||||||||||
| 28 | 0 | $tb->ok( undef, $desc ); | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | sub cmp_bool { | ||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my ( $bool1, $bool2, $desc ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
cmp_bool: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | my $tb = Test::Builder->new(); | |||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( $bool1 && !$bool2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$bool1 and not $bool2
MC/DC0%0/2
$bool1 and not $bool2
$bool1
not $bool2
Truth table0%0/3
A and not(B)
A= $bool1B= not $bool2
| |||||||||||||||||||||||||||||||||
| 37 | 0 | $tb->ok( 0, "$desc - bool1 is true, bool2 is false" ); | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | ▶ | elsif ( !$bool1 && $bool2 ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
not $bool1 and $bool2
MC/DC0%0/2
not $bool1 and $bool2
not $bool1
$bool2
Truth table0%0/3
not(A) and B
A= not $bool1B= $bool2
| |||||||||||||||||||||||||||||||||
| 40 | 0 | $tb->ok( 0, "$desc - bool1 is false, bool2 is true" ); | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||
| 43 | 0 | $tb->ok( 1, $desc ); | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | sub skip_until { | ||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ( $until_str, $how_many, $code ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
skip_until: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 0 | my $until = str2time($until_str); | |||||||||||||||||||||||||||||||
| 51 | SKIP: { | ||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | skip "until $until_str", $how_many if ( time < $until ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 0 | $code->(); | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | # Generate random string of printable ASCII characters. | ||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||
| 59 | sub random_string { | ||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | my ($length) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
random_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 3 | return join( '', map { chr( int( rand(95) + 33 ) ) } ( 1 .. $length ) ); | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 19 | 1; | |||||||||||||||||||||||||||||||