line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Log::Dispatch; |
2
|
4
|
|
|
4
|
|
1328826
|
use Data::Dumper; |
|
4
|
|
|
|
|
1968837
|
|
|
4
|
|
|
|
|
340
|
|
3
|
4
|
|
|
4
|
|
3896
|
use List::MoreUtils qw(first_index); |
|
4
|
|
|
|
|
6917
|
|
|
4
|
|
|
|
|
384
|
|
4
|
4
|
|
|
4
|
|
3710
|
use Log::Dispatch::Array; |
|
4
|
|
|
|
|
100565
|
|
|
4
|
|
|
|
|
133
|
|
5
|
4
|
|
|
4
|
|
41
|
use Test::Builder; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
147
|
|
6
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
117
|
|
7
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
123
|
|
8
|
4
|
|
|
4
|
|
20
|
use base qw(Log::Dispatch); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
3668
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $tb = Test::Builder->new(); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
3
|
|
|
3
|
1
|
45
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
42
|
my $self = $class->SUPER::new(); |
18
|
3
|
|
|
|
|
268
|
$self->add( |
19
|
|
|
|
|
|
|
Log::Dispatch::Array->new( |
20
|
|
|
|
|
|
|
name => 'test', |
21
|
|
|
|
|
|
|
min_level => 'debug', |
22
|
|
|
|
|
|
|
@_ |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
); |
25
|
3
|
|
|
|
|
511
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub clear { |
29
|
3
|
|
|
3
|
1
|
6288
|
my ($self) = @_; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
16
|
$self->{outputs}{test}{array} = []; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub msgs { |
35
|
31
|
|
|
31
|
1
|
930
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
31
|
|
|
|
|
185
|
return $self->{outputs}{test}{array}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub contains_ok { |
41
|
7
|
|
|
7
|
1
|
6775
|
my ( $self, $regex, $test_name ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
7
|
|
66
|
|
|
46
|
$test_name ||= "log contains '$regex'"; |
44
|
7
|
|
|
6
|
|
35
|
my $found = first_index { $_->{message} =~ /$regex/ } @{ $self->msgs }; |
|
6
|
|
|
|
|
42
|
|
|
7
|
|
|
|
|
23
|
|
45
|
7
|
100
|
|
|
|
43
|
if ( $found != -1 ) { |
46
|
5
|
|
|
|
|
8
|
splice( @{ $self->msgs }, $found, 1 ); |
|
5
|
|
|
|
|
12
|
|
47
|
5
|
|
|
|
|
45
|
$tb->ok( 1, $test_name ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
2
|
|
|
|
|
46
|
$tb->ok( 0, $test_name ); |
51
|
2
|
|
|
|
|
302
|
$tb->diag( "could not find message matching $regex; log contains: " |
52
|
|
|
|
|
|
|
. _dump_one_line( $self->msgs ) ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub does_not_contain_ok { |
57
|
3
|
|
|
3
|
1
|
7830
|
my ( $self, $regex, $test_name ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
66
|
|
|
21
|
$test_name ||= "log does not contain '$regex'"; |
60
|
3
|
|
|
2
|
|
24
|
my $found = first_index { $_->{message} =~ /$regex/ } @{ $self->msgs }; |
|
2
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
13
|
|
61
|
3
|
100
|
|
|
|
20
|
if ( $found != -1 ) { |
62
|
1
|
|
|
|
|
11
|
$tb->ok( 0, $test_name ); |
63
|
1
|
|
|
|
|
124
|
$tb->diag( "found message matching $regex: " . $self->msgs->[$found] ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
2
|
|
|
|
|
18
|
$tb->ok( 1, $test_name ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub empty_ok { |
71
|
5
|
|
|
5
|
1
|
15969
|
my ( $self, $test_name ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
5
|
|
100
|
|
|
27
|
$test_name ||= "log is empty"; |
74
|
5
|
100
|
|
|
|
9
|
if ( !@{ $self->msgs } ) { |
|
5
|
|
|
|
|
21
|
|
75
|
4
|
|
|
|
|
29
|
$tb->ok( 1, $test_name ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
1
|
|
|
|
|
11
|
$tb->ok( 0, $test_name ); |
79
|
1
|
|
|
|
|
170
|
$tb->diag( |
80
|
|
|
|
|
|
|
"log is not empty; contains " . _dump_one_line( $self->msgs ) ); |
81
|
1
|
|
|
|
|
165
|
$self->clear(); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub contains_only_ok { |
86
|
3
|
|
|
3
|
1
|
4490
|
my ( $self, $regex, $test_name ) = @_; |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
66
|
|
|
18
|
$test_name ||= "log contains only '$regex'"; |
89
|
3
|
|
|
|
|
6
|
my $count = scalar( @{ $self->msgs } ); |
|
3
|
|
|
|
|
11
|
|
90
|
3
|
100
|
|
|
|
12
|
if ( $count == 1 ) { |
91
|
1
|
|
|
|
|
2
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
92
|
1
|
|
|
|
|
5
|
$self->contains_ok( $regex, $test_name ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
2
|
|
|
|
|
16
|
$tb->ok( 0, $test_name ); |
96
|
2
|
|
|
|
|
224
|
$tb->diag( |
97
|
|
|
|
|
|
|
"log contains $count messages: " . _dump_one_line( $self->msgs ) ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _dump_one_line { |
102
|
5
|
|
|
5
|
|
11
|
my ($value) = @_; |
103
|
|
|
|
|
|
|
|
104
|
5
|
|
|
|
|
50
|
return Data::Dumper->new( [$value] )->Indent(0)->Sortkeys(1)->Quotekeys(0) |
105
|
|
|
|
|
|
|
->Terse(1)->Dump(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |