line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::Test::Util; |
2
|
|
|
|
|
|
|
$CHI::Test::Util::VERSION = '0.60'; |
3
|
20
|
|
|
20
|
|
18849
|
use Date::Parse; |
|
20
|
|
|
|
|
123953
|
|
|
20
|
|
|
|
|
2741
|
|
4
|
20
|
|
|
20
|
|
178
|
use Test::Builder; |
|
20
|
|
|
|
|
30
|
|
|
20
|
|
|
|
|
406
|
|
5
|
20
|
|
|
20
|
|
85
|
use Test::More; |
|
20
|
|
|
|
|
29
|
|
|
20
|
|
|
|
|
229
|
|
6
|
20
|
|
|
20
|
|
4853
|
use strict; |
|
20
|
|
|
|
|
46
|
|
|
20
|
|
|
|
|
556
|
|
7
|
20
|
|
|
20
|
|
88
|
use warnings; |
|
20
|
|
|
|
|
29
|
|
|
20
|
|
|
|
|
629
|
|
8
|
20
|
|
|
20
|
|
92
|
use base qw(Exporter); |
|
20
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
8083
|
|
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
|
28
|
|
|
28
|
0
|
247
|
my $log = Log::Any->get_logger( category => 'CHI' ); |
15
|
28
|
|
|
|
|
839
|
$log->clear(); |
16
|
28
|
|
|
|
|
7148
|
return $log; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub is_between { |
20
|
514
|
|
|
514
|
0
|
940
|
my ( $value, $min, $max, $desc ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
514
|
|
|
|
|
2411
|
my $tb = Test::Builder->new(); |
23
|
514
|
50
|
33
|
|
|
4801
|
if ( $value >= $min && $value <= $max ) { |
24
|
514
|
|
|
|
|
1854
|
$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
|
0
|
0
|
|
|
|
0
|
SKIP: { |
52
|
0
|
|
|
|
|
0
|
skip "until $until_str", $how_many if ( time < $until ); |
53
|
0
|
|
|
|
|
0
|
$code->(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Generate random string of printable ASCII characters. |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
sub random_string { |
60
|
3
|
|
|
3
|
0
|
4
|
my ($length) = @_; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
17
|
return join( '', map { chr( int( rand(95) + 33 ) ) } ( 1 .. $length ) ); |
|
300
|
|
|
|
|
469
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |