| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
11
|
|
|
11
|
|
231
|
use 5.008001; |
|
|
11
|
|
|
|
|
48
|
|
|
2
|
11
|
|
|
11
|
|
58
|
use strict; |
|
|
11
|
|
|
|
|
27
|
|
|
|
11
|
|
|
|
|
284
|
|
|
3
|
11
|
|
|
11
|
|
54
|
use warnings; |
|
|
11
|
|
|
|
|
20
|
|
|
|
11
|
|
|
|
|
730
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Log::Any::Adapter::Test; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.717'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
79
|
use Log::Any::Adapter::Util qw/dump_one_line/; |
|
|
11
|
|
|
|
|
28
|
|
|
|
11
|
|
|
|
|
664
|
|
|
10
|
11
|
|
|
11
|
|
71
|
use Test::Builder; |
|
|
11
|
|
|
|
|
19
|
|
|
|
11
|
|
|
|
|
316
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
11
|
|
|
11
|
|
3164
|
use Log::Any::Adapter::Base; |
|
|
11
|
|
|
|
|
32
|
|
|
|
11
|
|
|
|
|
1620
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw/Log::Any::Adapter::Base/; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $tb = Test::Builder->new(); |
|
16
|
|
|
|
|
|
|
my @msgs; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Ignore arguments for the original adapter if we're overriding, but recover |
|
19
|
|
|
|
|
|
|
# category from argument list; this depends on category => $category being put |
|
20
|
|
|
|
|
|
|
# at the end of the list in Log::Any::Manager. If not overriding, allow |
|
21
|
|
|
|
|
|
|
# arguments as usual. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
|
24
|
19
|
|
|
19
|
0
|
38
|
my $class = shift; |
|
25
|
19
|
100
|
66
|
|
|
86
|
if ( defined $Log::Any::OverrideDefaultAdapterClass |
|
26
|
|
|
|
|
|
|
&& $Log::Any::OverrideDefaultAdapterClass eq __PACKAGE__ ) |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
8
|
|
|
|
|
19
|
my $category = pop @_; |
|
29
|
8
|
|
|
|
|
46
|
return $class->SUPER::new( category => $category ); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
else { |
|
32
|
11
|
|
|
|
|
53
|
return $class->SUPER::new(@_); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# All detection methods return true |
|
37
|
|
|
|
|
|
|
# |
|
38
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { |
|
39
|
11
|
|
|
11
|
|
83
|
no strict 'refs'; |
|
|
11
|
|
|
|
|
58
|
|
|
|
11
|
|
|
|
|
951
|
|
|
40
|
55
|
|
|
55
|
|
163
|
*{$method} = sub { 1 }; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# All logging methods push onto msgs array |
|
44
|
|
|
|
|
|
|
# |
|
45
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { |
|
46
|
11
|
|
|
11
|
|
70
|
no strict 'refs'; |
|
|
11
|
|
|
|
|
29
|
|
|
|
11
|
|
|
|
|
13615
|
|
|
47
|
|
|
|
|
|
|
*{$method} = sub { |
|
48
|
30
|
|
|
30
|
|
80
|
my ( $self, $msg ) = @_; |
|
49
|
|
|
|
|
|
|
push( |
|
50
|
|
|
|
|
|
|
@msgs, |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
|
|
|
|
|
|
message => $msg, |
|
53
|
|
|
|
|
|
|
level => $method, |
|
54
|
|
|
|
|
|
|
category => $self->{category} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
30
|
|
|
|
|
167
|
); |
|
57
|
|
|
|
|
|
|
}; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Testing methods below |
|
61
|
|
|
|
|
|
|
# |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub msgs { |
|
64
|
61
|
|
|
61
|
0
|
109
|
my $self = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
61
|
|
|
|
|
188
|
return \@msgs; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub clear { |
|
70
|
9
|
|
|
9
|
0
|
17
|
my ($self) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
9
|
|
|
|
|
219
|
@msgs = (); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub contains_ok { |
|
76
|
21
|
|
|
21
|
0
|
55
|
my ( $self, $regex, $test_name ) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
21
|
|
|
|
|
43
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
79
|
|
|
|
|
|
|
|
|
80
|
21
|
|
66
|
|
|
68
|
$test_name ||= "log contains '$regex'"; |
|
81
|
|
|
|
|
|
|
my $found = |
|
82
|
21
|
|
|
20
|
|
82
|
_first_index( sub { $_->{message} =~ /$regex/ }, @{ $self->msgs } ); |
|
|
20
|
|
|
|
|
202
|
|
|
|
21
|
|
|
|
|
52
|
|
|
83
|
21
|
100
|
|
|
|
103
|
if ( $found != -1 ) { |
|
84
|
20
|
|
|
|
|
36
|
splice( @{ $self->msgs }, $found, 1 ); |
|
|
20
|
|
|
|
|
40
|
|
|
85
|
20
|
|
|
|
|
94
|
$tb->ok( 1, $test_name ); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
else { |
|
88
|
1
|
|
|
|
|
5
|
$tb->ok( 0, $test_name ); |
|
89
|
1
|
|
|
|
|
1484
|
$tb->diag( "could not find message matching $regex" ); |
|
90
|
1
|
|
|
|
|
311
|
_diag_msgs(); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub category_contains_ok { |
|
95
|
5
|
|
|
5
|
0
|
15
|
my ( $self, $category, $regex, $test_name ) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
5
|
|
|
|
|
10
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
98
|
|
|
|
|
|
|
|
|
99
|
5
|
|
33
|
|
|
16
|
$test_name ||= "log for $category contains '$regex'"; |
|
100
|
|
|
|
|
|
|
my $found = |
|
101
|
|
|
|
|
|
|
_first_index( |
|
102
|
5
|
50
|
|
5
|
|
73
|
sub { $_->{category} eq $category && $_->{message} =~ /$regex/ }, |
|
103
|
5
|
|
|
|
|
23
|
@{ $self->msgs } ); |
|
|
5
|
|
|
|
|
13
|
|
|
104
|
5
|
50
|
|
|
|
41
|
if ( $found != -1 ) { |
|
105
|
5
|
|
|
|
|
11
|
splice( @{ $self->msgs }, $found, 1 ); |
|
|
5
|
|
|
|
|
11
|
|
|
106
|
5
|
|
|
|
|
23
|
$tb->ok( 1, $test_name ); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
else { |
|
109
|
0
|
|
|
|
|
0
|
$tb->ok( 0, $test_name ); |
|
110
|
0
|
|
|
|
|
0
|
$tb->diag( "could not find $category message matching $regex" ); |
|
111
|
0
|
|
|
|
|
0
|
_diag_msgs(); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub does_not_contain_ok { |
|
116
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $regex, $test_name ) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
0
|
|
|
0
|
$test_name ||= "log does not contain '$regex'"; |
|
121
|
|
|
|
|
|
|
my $found = |
|
122
|
0
|
|
|
0
|
|
0
|
_first_index( sub { $_->{message} =~ /$regex/ }, @{ $self->msgs } ); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
123
|
0
|
0
|
|
|
|
0
|
if ( $found != -1 ) { |
|
124
|
0
|
|
|
|
|
0
|
$tb->ok( 0, $test_name ); |
|
125
|
0
|
|
|
|
|
0
|
$tb->diag( "found message matching $regex: " . $self->msgs->[$found]->{message} ); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
else { |
|
128
|
0
|
|
|
|
|
0
|
$tb->ok( 1, $test_name ); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub category_does_not_contain_ok { |
|
133
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $category, $regex, $test_name ) = @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
0
|
|
|
0
|
$test_name ||= "log for $category contains '$regex'"; |
|
138
|
|
|
|
|
|
|
my $found = |
|
139
|
|
|
|
|
|
|
_first_index( |
|
140
|
0
|
0
|
|
0
|
|
0
|
sub { $_->{category} eq $category && $_->{message} =~ /$regex/ }, |
|
141
|
0
|
|
|
|
|
0
|
@{ $self->msgs } ); |
|
|
0
|
|
|
|
|
0
|
|
|
142
|
0
|
0
|
|
|
|
0
|
if ( $found != -1 ) { |
|
143
|
0
|
|
|
|
|
0
|
$tb->ok( 0, $test_name ); |
|
144
|
0
|
|
|
|
|
0
|
$tb->diag( "found $category message matching $regex: " |
|
145
|
|
|
|
|
|
|
. $self->msgs->[$found] ); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
else { |
|
148
|
0
|
|
|
|
|
0
|
$tb->ok( 1, $test_name ); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub empty_ok { |
|
153
|
3
|
|
|
3
|
0
|
13
|
my ( $self, $test_name ) = @_; |
|
154
|
|
|
|
|
|
|
|
|
155
|
3
|
|
|
|
|
11
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
156
|
|
|
|
|
|
|
|
|
157
|
3
|
|
50
|
|
|
22
|
$test_name ||= "log is empty"; |
|
158
|
3
|
50
|
|
|
|
6
|
if ( !@{ $self->msgs } ) { |
|
|
3
|
|
|
|
|
9
|
|
|
159
|
3
|
|
|
|
|
14
|
$tb->ok( 1, $test_name ); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
else { |
|
162
|
0
|
|
|
|
|
0
|
$tb->ok( 0, $test_name ); |
|
163
|
0
|
|
|
|
|
0
|
$tb->diag( "log is not empty" ); |
|
164
|
0
|
|
|
|
|
0
|
_diag_msgs(); |
|
165
|
0
|
|
|
|
|
0
|
$self->clear(); |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub contains_only_ok { |
|
170
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $regex, $test_name ) = @_; |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
|
0
|
|
|
0
|
$test_name ||= "log contains only '$regex'"; |
|
175
|
0
|
|
|
|
|
0
|
my $count = scalar( @{ $self->msgs } ); |
|
|
0
|
|
|
|
|
0
|
|
|
176
|
0
|
0
|
|
|
|
0
|
if ( $count == 1 ) { |
|
177
|
0
|
|
|
|
|
0
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
178
|
0
|
|
|
|
|
0
|
$self->contains_ok( $regex, $test_name ); |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
else { |
|
181
|
0
|
|
|
|
|
0
|
$tb->ok( 0, $test_name ); |
|
182
|
0
|
|
|
|
|
0
|
_diag_msgs(); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub _diag_msgs { |
|
187
|
1
|
|
|
1
|
|
3
|
my $count = @msgs; |
|
188
|
1
|
50
|
|
|
|
5
|
if ( ! $count ) { |
|
189
|
1
|
|
|
|
|
4
|
$tb->diag("log contains no messages"); |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
else { |
|
192
|
0
|
0
|
|
|
|
0
|
$tb->diag("log contains $count message" . ( $count > 1 ? "s:" : ":")); |
|
193
|
0
|
|
|
|
|
0
|
$tb->diag(dump_one_line($_)) for @msgs; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub _first_index { |
|
198
|
26
|
|
|
26
|
|
41
|
my $f = shift; |
|
199
|
26
|
|
|
|
|
88
|
for my $i ( 0 .. $#_ ) { |
|
200
|
25
|
|
|
|
|
62
|
local *_ = \$_[$i]; |
|
201
|
25
|
50
|
|
|
|
70
|
return $i if $f->(); |
|
202
|
|
|
|
|
|
|
} |
|
203
|
1
|
|
|
|
|
5
|
return -1; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
__END__ |