line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stream::Plugin::Compare; |
2
|
100
|
|
|
100
|
|
1212
|
use strict; |
|
100
|
|
|
|
|
177
|
|
|
100
|
|
|
|
|
2572
|
|
3
|
100
|
|
|
100
|
|
478
|
use warnings; |
|
100
|
|
|
|
|
186
|
|
|
100
|
|
|
|
|
2528
|
|
4
|
|
|
|
|
|
|
|
5
|
100
|
|
|
100
|
|
504
|
use Test::Stream::Exporter; |
|
100
|
|
|
|
|
163
|
|
|
100
|
|
|
|
|
659
|
|
6
|
|
|
|
|
|
|
default_exports qw/is like/; |
7
|
|
|
|
|
|
|
exports qw{ |
8
|
|
|
|
|
|
|
match mismatch validator |
9
|
|
|
|
|
|
|
hash array object meta number string |
10
|
|
|
|
|
|
|
in_set not_in_set check_set |
11
|
|
|
|
|
|
|
item field call prop check |
12
|
|
|
|
|
|
|
end filter_items |
13
|
|
|
|
|
|
|
T F D DNE FDNE |
14
|
|
|
|
|
|
|
event |
15
|
|
|
|
|
|
|
exact_ref |
16
|
|
|
|
|
|
|
}; |
17
|
100
|
|
|
100
|
|
529
|
no Test::Stream::Exporter; |
|
100
|
|
|
|
|
176
|
|
|
100
|
|
|
|
|
408
|
|
18
|
|
|
|
|
|
|
|
19
|
100
|
|
|
100
|
|
510
|
use Carp qw/croak/; |
|
100
|
|
|
|
|
181
|
|
|
100
|
|
|
|
|
4568
|
|
20
|
100
|
|
|
100
|
|
512
|
use Scalar::Util qw/reftype blessed/; |
|
100
|
|
|
|
|
170
|
|
|
100
|
|
|
|
|
5479
|
|
21
|
|
|
|
|
|
|
|
22
|
100
|
|
|
100
|
|
51313
|
use Test::Stream::Compare qw/-all/; |
|
100
|
|
|
|
|
259
|
|
|
100
|
|
|
|
|
401
|
|
23
|
100
|
|
|
100
|
|
604
|
use Test::Stream::Context qw/context/; |
|
100
|
|
|
|
|
203
|
|
|
100
|
|
|
|
|
665
|
|
24
|
100
|
|
|
100
|
|
534
|
use Test::Stream::Util qw/rtype/; |
|
100
|
|
|
|
|
202
|
|
|
100
|
|
|
|
|
417
|
|
25
|
|
|
|
|
|
|
|
26
|
100
|
|
|
100
|
|
59765
|
use Test::Stream::Compare::Array; |
|
100
|
|
|
|
|
251
|
|
|
100
|
|
|
|
|
795
|
|
27
|
100
|
|
|
100
|
|
56069
|
use Test::Stream::Compare::Custom; |
|
100
|
|
|
|
|
247
|
|
|
100
|
|
|
|
|
933
|
|
28
|
100
|
|
|
100
|
|
54287
|
use Test::Stream::Compare::Event; |
|
100
|
|
|
|
|
287
|
|
|
100
|
|
|
|
|
732
|
|
29
|
100
|
|
|
100
|
|
55267
|
use Test::Stream::Compare::Hash; |
|
100
|
|
|
|
|
270
|
|
|
100
|
|
|
|
|
738
|
|
30
|
100
|
|
|
100
|
|
659
|
use Test::Stream::Compare::Meta; |
|
100
|
|
|
|
|
199
|
|
|
100
|
|
|
|
|
795
|
|
31
|
100
|
|
|
100
|
|
55551
|
use Test::Stream::Compare::Number; |
|
100
|
|
|
|
|
250
|
|
|
100
|
|
|
|
|
823
|
|
32
|
100
|
|
|
100
|
|
638
|
use Test::Stream::Compare::Object; |
|
100
|
|
|
|
|
204
|
|
|
100
|
|
|
|
|
719
|
|
33
|
100
|
|
|
100
|
|
54160
|
use Test::Stream::Compare::Pattern; |
|
100
|
|
|
|
|
259
|
|
|
100
|
|
|
|
|
686
|
|
34
|
100
|
|
|
100
|
|
55481
|
use Test::Stream::Compare::Ref; |
|
100
|
|
|
|
|
261
|
|
|
100
|
|
|
|
|
674
|
|
35
|
100
|
|
|
100
|
|
53833
|
use Test::Stream::Compare::Regex; |
|
100
|
|
|
|
|
257
|
|
|
100
|
|
|
|
|
706
|
|
36
|
100
|
|
|
100
|
|
53699
|
use Test::Stream::Compare::Scalar; |
|
100
|
|
|
|
|
255
|
|
|
100
|
|
|
|
|
711
|
|
37
|
100
|
|
|
100
|
|
54155
|
use Test::Stream::Compare::Set; |
|
100
|
|
|
|
|
270
|
|
|
100
|
|
|
|
|
719
|
|
38
|
100
|
|
|
100
|
|
53637
|
use Test::Stream::Compare::String; |
|
100
|
|
|
|
|
253
|
|
|
100
|
|
|
|
|
724
|
|
39
|
100
|
|
|
100
|
|
53883
|
use Test::Stream::Compare::Undef; |
|
100
|
|
|
|
|
273
|
|
|
100
|
|
|
|
|
727
|
|
40
|
100
|
|
|
100
|
|
54011
|
use Test::Stream::Compare::Value; |
|
100
|
|
|
|
|
310
|
|
|
100
|
|
|
|
|
699
|
|
41
|
100
|
|
|
100
|
|
53387
|
use Test::Stream::Compare::Wildcard; |
|
100
|
|
|
|
|
272
|
|
|
100
|
|
|
|
|
847
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub is($$;$@) { |
44
|
1440
|
|
|
1440
|
1
|
13592606
|
my ($got, $exp, $name, @diag) = @_; |
45
|
1440
|
|
|
|
|
3981
|
my $ctx = context(); |
46
|
|
|
|
|
|
|
|
47
|
1440
|
|
|
|
|
5230
|
my $delta = compare($got, $exp, \&strict_convert); |
48
|
|
|
|
|
|
|
|
49
|
1440
|
100
|
|
|
|
4137
|
if ($delta) { |
50
|
78
|
|
|
|
|
260
|
$ctx->ok(0, $name, [$delta->table, @diag]); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
1362
|
|
|
|
|
4326
|
$ctx->ok(1, $name); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1440
|
|
|
|
|
4516
|
$ctx->release; |
57
|
1440
|
|
|
|
|
5033
|
return !$delta; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub like($$;$@) { |
61
|
430
|
|
|
430
|
1
|
1596
|
my ($got, $exp, $name, @diag) = @_; |
62
|
430
|
|
|
|
|
1833
|
my $ctx = context(); |
63
|
|
|
|
|
|
|
|
64
|
430
|
|
|
|
|
1656
|
my $delta = compare($got, $exp, \&relaxed_convert); |
65
|
|
|
|
|
|
|
|
66
|
430
|
100
|
|
|
|
1382
|
if ($delta) { |
67
|
3
|
|
|
|
|
15
|
$ctx->ok(0, $name, [$delta->table, @diag]); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
427
|
|
|
|
|
1501
|
$ctx->ok(1, $name); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
430
|
|
|
|
|
1477
|
$ctx->release; |
74
|
430
|
|
|
|
|
1486
|
return !$delta; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
4
|
1
|
46
|
sub meta(&) { build('Test::Stream::Compare::Meta', @_) } |
78
|
10
|
|
|
10
|
1
|
88
|
sub hash(&) { build('Test::Stream::Compare::Hash', @_) } |
79
|
198
|
|
|
198
|
1
|
1433
|
sub array(&) { build('Test::Stream::Compare::Array', @_) } |
80
|
125
|
|
|
125
|
1
|
689
|
sub object(&) { build('Test::Stream::Compare::Object', @_) } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $FDNE = Test::Stream::Compare::Custom->new(code => sub { $_ ? 0 : 1 }, name => 'FALSE', operator => 'FALSE() || !exists'); |
83
|
|
|
|
|
|
|
my $DNE = Test::Stream::Compare::Custom->new(code => sub { my %p = @_; $p{exists} ? 0 : 1 }, name => '', operator => '!exists'); |
84
|
|
|
|
|
|
|
my $F = Test::Stream::Compare::Custom->new(code => sub { my %p = @_; $p{got} ? 0 : $p{exists} }, name => 'FALSE', operator => 'FALSE()'); |
85
|
|
|
|
|
|
|
my $T = Test::Stream::Compare::Custom->new(code => sub { $_ ? 1 : 0 }, name => 'TRUE', operator => 'TRUE()'); |
86
|
|
|
|
|
|
|
my $D = Test::Stream::Compare::Custom->new(code => sub { defined $_ ? 1 : 0 }, name => 'DEFINED', operator => 'DEFINED()'); |
87
|
|
|
|
|
|
|
|
88
|
58
|
|
|
58
|
1
|
372
|
sub T() { $T } |
89
|
31
|
|
|
31
|
1
|
145
|
sub F() { $F } |
90
|
6
|
|
|
6
|
1
|
23
|
sub D() { $D } |
91
|
53
|
|
|
53
|
1
|
435
|
sub DNE() { $DNE } |
92
|
6
|
|
|
6
|
1
|
25
|
sub FDNE() { $FDNE } |
93
|
|
|
|
|
|
|
|
94
|
5141
|
|
|
5141
|
0
|
11347
|
sub strict_convert { convert($_[0], 1) } |
95
|
2235
|
|
|
2235
|
0
|
4739
|
sub relaxed_convert { convert($_[0], 0) } |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub exact_ref($) { |
98
|
19
|
|
|
19
|
1
|
103
|
my @caller = caller; |
99
|
19
|
|
|
|
|
124
|
return Test::Stream::Compare::Ref->new( |
100
|
|
|
|
|
|
|
file => $caller[1], |
101
|
|
|
|
|
|
|
lines => [$caller[2]], |
102
|
|
|
|
|
|
|
input => $_[0], |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub match($) { |
107
|
23
|
|
|
23
|
1
|
165
|
my @caller = caller; |
108
|
23
|
|
|
|
|
147
|
return Test::Stream::Compare::Pattern->new( |
109
|
|
|
|
|
|
|
file => $caller[1], |
110
|
|
|
|
|
|
|
lines => [$caller[2]], |
111
|
|
|
|
|
|
|
pattern => $_[0], |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub mismatch($) { |
116
|
4
|
|
|
4
|
1
|
44
|
my @caller = caller; |
117
|
4
|
|
|
|
|
35
|
return Test::Stream::Compare::Pattern->new( |
118
|
|
|
|
|
|
|
file => $caller[1], |
119
|
|
|
|
|
|
|
lines => [$caller[2]], |
120
|
|
|
|
|
|
|
negate => 1, |
121
|
|
|
|
|
|
|
pattern => $_[0], |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub validator { |
126
|
109
|
|
|
109
|
1
|
713
|
my $code = pop; |
127
|
109
|
|
|
|
|
148
|
my $cname = pop; |
128
|
109
|
|
|
|
|
149
|
my $op = pop; |
129
|
|
|
|
|
|
|
|
130
|
109
|
|
|
|
|
313
|
my @caller = caller; |
131
|
109
|
|
|
|
|
479
|
return Test::Stream::Compare::Custom->new( |
132
|
|
|
|
|
|
|
file => $caller[1], |
133
|
|
|
|
|
|
|
lines => [$caller[2]], |
134
|
|
|
|
|
|
|
code => $code, |
135
|
|
|
|
|
|
|
name => $cname, |
136
|
|
|
|
|
|
|
operator => $op, |
137
|
|
|
|
|
|
|
); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub number($;@) { |
141
|
2
|
|
|
2
|
1
|
12
|
my ($num, @args) = @_; |
142
|
2
|
|
|
|
|
9
|
my @caller = caller; |
143
|
2
|
|
|
|
|
22
|
return Test::Stream::Compare::Number->new( |
144
|
|
|
|
|
|
|
file => $caller[1], |
145
|
|
|
|
|
|
|
lines => [$caller[2]], |
146
|
|
|
|
|
|
|
input => $num, |
147
|
|
|
|
|
|
|
@args, |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub string($;@) { |
152
|
2
|
|
|
2
|
1
|
12
|
my ($str, @args) = @_; |
153
|
2
|
|
|
|
|
9
|
my @caller = caller; |
154
|
2
|
|
|
|
|
15
|
return Test::Stream::Compare::String->new( |
155
|
|
|
|
|
|
|
file => $caller[1], |
156
|
|
|
|
|
|
|
lines => [$caller[2]], |
157
|
|
|
|
|
|
|
input => $str, |
158
|
|
|
|
|
|
|
@args, |
159
|
|
|
|
|
|
|
); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub filter_items(&) { |
163
|
5
|
100
|
|
5
|
1
|
41
|
my $build = get_build() or croak "No current build!"; |
164
|
|
|
|
|
|
|
|
165
|
4
|
100
|
|
|
|
140
|
croak "'$build' does not support filters" |
166
|
|
|
|
|
|
|
unless $build->can('add_filter'); |
167
|
|
|
|
|
|
|
|
168
|
3
|
100
|
|
|
|
114
|
croak "'filter_items' should only ever be called in void context" |
169
|
|
|
|
|
|
|
if defined wantarray; |
170
|
|
|
|
|
|
|
|
171
|
2
|
|
|
|
|
11
|
$build->add_filter(@_); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub end() { |
175
|
139
|
100
|
|
139
|
1
|
658
|
my $build = get_build() or croak "No current build!"; |
176
|
|
|
|
|
|
|
|
177
|
138
|
100
|
|
|
|
685
|
croak "'$build' does not support 'ending'" |
178
|
|
|
|
|
|
|
unless $build->can('ending'); |
179
|
|
|
|
|
|
|
|
180
|
137
|
100
|
|
|
|
448
|
croak "'end' should only ever be called in void context" |
181
|
|
|
|
|
|
|
if defined wantarray; |
182
|
|
|
|
|
|
|
|
183
|
136
|
|
|
|
|
469
|
$build->set_ending(1); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub call($$) { |
187
|
1056
|
|
|
1056
|
1
|
2245
|
my ($name, $expect) = @_; |
188
|
1056
|
100
|
|
|
|
2425
|
my $build = get_build() or croak "No current build!"; |
189
|
|
|
|
|
|
|
|
190
|
1055
|
100
|
|
|
|
3745
|
croak "'$build' does not support method calls" |
191
|
|
|
|
|
|
|
unless $build->can('add_call'); |
192
|
|
|
|
|
|
|
|
193
|
1054
|
100
|
|
|
|
2251
|
croak "'call' should only ever be called in void context" |
194
|
|
|
|
|
|
|
if defined wantarray; |
195
|
|
|
|
|
|
|
|
196
|
1053
|
|
|
|
|
2810
|
my @caller = caller; |
197
|
1053
|
|
|
|
|
3972
|
$build->add_call( |
198
|
|
|
|
|
|
|
$name, |
199
|
|
|
|
|
|
|
Test::Stream::Compare::Wildcard->new( |
200
|
|
|
|
|
|
|
expect => $expect, |
201
|
|
|
|
|
|
|
file => $caller[1], |
202
|
|
|
|
|
|
|
lines => [$caller[2]], |
203
|
|
|
|
|
|
|
), |
204
|
|
|
|
|
|
|
); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub prop($$) { |
208
|
217
|
|
|
217
|
1
|
652
|
my ($name, $expect) = @_; |
209
|
217
|
100
|
|
|
|
506
|
my $build = get_build() or croak "No current build!"; |
210
|
|
|
|
|
|
|
|
211
|
216
|
100
|
|
|
|
948
|
croak "'$build' does not support meta-checks" |
212
|
|
|
|
|
|
|
unless $build->can('add_prop'); |
213
|
|
|
|
|
|
|
|
214
|
215
|
100
|
|
|
|
559
|
croak "'prop' should only ever be called in void context" |
215
|
|
|
|
|
|
|
if defined wantarray; |
216
|
|
|
|
|
|
|
|
217
|
214
|
|
|
|
|
624
|
my @caller = caller; |
218
|
214
|
|
|
|
|
902
|
$build->add_prop( |
219
|
|
|
|
|
|
|
$name, |
220
|
|
|
|
|
|
|
Test::Stream::Compare::Wildcard->new( |
221
|
|
|
|
|
|
|
expect => $expect, |
222
|
|
|
|
|
|
|
file => $caller[1], |
223
|
|
|
|
|
|
|
lines => [$caller[2]], |
224
|
|
|
|
|
|
|
), |
225
|
|
|
|
|
|
|
); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub item($;$) { |
229
|
196
|
|
|
196
|
1
|
424
|
my @args = @_; |
230
|
196
|
|
|
|
|
289
|
my $expect = pop @args; |
231
|
|
|
|
|
|
|
|
232
|
196
|
100
|
|
|
|
474
|
my $build = get_build() or croak "No current build!"; |
233
|
|
|
|
|
|
|
|
234
|
195
|
100
|
|
|
|
806
|
croak "'$build' does not support array item checks" |
235
|
|
|
|
|
|
|
unless $build->can('add_item'); |
236
|
|
|
|
|
|
|
|
237
|
194
|
100
|
|
|
|
552
|
croak "'item' should only ever be called in void context" |
238
|
|
|
|
|
|
|
if defined wantarray; |
239
|
|
|
|
|
|
|
|
240
|
193
|
|
|
|
|
498
|
my @caller = caller; |
241
|
193
|
|
|
|
|
714
|
push @args => Test::Stream::Compare::Wildcard->new( |
242
|
|
|
|
|
|
|
expect => $expect, |
243
|
|
|
|
|
|
|
file => $caller[1], |
244
|
|
|
|
|
|
|
lines => [$caller[2]], |
245
|
|
|
|
|
|
|
); |
246
|
|
|
|
|
|
|
|
247
|
193
|
|
|
|
|
607
|
$build->add_item(@args); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub field($$) { |
251
|
80
|
|
|
80
|
1
|
335
|
my ($name, $expect) = @_; |
252
|
|
|
|
|
|
|
|
253
|
80
|
100
|
|
|
|
198
|
my $build = get_build() or croak "No current build!"; |
254
|
|
|
|
|
|
|
|
255
|
79
|
100
|
|
|
|
427
|
croak "'$build' does not support hash field checks" |
256
|
|
|
|
|
|
|
unless $build->can('add_field'); |
257
|
|
|
|
|
|
|
|
258
|
78
|
100
|
|
|
|
265
|
croak "'field' should only ever be called in void context" |
259
|
|
|
|
|
|
|
if defined wantarray; |
260
|
|
|
|
|
|
|
|
261
|
77
|
|
|
|
|
216
|
my @caller = caller; |
262
|
77
|
|
|
|
|
331
|
$build->add_field( |
263
|
|
|
|
|
|
|
$name, |
264
|
|
|
|
|
|
|
Test::Stream::Compare::Wildcard->new( |
265
|
|
|
|
|
|
|
expect => $expect, |
266
|
|
|
|
|
|
|
file => $caller[1], |
267
|
|
|
|
|
|
|
lines => [$caller[2]], |
268
|
|
|
|
|
|
|
), |
269
|
|
|
|
|
|
|
); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub check($) { |
273
|
18
|
|
|
18
|
1
|
71
|
my ($check) = @_; |
274
|
|
|
|
|
|
|
|
275
|
18
|
100
|
|
|
|
48
|
my $build = get_build() or croak "No current build!"; |
276
|
|
|
|
|
|
|
|
277
|
17
|
100
|
|
|
|
177
|
croak "'$build' is not a check-set" |
278
|
|
|
|
|
|
|
unless $build->can('add_check'); |
279
|
|
|
|
|
|
|
|
280
|
16
|
100
|
|
|
|
133
|
croak "'check' should only ever be called in void context" |
281
|
|
|
|
|
|
|
if defined wantarray; |
282
|
|
|
|
|
|
|
|
283
|
15
|
|
|
|
|
47
|
my @caller = caller; |
284
|
15
|
|
|
|
|
80
|
my $wc = Test::Stream::Compare::Wildcard->new( |
285
|
|
|
|
|
|
|
expect => $check, |
286
|
|
|
|
|
|
|
file => $caller[1], |
287
|
|
|
|
|
|
|
lines => [$caller[2]], |
288
|
|
|
|
|
|
|
); |
289
|
|
|
|
|
|
|
|
290
|
15
|
|
|
|
|
44
|
$build->add_check($wc); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
4
|
|
|
4
|
1
|
27
|
sub check_set { return _build_set('all' => @_) } |
294
|
13
|
|
|
13
|
1
|
51
|
sub in_set { return _build_set('any' => @_) } |
295
|
4
|
|
|
4
|
1
|
22
|
sub not_in_set { return _build_set('none' => @_) } |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub _build_set { |
298
|
21
|
|
|
21
|
|
37
|
my $redux = shift; |
299
|
21
|
|
|
|
|
31
|
my ($builder) = @_; |
300
|
21
|
|
100
|
|
|
83
|
my $btype = reftype($builder) || ''; |
301
|
|
|
|
|
|
|
|
302
|
21
|
|
|
|
|
26
|
my $set; |
303
|
21
|
100
|
|
|
|
51
|
if ($btype eq 'CODE') { |
304
|
7
|
|
|
|
|
24
|
$set = build('Test::Stream::Compare::Set', $builder); |
305
|
6
|
|
|
|
|
30
|
$set->set_builder($builder); |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
else { |
308
|
14
|
|
|
|
|
61
|
$set = Test::Stream::Compare::Set->new(checks => [@_]); |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
20
|
|
|
|
|
69
|
$set->set_reduction($redux); |
312
|
20
|
|
|
|
|
91
|
return $set; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
sub event($;$) { |
316
|
291
|
|
|
291
|
1
|
2088
|
my ($intype, $spec) = @_; |
317
|
|
|
|
|
|
|
|
318
|
291
|
|
|
|
|
866
|
my @caller = caller; |
319
|
|
|
|
|
|
|
|
320
|
291
|
100
|
|
|
|
908
|
croak "type is required" unless $intype; |
321
|
|
|
|
|
|
|
|
322
|
290
|
|
|
|
|
352
|
my $type; |
323
|
290
|
100
|
|
|
|
767
|
if ($intype =~ m/^\+(.*)$/) { |
324
|
1
|
|
|
|
|
5
|
$type = $1; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
else { |
327
|
289
|
|
|
|
|
614
|
$type = "Test::Stream::Event::$intype"; |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
290
|
|
|
|
|
353
|
my $event; |
331
|
290
|
100
|
|
|
|
1471
|
if (!$spec) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
332
|
1
|
|
|
|
|
6
|
$event = Test::Stream::Compare::Event->new( |
333
|
|
|
|
|
|
|
etype => $intype, |
334
|
|
|
|
|
|
|
file => $caller[1], |
335
|
|
|
|
|
|
|
lines => [$caller[2]], |
336
|
|
|
|
|
|
|
); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
elsif (!ref $spec) { |
339
|
1
|
|
|
|
|
137
|
croak "'$spec' is not a valid event specification" |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
elsif (reftype($spec) eq 'CODE') { |
342
|
109
|
|
|
|
|
419
|
$event = build('Test::Stream::Compare::Event', $spec); |
343
|
109
|
|
|
|
|
390
|
$event->set_etype($intype), |
344
|
|
|
|
|
|
|
$event->set_builder($spec); |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
else { |
347
|
179
|
|
|
|
|
1105
|
my $refcheck = Test::Stream::Compare::Hash->new( |
348
|
|
|
|
|
|
|
inref => $spec, |
349
|
|
|
|
|
|
|
file => $caller[1], |
350
|
|
|
|
|
|
|
lines => [$caller[2]], |
351
|
|
|
|
|
|
|
); |
352
|
179
|
|
|
|
|
1006
|
$event = Test::Stream::Compare::Event->new( |
353
|
|
|
|
|
|
|
refcheck => $refcheck, |
354
|
|
|
|
|
|
|
file => $caller[1], |
355
|
|
|
|
|
|
|
lines => [$caller[2]], |
356
|
|
|
|
|
|
|
etype => $intype, |
357
|
|
|
|
|
|
|
); |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
289
|
|
|
|
|
1605
|
$event->add_prop('blessed' => $type); |
361
|
|
|
|
|
|
|
|
362
|
289
|
100
|
|
|
|
688
|
return $event if defined wantarray; |
363
|
|
|
|
|
|
|
|
364
|
284
|
100
|
|
|
|
851
|
my $build = get_build() or croak "No current build!"; |
365
|
283
|
|
|
|
|
956
|
$build->add_item($event); |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
sub convert { |
369
|
9034
|
|
|
9034
|
0
|
17610
|
my ($thing, $strict) = @_; |
370
|
|
|
|
|
|
|
|
371
|
9034
|
100
|
|
|
|
19580
|
return Test::Stream::Compare::Undef->new() |
372
|
|
|
|
|
|
|
unless defined $thing; |
373
|
|
|
|
|
|
|
|
374
|
8500
|
100
|
100
|
|
|
57218
|
if ($thing && blessed($thing) && $thing->isa('Test::Stream::Compare')) { |
|
|
|
100
|
|
|
|
|
375
|
2674
|
100
|
|
|
|
11373
|
return $thing unless $thing->isa('Test::Stream::Compare::Wildcard'); |
376
|
1649
|
|
|
|
|
4536
|
my $newthing = convert($thing->expect, $strict); |
377
|
1649
|
100
|
|
|
|
4872
|
$newthing->set_builder($thing->builder) unless $newthing->builder; |
378
|
1649
|
100
|
|
|
|
15603
|
$newthing->set_file($thing->_file) unless $newthing->_file; |
379
|
1649
|
100
|
|
|
|
15401
|
$newthing->set_lines($thing->_lines) unless $newthing->_lines; |
380
|
1649
|
|
|
|
|
15178
|
return $newthing; |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
5826
|
|
|
|
|
15558
|
my $type = rtype($thing); |
384
|
|
|
|
|
|
|
|
385
|
5826
|
100
|
|
|
|
17271
|
return Test::Stream::Compare::Array->new(inref => $thing, $strict ? (ending => 1) : ()) |
|
|
100
|
|
|
|
|
|
386
|
|
|
|
|
|
|
if $type eq 'ARRAY'; |
387
|
|
|
|
|
|
|
|
388
|
5136
|
100
|
|
|
|
12328
|
return Test::Stream::Compare::Hash->new(inref => $thing, $strict ? (ending => 1) : ()) |
|
|
100
|
|
|
|
|
|
389
|
|
|
|
|
|
|
if $type eq 'HASH'; |
390
|
|
|
|
|
|
|
|
391
|
4534
|
100
|
|
|
|
9335
|
unless ($strict) { |
392
|
1437
|
100
|
|
|
|
4768
|
return Test::Stream::Compare::Pattern->new(pattern => $thing) |
393
|
|
|
|
|
|
|
if $type eq 'REGEXP'; |
394
|
|
|
|
|
|
|
|
395
|
937
|
100
|
|
|
|
1984
|
return Test::Stream::Compare::Custom->new(code => $thing) |
396
|
|
|
|
|
|
|
if $type eq 'CODE'; |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
4003
|
100
|
|
|
|
8299
|
return Test::Stream::Compare::Regex->new(input => $thing) |
400
|
|
|
|
|
|
|
if $type eq 'REGEXP'; |
401
|
|
|
|
|
|
|
|
402
|
3999
|
100
|
|
|
|
7471
|
if ($type eq 'SCALAR') { |
403
|
9
|
|
|
|
|
23
|
my $nested = convert($$thing, $strict); |
404
|
9
|
|
|
|
|
44
|
return Test::Stream::Compare::Scalar->new(item => $nested) |
405
|
|
|
|
|
|
|
} |
406
|
|
|
|
|
|
|
|
407
|
3990
|
100
|
|
|
|
7569
|
return Test::Stream::Compare::Ref->new(input => $thing) |
408
|
|
|
|
|
|
|
if $type; |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
# is() will assume string and use 'eq' |
411
|
3851
|
|
|
|
|
18682
|
return Test::Stream::Compare::String->new(input => $thing); |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
1; |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
__END__ |