line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::Test::Util; |
2
|
|
|
|
|
|
|
$CHI::Test::Util::VERSION = '0.61'; |
3
|
20
|
|
|
20
|
|
20182
|
use Date::Parse; |
|
20
|
|
|
|
|
153482
|
|
|
20
|
|
|
|
|
2451
|
|
4
|
20
|
|
|
20
|
|
187
|
use Test::Builder; |
|
20
|
|
|
|
|
50
|
|
|
20
|
|
|
|
|
443
|
|
5
|
20
|
|
|
20
|
|
107
|
use Test::More; |
|
20
|
|
|
|
|
45
|
|
|
20
|
|
|
|
|
223
|
|
6
|
20
|
|
|
20
|
|
5291
|
use strict; |
|
20
|
|
|
|
|
49
|
|
|
20
|
|
|
|
|
436
|
|
7
|
20
|
|
|
20
|
|
97
|
use warnings; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
2425
|
|
8
|
20
|
|
|
20
|
|
112
|
use base qw(Exporter); |
|
20
|
|
|
|
|
2951
|
|
|
20
|
|
|
|
|
11764
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = |
11
|
|
|
|
|
|
|
qw(activate_test_logger is_between cmp_bool random_string skip_until); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub activate_test_logger { |
14
|
33
|
|
|
33
|
0
|
371
|
my $log = Log::Any->get_logger( category => 'CHI' ); |
15
|
33
|
|
|
|
|
4309
|
$log->clear(); |
16
|
33
|
|
|
|
|
9184
|
return $log; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub is_between { |
20
|
589
|
|
|
589
|
0
|
63378
|
my ( $value, $min, $max, $desc ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
589
|
|
|
|
|
3411
|
my $tb = Test::Builder->new(); |
23
|
589
|
50
|
33
|
|
|
6216
|
if ( $value >= $min && $value <= $max ) { |
24
|
589
|
|
|
|
|
2225
|
$tb->ok( 1, $desc ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
|
|
|
|
0
|
$tb->diag("$value is not between $min and $max"); |
28
|
0
|
|
|
|
|
0
|
$tb->ok( undef, $desc ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub cmp_bool { |
33
|
0
|
|
|
0
|
0
|
0
|
my ( $bool1, $bool2, $desc ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $tb = Test::Builder->new(); |
36
|
0
|
0
|
0
|
|
|
0
|
if ( $bool1 && !$bool2 ) { |
|
|
0
|
0
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
$tb->ok( 0, "$desc - bool1 is true, bool2 is false" ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ( !$bool1 && $bool2 ) { |
40
|
0
|
|
|
|
|
0
|
$tb->ok( 0, "$desc - bool1 is false, bool2 is true" ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
0
|
$tb->ok( 1, $desc ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub skip_until { |
48
|
0
|
|
|
0
|
0
|
0
|
my ( $until_str, $how_many, $code ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
my $until = str2time($until_str); |
51
|
|
|
|
|
|
|
SKIP: { |
52
|
0
|
0
|
|
|
|
0
|
skip "until $until_str", $how_many if ( time < $until ); |
|
0
|
|
|
|
|
0
|
|
53
|
0
|
|
|
|
|
0
|
$code->(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Generate random string of printable ASCII characters. |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
sub random_string { |
60
|
3
|
|
|
3
|
0
|
6
|
my ($length) = @_; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
10
|
return join( '', map { chr( int( rand(95) + 33 ) ) } ( 1 .. $length ) ); |
|
300
|
|
|
|
|
501
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |