line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
|
|
|
|
|
|
package Test::Builder; |
3
|
14
|
|
|
14
|
|
753
|
|
|
14
|
|
|
|
|
45
|
|
|
14
|
|
|
|
|
826
|
|
4
|
14
|
|
|
14
|
|
76
|
use 5.006; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
728
|
|
5
|
14
|
|
|
14
|
|
613
|
use strict; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
2083
|
|
6
|
|
|
|
|
|
|
use warnings; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.001002'; |
9
|
|
|
|
|
|
|
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) |
10
|
|
|
|
|
|
|
|
11
|
14
|
50
|
|
14
|
|
580
|
BEGIN { |
12
|
0
|
|
|
|
|
0
|
if( $] < 5.008 ) { |
13
|
|
|
|
|
|
|
require Test::Builder::IO::Scalar; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Make Test::Builder thread-safe for ithreads. |
19
|
14
|
|
|
14
|
|
1429
|
BEGIN { |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
7104
|
|
20
|
|
|
|
|
|
|
use Config; |
21
|
|
|
|
|
|
|
# Load threads::shared when threads are turned on. |
22
|
14
|
50
|
33
|
14
|
|
526
|
# 5.8.0's threads are so busted we no longer support them. |
|
|
|
33
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
if( $] >= 5.008001 && $Config{useithreads} && $INC{'threads.pm'} ) { |
24
|
|
|
|
|
|
|
require threads::shared; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Hack around YET ANOTHER threads::shared bug. It would |
27
|
|
|
|
|
|
|
# occasionally forget the contents of the variable when sharing it. |
28
|
|
|
|
|
|
|
# So we first copy the data, then share, then put our copy back. |
29
|
0
|
|
|
|
|
0
|
*share = sub (\[$@%]) { |
30
|
0
|
|
|
|
|
0
|
my $type = ref $_[0]; |
31
|
|
|
|
|
|
|
my $data; |
32
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
if( $type eq 'HASH' ) { |
|
0
|
|
|
|
|
0
|
|
34
|
|
|
|
|
|
|
%$data = %{ $_[0] }; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
0
|
elsif( $type eq 'ARRAY' ) { |
|
0
|
|
|
|
|
0
|
|
37
|
|
|
|
|
|
|
@$data = @{ $_[0] }; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
0
|
elsif( $type eq 'SCALAR' ) { |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
$$data = ${ $_[0] }; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
else { |
43
|
|
|
|
|
|
|
die( "Unknown type: " . $type ); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
0
|
|
46
|
|
|
|
|
|
|
$_[0] = &threads::shared::share( $_[0] ); |
47
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
if( $type eq 'HASH' ) { |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
%{ $_[0] } = %$data; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
0
|
elsif( $type eq 'ARRAY' ) { |
|
0
|
|
|
|
|
0
|
|
52
|
|
|
|
|
|
|
@{ $_[0] } = @$data; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
0
|
elsif( $type eq 'SCALAR' ) { |
|
0
|
|
|
|
|
0
|
|
55
|
|
|
|
|
|
|
${ $_[0] } = $$data; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
else { |
58
|
|
|
|
|
|
|
die( "Unknown type: " . $type ); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
0
|
|
61
|
0
|
|
|
|
|
0
|
return $_[0]; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
# 5.8.0's threads::shared is busted when threads are off |
65
|
|
|
|
|
|
|
# and earlier Perls just don't have that module at all. |
66
|
14
|
|
|
97
|
|
79
|
else { |
|
97
|
|
|
|
|
216
|
|
67
|
14
|
|
|
63
|
|
73056
|
*share = sub { return $_[0] }; |
|
63
|
|
|
|
|
88
|
|
68
|
|
|
|
|
|
|
*lock = sub { 0 }; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#line 117 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
our $Test = Test::Builder->new; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new { |
77
|
|
|
|
|
|
|
my($class) = shift; |
78
|
|
|
|
|
|
|
$Test ||= $class->create; |
79
|
|
|
|
|
|
|
return $Test; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#line 139 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub create { |
85
|
|
|
|
|
|
|
my $class = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $self = bless {}, $class; |
88
|
|
|
|
|
|
|
$self->reset; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return $self; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Copy an object, currently a shallow. |
95
|
|
|
|
|
|
|
# This does *not* bless the destination. This keeps the destructor from |
96
|
|
|
|
|
|
|
# firing when we're just storing a copy of the object to restore later. |
97
|
|
|
|
|
|
|
sub _copy { |
98
|
|
|
|
|
|
|
my($src, $dest) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
%$dest = %$src; |
101
|
|
|
|
|
|
|
_share_keys($dest); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#line 182 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub child { |
110
|
|
|
|
|
|
|
my( $self, $name ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if( $self->{Child_Name} ) { |
113
|
|
|
|
|
|
|
$self->croak("You already have a child named ($self->{Child_Name}) running"); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $parent_in_todo = $self->in_todo; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Clear $TODO for the child. |
119
|
|
|
|
|
|
|
my $orig_TODO = $self->find_TODO(undef, 1, undef); |
120
|
|
|
|
|
|
|
|
121
|
97
|
|
|
97
|
1
|
253
|
my $class = ref $self; |
122
|
97
|
|
66
|
|
|
563
|
my $child = $class->create; |
123
|
97
|
|
|
|
|
297
|
|
124
|
|
|
|
|
|
|
# Add to our indentation |
125
|
|
|
|
|
|
|
$child->_indent( $self->_indent . ' ' ); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Make the child use the same outputs as the parent |
128
|
|
|
|
|
|
|
for my $method (qw(output failure_output todo_output)) { |
129
|
|
|
|
|
|
|
$child->$method( $self->$method ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Ensure the child understands if they're inside a TODO |
133
|
|
|
|
|
|
|
if( $parent_in_todo ) { |
134
|
|
|
|
|
|
|
$child->failure_output( $self->todo_output ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# This will be reset in finalize. We do this here lest one child failure |
138
|
|
|
|
|
|
|
# cause all children to fail. |
139
|
|
|
|
|
|
|
$child->{Child_Error} = $?; |
140
|
|
|
|
|
|
|
$? = 0; |
141
|
14
|
|
|
14
|
1
|
37
|
$child->{Parent} = $self; |
142
|
|
|
|
|
|
|
$child->{Parent_TODO} = $orig_TODO; |
143
|
14
|
|
|
|
|
62
|
$child->{Name} = $name || "Child of " . $self->name; |
144
|
14
|
|
|
|
|
66
|
$self->{Child_Name} = $child->name; |
145
|
|
|
|
|
|
|
return $child; |
146
|
14
|
|
|
|
|
66
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#line 230 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub subtest { |
152
|
|
|
|
|
|
|
my $self = shift; |
153
|
|
|
|
|
|
|
my($name, $subtests) = @_; |
154
|
0
|
|
|
0
|
|
0
|
|
155
|
|
|
|
|
|
|
if ('CODE' ne ref $subtests) { |
156
|
0
|
|
|
|
|
0
|
$self->croak("subtest()'s second argument must be a code ref"); |
157
|
0
|
|
|
|
|
0
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
# Turn the child into the parent so anyone who has stored a copy of |
160
|
|
|
|
|
|
|
# the Test::Builder singleton will get the child. |
161
|
|
|
|
|
|
|
my $error; |
162
|
|
|
|
|
|
|
my $child; |
163
|
|
|
|
|
|
|
my $parent = {}; |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
# child() calls reset() which sets $Level to 1, so we localize |
166
|
|
|
|
|
|
|
# $Level first to limit the scope of the reset to the subtest. |
167
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Store the guts of $self as $parent and turn $child into $self. |
170
|
|
|
|
|
|
|
$child = $self->child($name); |
171
|
|
|
|
|
|
|
_copy($self, $parent); |
172
|
|
|
|
|
|
|
_copy($child, $self); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $run_the_subtests = sub { |
175
|
|
|
|
|
|
|
# Add subtest name for clarification of starting point |
176
|
|
|
|
|
|
|
$self->note("Subtest: $name"); |
177
|
|
|
|
|
|
|
$subtests->(); |
178
|
|
|
|
|
|
|
$self->done_testing unless $self->_plan_handled; |
179
|
|
|
|
|
|
|
1; |
180
|
|
|
|
|
|
|
}; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
if( !eval { $run_the_subtests->() } ) { |
183
|
|
|
|
|
|
|
$error = $@; |
184
|
0
|
|
|
0
|
1
|
0
|
} |
185
|
|
|
|
|
|
|
} |
186
|
0
|
0
|
|
|
|
0
|
|
187
|
0
|
|
|
|
|
0
|
# Restore the parent and the copied child. |
188
|
|
|
|
|
|
|
_copy($self, $child); |
189
|
|
|
|
|
|
|
_copy($parent, $self); |
190
|
0
|
|
|
|
|
0
|
|
191
|
|
|
|
|
|
|
# Restore the parent's $TODO |
192
|
|
|
|
|
|
|
$self->find_TODO(undef, 1, $child->{Parent_TODO}); |
193
|
0
|
|
|
|
|
0
|
|
194
|
|
|
|
|
|
|
# Die *after* we restore the parent. |
195
|
0
|
|
|
|
|
0
|
die $error if $error and !eval { $error->isa('Test::Builder::Exception') }; |
196
|
0
|
|
|
|
|
0
|
|
197
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
198
|
|
|
|
|
|
|
my $finalize = $child->finalize; |
199
|
0
|
|
|
|
|
0
|
|
200
|
|
|
|
|
|
|
$self->BAIL_OUT($child->{Bailed_Out_Reason}) if $child->{Bailed_Out}; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
0
|
return $finalize; |
203
|
0
|
|
|
|
|
0
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
#line 309 |
206
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
0
|
sub _plan_handled { |
208
|
0
|
|
|
|
|
0
|
my $self = shift; |
209
|
|
|
|
|
|
|
return $self->{Have_Plan} || $self->{No_Plan} || $self->{Skip_All}; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
0
|
#line 334 |
214
|
0
|
|
|
|
|
0
|
|
215
|
0
|
|
|
|
|
0
|
sub finalize { |
216
|
0
|
|
|
|
|
0
|
my $self = shift; |
217
|
0
|
|
0
|
|
|
0
|
|
218
|
0
|
|
|
|
|
0
|
return unless $self->parent; |
219
|
0
|
|
|
|
|
0
|
if( $self->{Child_Name} ) { |
220
|
|
|
|
|
|
|
$self->croak("Can't call finalize() with child ($self->{Child_Name}) active"); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
local $? = 0; # don't fail if $subtests happened to set $? nonzero |
224
|
|
|
|
|
|
|
$self->_ending; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# XXX This will only be necessary for TAP envelopes (we think) |
227
|
|
|
|
|
|
|
#$self->_print( $self->is_passing ? "PASS\n" : "FAIL\n" ); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
230
|
|
|
|
|
|
|
my $ok = 1; |
231
|
|
|
|
|
|
|
$self->parent->{Child_Name} = undef; |
232
|
0
|
|
|
0
|
1
|
0
|
unless ($self->{Bailed_Out}) { |
233
|
0
|
|
|
|
|
0
|
if ( $self->{Skip_All} ) { |
234
|
|
|
|
|
|
|
$self->parent->skip($self->{Skip_All}); |
235
|
0
|
0
|
|
|
|
0
|
} |
236
|
0
|
|
|
|
|
0
|
elsif ( not @{ $self->{Test_Results} } ) { |
237
|
|
|
|
|
|
|
$self->parent->ok( 0, sprintf q[No tests run for subtest "%s"], $self->name ); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
else { |
240
|
|
|
|
|
|
|
$self->parent->ok( $self->is_passing, $self->name ); |
241
|
0
|
|
|
|
|
0
|
} |
242
|
|
|
|
|
|
|
} |
243
|
0
|
|
|
|
|
0
|
$? = $self->{Child_Error}; |
244
|
|
|
|
|
|
|
delete $self->{Parent}; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
return $self->is_passing; |
247
|
0
|
|
|
|
|
0
|
} |
|
0
|
|
|
|
|
0
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub _indent { |
250
|
0
|
|
|
|
|
0
|
my $self = shift; |
251
|
0
|
|
|
|
|
0
|
|
252
|
0
|
|
|
|
|
0
|
if( @_ ) { |
253
|
|
|
|
|
|
|
$self->{Indent} = shift; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
0
|
|
0
|
return $self->{Indent}; |
257
|
0
|
|
|
|
|
0
|
} |
258
|
0
|
0
|
|
|
|
0
|
|
259
|
0
|
|
|
|
|
0
|
#line 389 |
260
|
0
|
|
|
|
|
0
|
|
261
|
|
|
|
|
|
|
sub parent { shift->{Parent} } |
262
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
263
|
0
|
|
|
|
|
0
|
#line 401 |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub name { shift->{Name} } |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub DESTROY { |
268
|
0
|
|
|
|
|
0
|
my $self = shift; |
269
|
0
|
|
|
|
|
0
|
if ( $self->parent and $$ == $self->{Original_Pid} ) { |
270
|
|
|
|
|
|
|
my $name = $self->name; |
271
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
272
|
0
|
|
|
|
|
0
|
Child ($name) exited without calling finalize() |
273
|
|
|
|
|
|
|
FAIL |
274
|
|
|
|
|
|
|
$self->parent->{In_Destroy} = 1; |
275
|
0
|
0
|
0
|
|
|
0
|
$self->parent->ok(0, $name); |
|
0
|
|
|
|
|
0
|
|
276
|
|
|
|
|
|
|
} |
277
|
0
|
|
|
|
|
0
|
} |
278
|
0
|
|
|
|
|
0
|
|
279
|
|
|
|
|
|
|
#line 425 |
280
|
0
|
0
|
|
|
|
0
|
|
281
|
|
|
|
|
|
|
our $Level; |
282
|
0
|
|
|
|
|
0
|
|
283
|
|
|
|
|
|
|
sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
284
|
|
|
|
|
|
|
my($self) = @_; |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
# We leave this a global because it has to be localized and localizing |
287
|
|
|
|
|
|
|
# hash keys is just asking for pain. Also, it was documented. |
288
|
|
|
|
|
|
|
$Level = 1; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
$self->{Name} = $0; |
291
|
|
|
|
|
|
|
$self->is_passing(1); |
292
|
|
|
|
|
|
|
$self->{Ending} = 0; |
293
|
|
|
|
|
|
|
$self->{Have_Plan} = 0; |
294
|
|
|
|
|
|
|
$self->{No_Plan} = 0; |
295
|
|
|
|
|
|
|
$self->{Have_Output_Plan} = 0; |
296
|
|
|
|
|
|
|
$self->{Done_Testing} = 0; |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
$self->{Original_Pid} = $$; |
299
|
|
|
|
|
|
|
$self->{Child_Name} = undef; |
300
|
|
|
|
|
|
|
$self->{Indent} ||= ''; |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
$self->{Curr_Test} = 0; |
303
|
|
|
|
|
|
|
$self->{Test_Results} = &share( [] ); |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
$self->{Exported_To} = undef; |
306
|
|
|
|
|
|
|
$self->{Expected_Tests} = 0; |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
$self->{Skip_All} = 0; |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
$self->{Use_Nums} = 1; |
311
|
0
|
|
|
0
|
|
0
|
|
312
|
0
|
|
0
|
|
|
0
|
$self->{No_Header} = 0; |
313
|
|
|
|
|
|
|
$self->{No_Ending} = 0; |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$self->{Todo} = undef; |
316
|
|
|
|
|
|
|
$self->{Todo_Stack} = []; |
317
|
|
|
|
|
|
|
$self->{Start_Todo} = 0; |
318
|
|
|
|
|
|
|
$self->{Opened_Testhandles} = 0; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
$self->_share_keys; |
321
|
|
|
|
|
|
|
$self->_dup_stdhandles; |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
return; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# Shared scalar values are lost when a hash is copied, so we have |
328
|
|
|
|
|
|
|
# a separate method to restore them. |
329
|
|
|
|
|
|
|
# Shared references are retained across copies. |
330
|
|
|
|
|
|
|
sub _share_keys { |
331
|
|
|
|
|
|
|
my $self = shift; |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
share( $self->{Curr_Test} ); |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
return; |
336
|
0
|
|
|
0
|
1
|
0
|
} |
337
|
|
|
|
|
|
|
|
338
|
0
|
0
|
|
|
|
0
|
|
339
|
0
|
0
|
|
|
|
0
|
#line 517 |
340
|
0
|
|
|
|
|
0
|
|
341
|
|
|
|
|
|
|
my %plan_cmds = ( |
342
|
|
|
|
|
|
|
no_plan => \&no_plan, |
343
|
0
|
|
|
|
|
0
|
skip_all => \&skip_all, |
344
|
0
|
|
|
|
|
0
|
tests => \&_plan_tests, |
345
|
|
|
|
|
|
|
); |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
sub plan { |
348
|
|
|
|
|
|
|
my( $self, $cmd, $arg ) = @_; |
349
|
0
|
|
|
|
|
0
|
|
350
|
0
|
|
|
|
|
0
|
return unless $cmd; |
351
|
0
|
|
|
|
|
0
|
|
352
|
0
|
0
|
|
|
|
0
|
local $Level = $Level + 1; |
353
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
354
|
0
|
|
|
|
|
0
|
$self->croak("You tried to plan twice") if $self->{Have_Plan}; |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
if( my $method = $plan_cmds{$cmd} ) { |
357
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
358
|
|
|
|
|
|
|
$self->$method($arg); |
359
|
|
|
|
|
|
|
} |
360
|
0
|
|
|
|
|
0
|
else { |
361
|
|
|
|
|
|
|
my @args = grep { defined } ( $cmd, $arg ); |
362
|
|
|
|
|
|
|
$self->croak("plan() doesn't understand @args"); |
363
|
0
|
|
|
|
|
0
|
} |
364
|
0
|
|
|
|
|
0
|
|
365
|
|
|
|
|
|
|
return 1; |
366
|
0
|
|
|
|
|
0
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
sub _plan_tests { |
370
|
102
|
|
|
102
|
|
259
|
my($self, $arg) = @_; |
371
|
|
|
|
|
|
|
|
372
|
102
|
50
|
|
|
|
248
|
if($arg) { |
373
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
374
|
|
|
|
|
|
|
return $self->expected_tests($arg); |
375
|
|
|
|
|
|
|
} |
376
|
102
|
|
|
|
|
254
|
elsif( !defined $arg ) { |
377
|
|
|
|
|
|
|
$self->croak("Got an undefined number of tests"); |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
else { |
380
|
|
|
|
|
|
|
$self->croak("You said to run 0 tests"); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
return; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
#line 572 |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
sub expected_tests { |
389
|
|
|
|
|
|
|
my $self = shift; |
390
|
0
|
|
|
0
|
1
|
0
|
my($max) = @_; |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
if(@_) { |
393
|
|
|
|
|
|
|
$self->croak("Number of tests must be a positive integer. You gave it '$max'") |
394
|
|
|
|
|
|
|
unless $max =~ /^\+?\d+$/; |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
$self->{Expected_Tests} = $max; |
397
|
|
|
|
|
|
|
$self->{Have_Plan} = 1; |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
$self->_output_plan($max) unless $self->no_header; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
return $self->{Expected_Tests}; |
402
|
0
|
|
|
0
|
1
|
0
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
#line 596 |
405
|
0
|
|
|
0
|
|
0
|
|
406
|
0
|
0
|
0
|
|
|
0
|
sub no_plan { |
407
|
0
|
|
|
|
|
0
|
my($self, $arg) = @_; |
408
|
0
|
|
|
|
|
0
|
|
409
|
|
|
|
|
|
|
$self->carp("no_plan takes no arguments") if $arg; |
410
|
|
|
|
|
|
|
|
411
|
0
|
|
|
|
|
0
|
$self->{No_Plan} = 1; |
412
|
0
|
|
|
|
|
0
|
$self->{Have_Plan} = 1; |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
return 1; |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
#line 629 |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
sub _output_plan { |
420
|
|
|
|
|
|
|
my($self, $max, $directive, $reason) = @_; |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
$self->carp("The plan was already output") if $self->{Have_Output_Plan}; |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
my $plan = "1..$max"; |
425
|
|
|
|
|
|
|
$plan .= " # $directive" if defined $directive; |
426
|
|
|
|
|
|
|
$plan .= " $reason" if defined $reason; |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
$self->_print("$plan\n"); |
429
|
14
|
|
|
14
|
1
|
36
|
|
430
|
|
|
|
|
|
|
$self->{Have_Output_Plan} = 1; |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
return; |
433
|
14
|
|
|
|
|
35
|
} |
434
|
|
|
|
|
|
|
|
435
|
14
|
|
|
|
|
165
|
|
436
|
14
|
|
|
|
|
60
|
#line 681 |
437
|
14
|
|
|
|
|
28
|
|
438
|
14
|
|
|
|
|
37
|
sub done_testing { |
439
|
14
|
|
|
|
|
37
|
my($self, $num_tests) = @_; |
440
|
14
|
|
|
|
|
36
|
|
441
|
14
|
|
|
|
|
33
|
# If done_testing() specified the number of tests, shut off no_plan. |
442
|
|
|
|
|
|
|
if( defined $num_tests ) { |
443
|
14
|
|
|
|
|
282
|
$self->{No_Plan} = 0; |
444
|
14
|
|
|
|
|
44
|
} |
445
|
14
|
|
50
|
|
|
198
|
else { |
446
|
|
|
|
|
|
|
$num_tests = $self->current_test; |
447
|
14
|
|
|
|
|
31
|
} |
448
|
14
|
|
|
|
|
61
|
|
449
|
|
|
|
|
|
|
if( $self->{Done_Testing} ) { |
450
|
14
|
|
|
|
|
32
|
my($file, $line) = @{$self->{Done_Testing}}[1,2]; |
451
|
14
|
|
|
|
|
31
|
$self->ok(0, "done_testing() was already called at $file line $line"); |
452
|
|
|
|
|
|
|
return; |
453
|
14
|
|
|
|
|
29
|
} |
454
|
|
|
|
|
|
|
|
455
|
14
|
|
|
|
|
51
|
$self->{Done_Testing} = [caller]; |
456
|
|
|
|
|
|
|
|
457
|
14
|
|
|
|
|
35
|
if( $self->expected_tests && $num_tests != $self->expected_tests ) { |
458
|
14
|
|
|
|
|
32
|
$self->ok(0, "planned to run @{[ $self->expected_tests ]} ". |
459
|
|
|
|
|
|
|
"but done_testing() expects $num_tests"); |
460
|
14
|
|
|
|
|
33
|
} |
461
|
14
|
|
|
|
|
38
|
else { |
462
|
14
|
|
|
|
|
34
|
$self->{Expected_Tests} = $num_tests; |
463
|
14
|
|
|
|
|
27
|
} |
464
|
|
|
|
|
|
|
|
465
|
14
|
|
|
|
|
62
|
$self->_output_plan($num_tests) unless $self->{Have_Output_Plan}; |
466
|
14
|
|
|
|
|
52
|
|
467
|
|
|
|
|
|
|
$self->{Have_Plan} = 1; |
468
|
14
|
|
|
|
|
25
|
|
469
|
|
|
|
|
|
|
# The wrong number of tests were run |
470
|
|
|
|
|
|
|
$self->is_passing(0) if $self->{Expected_Tests} != $self->{Curr_Test}; |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
# No tests were run |
473
|
|
|
|
|
|
|
$self->is_passing(0) if $self->{Curr_Test} == 0; |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
return 1; |
476
|
14
|
|
|
14
|
|
28
|
} |
477
|
|
|
|
|
|
|
|
478
|
14
|
|
|
|
|
49
|
|
479
|
|
|
|
|
|
|
#line 732 |
480
|
14
|
|
|
|
|
18
|
|
481
|
|
|
|
|
|
|
sub has_plan { |
482
|
|
|
|
|
|
|
my $self = shift; |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
return( $self->{Expected_Tests} ) if $self->{Expected_Tests}; |
485
|
|
|
|
|
|
|
return('no_plan') if $self->{No_Plan}; |
486
|
|
|
|
|
|
|
return(undef); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
#line 749 |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
sub skip_all { |
492
|
|
|
|
|
|
|
my( $self, $reason ) = @_; |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
$self->{Skip_All} = $self->parent ? $reason : 1; |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
$self->_output_plan(0, "SKIP", $reason) unless $self->no_header; |
497
|
|
|
|
|
|
|
if ( $self->parent ) { |
498
|
|
|
|
|
|
|
die bless {} => 'Test::Builder::Exception'; |
499
|
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
exit(0); |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
#line 774 |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
sub exported_to { |
506
|
|
|
|
|
|
|
my( $self, $pack ) = @_; |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
if( defined $pack ) { |
509
|
|
|
|
|
|
|
$self->{Exported_To} = $pack; |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
return $self->{Exported_To}; |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
#line 804 |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
sub ok { |
517
|
|
|
|
|
|
|
my( $self, $test, $name ) = @_; |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
if ( $self->{Child_Name} and not $self->{In_Destroy} ) { |
520
|
|
|
|
|
|
|
$name = 'unnamed test' unless defined $name; |
521
|
|
|
|
|
|
|
$self->is_passing(0); |
522
|
|
|
|
|
|
|
$self->croak("Cannot run test ($name) with active children"); |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
# $test might contain an object which we don't want to accidentally |
525
|
16
|
|
|
16
|
1
|
87
|
# store, so we turn it into a boolean. |
526
|
|
|
|
|
|
|
$test = $test ? 1 : 0; |
527
|
16
|
100
|
|
|
|
63
|
|
528
|
|
|
|
|
|
|
lock $self->{Curr_Test}; |
529
|
12
|
|
|
|
|
38
|
$self->{Curr_Test}++; |
530
|
|
|
|
|
|
|
|
531
|
12
|
50
|
|
|
|
58
|
# In case $name is a string overloaded object, force it to stringify. |
532
|
|
|
|
|
|
|
$self->_unoverload_str( \$name ); |
533
|
12
|
50
|
|
|
|
55
|
|
534
|
12
|
|
|
|
|
33
|
$self->diag(<<"ERR") if defined $name and $name =~ /^[\d\s]+$/; |
535
|
12
|
|
|
|
|
53
|
You named your test '$name'. You shouldn't use numbers for your test names. |
536
|
|
|
|
|
|
|
Very confusing. |
537
|
|
|
|
|
|
|
ERR |
538
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
539
|
0
|
|
|
|
|
0
|
# Capture the value of $TODO for the rest of this ok() call |
540
|
|
|
|
|
|
|
# so it can more easily be found by other routines. |
541
|
|
|
|
|
|
|
my $todo = $self->todo(); |
542
|
12
|
|
|
|
|
2400
|
my $in_todo = $self->in_todo; |
543
|
|
|
|
|
|
|
local $self->{Todo} = $todo if $in_todo; |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
$self->_unoverload_str( \$todo ); |
546
|
|
|
|
|
|
|
|
547
|
12
|
|
|
12
|
|
30
|
my $out; |
548
|
|
|
|
|
|
|
my $result = &share( {} ); |
549
|
12
|
50
|
|
|
|
40
|
|
|
|
0
|
|
|
|
|
|
550
|
12
|
|
|
|
|
28
|
unless($test) { |
551
|
12
|
|
|
|
|
51
|
$out .= "not "; |
552
|
|
|
|
|
|
|
@$result{ 'ok', 'actual_ok' } = ( ( $self->in_todo ? 1 : 0 ), 0 ); |
553
|
|
|
|
|
|
|
} |
554
|
0
|
|
|
|
|
0
|
else { |
555
|
|
|
|
|
|
|
@$result{ 'ok', 'actual_ok' } = ( 1, $test ); |
556
|
|
|
|
|
|
|
} |
557
|
0
|
|
|
|
|
0
|
|
558
|
|
|
|
|
|
|
$out .= "ok"; |
559
|
|
|
|
|
|
|
$out .= " $self->{Curr_Test}" if $self->use_numbers; |
560
|
0
|
|
|
|
|
0
|
|
561
|
|
|
|
|
|
|
if( defined $name ) { |
562
|
|
|
|
|
|
|
$name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. |
563
|
|
|
|
|
|
|
$out .= " - $name"; |
564
|
|
|
|
|
|
|
$result->{name} = $name; |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
else { |
567
|
|
|
|
|
|
|
$result->{name} = ''; |
568
|
|
|
|
|
|
|
} |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
if( $self->in_todo ) { |
571
|
|
|
|
|
|
|
$out .= " # TODO $todo"; |
572
|
|
|
|
|
|
|
$result->{reason} = $todo; |
573
|
|
|
|
|
|
|
$result->{type} = 'todo'; |
574
|
12
|
|
|
12
|
1
|
28
|
} |
575
|
12
|
|
|
|
|
44
|
else { |
576
|
|
|
|
|
|
|
$result->{reason} = ''; |
577
|
12
|
50
|
|
|
|
89
|
$result->{type} = ''; |
578
|
12
|
50
|
|
|
|
103
|
} |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
$self->{Test_Results}[ $self->{Curr_Test} - 1 ] = $result; |
581
|
12
|
|
|
|
|
36
|
$out .= "\n"; |
582
|
12
|
|
|
|
|
25
|
|
583
|
|
|
|
|
|
|
$self->_print($out); |
584
|
12
|
50
|
|
|
|
56
|
|
585
|
|
|
|
|
|
|
unless($test) { |
586
|
12
|
|
|
|
|
52
|
my $msg = $self->in_todo ? "Failed (TODO)" : "Failed"; |
587
|
|
|
|
|
|
|
$self->_print_to_fh( $self->_diag_fh, "\n" ) if $ENV{HARNESS_ACTIVE}; |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
my( undef, $file, $line ) = $self->caller; |
590
|
|
|
|
|
|
|
if( defined $name ) { |
591
|
|
|
|
|
|
|
$self->diag(qq[ $msg test '$name'\n]); |
592
|
|
|
|
|
|
|
$self->diag(qq[ at $file line $line.\n]); |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
else { |
595
|
|
|
|
|
|
|
$self->diag(qq[ $msg test at $file line $line.\n]); |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
} |
598
|
0
|
|
|
0
|
1
|
0
|
|
599
|
|
|
|
|
|
|
$self->is_passing(0) unless $test || $self->in_todo; |
600
|
0
|
0
|
|
|
|
0
|
|
601
|
|
|
|
|
|
|
# Check that we haven't violated the plan |
602
|
0
|
|
|
|
|
0
|
$self->_check_is_passing_plan(); |
603
|
0
|
|
|
|
|
0
|
|
604
|
|
|
|
|
|
|
return $test ? 1 : 0; |
605
|
0
|
|
|
|
|
0
|
} |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
# Check that we haven't yet violated the plan and set |
609
|
|
|
|
|
|
|
# is_passing() accordingly |
610
|
|
|
|
|
|
|
sub _check_is_passing_plan { |
611
|
|
|
|
|
|
|
my $self = shift; |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
my $plan = $self->has_plan; |
614
|
|
|
|
|
|
|
return unless defined $plan; # no plan yet defined |
615
|
|
|
|
|
|
|
return unless $plan !~ /\D/; # no numeric plan |
616
|
|
|
|
|
|
|
$self->is_passing(0) if $plan < $self->{Curr_Test}; |
617
|
|
|
|
|
|
|
} |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
sub _unoverload { |
621
|
|
|
|
|
|
|
my $self = shift; |
622
|
|
|
|
|
|
|
my $type = shift; |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
$self->_try(sub { require overload; }, die_on_fail => 1); |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
foreach my $thing (@_) { |
627
|
|
|
|
|
|
|
if( $self->_is_object($$thing) ) { |
628
|
|
|
|
|
|
|
if( my $string_meth = overload::Method( $$thing, $type ) ) { |
629
|
|
|
|
|
|
|
$$thing = $$thing->$string_meth(); |
630
|
|
|
|
|
|
|
} |
631
|
12
|
|
|
12
|
|
34
|
} |
632
|
|
|
|
|
|
|
} |
633
|
12
|
50
|
|
|
|
103
|
|
634
|
|
|
|
|
|
|
return; |
635
|
12
|
|
|
|
|
38
|
} |
636
|
12
|
50
|
|
|
|
47
|
|
637
|
12
|
50
|
|
|
|
42
|
sub _is_object { |
638
|
|
|
|
|
|
|
my( $self, $thing ) = @_; |
639
|
12
|
|
|
|
|
118
|
|
640
|
|
|
|
|
|
|
return $self->_try( sub { ref $thing && $thing->isa('UNIVERSAL') } ) ? 1 : 0; |
641
|
12
|
|
|
|
|
41
|
} |
642
|
|
|
|
|
|
|
|
643
|
12
|
|
|
|
|
44
|
sub _unoverload_str { |
644
|
|
|
|
|
|
|
my $self = shift; |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
return $self->_unoverload( q[""], @_ ); |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
sub _unoverload_num { |
650
|
|
|
|
|
|
|
my $self = shift; |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
$self->_unoverload( '0+', @_ ); |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
for my $val (@_) { |
655
|
|
|
|
|
|
|
next unless $self->_is_dualvar($$val); |
656
|
|
|
|
|
|
|
$$val = $$val + 0; |
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
return; |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
# This is a hack to detect a dualvar such as $! |
663
|
|
|
|
|
|
|
sub _is_dualvar { |
664
|
|
|
|
|
|
|
my( $self, $val ) = @_; |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
# Objects are not dualvars. |
667
|
|
|
|
|
|
|
return 0 if ref $val; |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
no warnings 'numeric'; |
670
|
|
|
|
|
|
|
my $numval = $val + 0; |
671
|
|
|
|
|
|
|
return ($numval != 0 and $numval ne $val ? 1 : 0); |
672
|
|
|
|
|
|
|
} |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
#line 982 |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
sub is_eq { |
677
|
|
|
|
|
|
|
my( $self, $got, $expect, $name ) = @_; |
678
|
|
|
|
|
|
|
local $Level = $Level + 1; |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
if( !defined $got || !defined $expect ) { |
681
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
682
|
|
|
|
|
|
|
my $test = !defined $got && !defined $expect; |
683
|
0
|
|
|
0
|
1
|
0
|
|
684
|
|
|
|
|
|
|
$self->ok( $test, $name ); |
685
|
|
|
|
|
|
|
$self->_is_diag( $got, 'eq', $expect ) unless $test; |
686
|
0
|
0
|
|
|
|
0
|
return $test; |
687
|
0
|
|
|
|
|
0
|
} |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
return $self->cmp_ok( $got, 'eq', $expect, $name ); |
690
|
0
|
|
|
|
|
0
|
} |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
sub is_num { |
693
|
0
|
0
|
|
|
|
0
|
my( $self, $got, $expect, $name ) = @_; |
694
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
|
0
|
|
|
|
|
0
|
|
695
|
0
|
|
|
|
|
0
|
|
696
|
0
|
|
|
|
|
0
|
if( !defined $got || !defined $expect ) { |
697
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
698
|
|
|
|
|
|
|
my $test = !defined $got && !defined $expect; |
699
|
0
|
|
|
|
|
0
|
|
700
|
|
|
|
|
|
|
$self->ok( $test, $name ); |
701
|
0
|
0
|
0
|
|
|
0
|
$self->_is_diag( $got, '==', $expect ) unless $test; |
702
|
0
|
|
|
|
|
0
|
return $test; |
|
0
|
|
|
|
|
0
|
|
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
return $self->cmp_ok( $got, '==', $expect, $name ); |
706
|
0
|
|
|
|
|
0
|
} |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
sub _diag_fmt { |
709
|
0
|
0
|
|
|
|
0
|
my( $self, $type, $val ) = @_; |
710
|
|
|
|
|
|
|
|
711
|
0
|
|
|
|
|
0
|
if( defined $$val ) { |
712
|
|
|
|
|
|
|
if( $type eq 'eq' or $type eq 'ne' ) { |
713
|
|
|
|
|
|
|
# quote and force string context |
714
|
0
|
0
|
|
|
|
0
|
$$val = "'$$val'"; |
715
|
|
|
|
|
|
|
} |
716
|
|
|
|
|
|
|
else { |
717
|
0
|
0
|
|
|
|
0
|
# force numeric context |
718
|
|
|
|
|
|
|
$self->_unoverload_num($val); |
719
|
0
|
|
|
|
|
0
|
} |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
else { |
722
|
|
|
|
|
|
|
$$val = 'undef'; |
723
|
|
|
|
|
|
|
} |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
return; |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
sub _is_diag { |
729
|
|
|
|
|
|
|
my( $self, $got, $type, $expect ) = @_; |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
$self->_diag_fmt( $type, $_ ) for \$got, \$expect; |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
local $Level = $Level + 1; |
734
|
63
|
|
|
63
|
1
|
114
|
return $self->diag(<<"DIAGNOSTIC"); |
735
|
|
|
|
|
|
|
got: $got |
736
|
63
|
50
|
|
|
|
261
|
expected: $expect |
737
|
0
|
0
|
|
|
|
0
|
DIAGNOSTIC |
738
|
0
|
|
|
|
|
0
|
|
739
|
|
|
|
|
|
|
} |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
sub _isnt_diag { |
742
|
|
|
|
|
|
|
my( $self, $got, $type ) = @_; |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
$self->_diag_fmt( $type, \$got ); |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
local $Level = $Level + 1; |
747
|
|
|
|
|
|
|
return $self->diag(<<"DIAGNOSTIC"); |
748
|
|
|
|
|
|
|
got: $got |
749
|
|
|
|
|
|
|
expected: anything else |
750
|
|
|
|
|
|
|
DIAGNOSTIC |
751
|
0
|
|
|
0
|
1
|
0
|
} |
752
|
|
|
|
|
|
|
|
753
|
0
|
0
|
|
|
|
0
|
#line 1075 |
754
|
|
|
|
|
|
|
|
755
|
0
|
0
|
|
|
|
0
|
sub isnt_eq { |
756
|
0
|
0
|
|
|
|
0
|
my( $self, $got, $dont_expect, $name ) = @_; |
757
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
758
|
|
|
|
|
|
|
|
759
|
0
|
|
|
|
|
0
|
if( !defined $got || !defined $dont_expect ) { |
760
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
761
|
|
|
|
|
|
|
my $test = defined $got || defined $dont_expect; |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
$self->ok( $test, $name ); |
764
|
|
|
|
|
|
|
$self->_isnt_diag( $got, 'ne' ) unless $test; |
765
|
|
|
|
|
|
|
return $test; |
766
|
|
|
|
|
|
|
} |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
return $self->cmp_ok( $got, 'ne', $dont_expect, $name ); |
769
|
|
|
|
|
|
|
} |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
sub isnt_num { |
772
|
|
|
|
|
|
|
my( $self, $got, $dont_expect, $name ) = @_; |
773
|
|
|
|
|
|
|
local $Level = $Level + 1; |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
if( !defined $got || !defined $dont_expect ) { |
776
|
14
|
|
|
14
|
1
|
41
|
# undef only matches undef and nothing else |
777
|
|
|
|
|
|
|
my $test = defined $got || defined $dont_expect; |
778
|
14
|
50
|
|
|
|
70
|
|
779
|
14
|
|
|
|
|
66
|
$self->ok( $test, $name ); |
780
|
|
|
|
|
|
|
$self->_isnt_diag( $got, '!=' ) unless $test; |
781
|
14
|
|
|
|
|
50
|
return $test; |
782
|
|
|
|
|
|
|
} |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
return $self->cmp_ok( $got, '!=', $dont_expect, $name ); |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
#line 1124 |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
sub like { |
790
|
|
|
|
|
|
|
my( $self, $thing, $regex, $name ) = @_; |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
local $Level = $Level + 1; |
793
|
|
|
|
|
|
|
return $self->_regex_ok( $thing, $regex, '=~', $name ); |
794
|
|
|
|
|
|
|
} |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
sub unlike { |
797
|
|
|
|
|
|
|
my( $self, $thing, $regex, $name ) = @_; |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
local $Level = $Level + 1; |
800
|
|
|
|
|
|
|
return $self->_regex_ok( $thing, $regex, '!~', $name ); |
801
|
|
|
|
|
|
|
} |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
#line 1148 |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
my %numeric_cmps = map { ( $_, 1 ) } ( "<", "<=", ">", ">=", "==", "!=", "<=>" ); |
806
|
63
|
|
|
63
|
1
|
123
|
|
807
|
|
|
|
|
|
|
# Bad, these are not comparison operators. Should we include more? |
808
|
63
|
50
|
33
|
|
|
227
|
my %cmp_ok_bl = map { ( $_, 1 ) } ( "=", "+=", ".=", "x=", "^=", "|=", "||=", "&&=", "..."); |
809
|
0
|
0
|
|
|
|
0
|
|
810
|
0
|
|
|
|
|
0
|
sub cmp_ok { |
811
|
0
|
|
|
|
|
0
|
my( $self, $got, $type, $expect, $name ) = @_; |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
if ($cmp_ok_bl{$type}) { |
814
|
|
|
|
|
|
|
$self->croak("$type is not a valid comparison operator in cmp_ok()"); |
815
|
63
|
100
|
|
|
|
136
|
} |
816
|
|
|
|
|
|
|
|
817
|
63
|
|
|
|
|
185
|
my $test; |
818
|
63
|
|
|
|
|
96
|
my $error; |
819
|
|
|
|
|
|
|
{ |
820
|
|
|
|
|
|
|
## no critic (BuiltinFunctions::ProhibitStringyEval) |
821
|
63
|
|
|
|
|
191
|
|
822
|
|
|
|
|
|
|
local( $@, $!, $SIG{__DIE__} ); # isolate eval |
823
|
63
|
50
|
33
|
|
|
508
|
|
824
|
|
|
|
|
|
|
my($pack, $file, $line) = $self->caller(); |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
# This is so that warnings come out at the caller's level |
827
|
|
|
|
|
|
|
$test = eval qq[ |
828
|
|
|
|
|
|
|
#line $line "(eval in cmp_ok) $file" |
829
|
|
|
|
|
|
|
\$got $type \$expect; |
830
|
63
|
|
|
|
|
210
|
]; |
831
|
63
|
|
|
|
|
161
|
$error = $@; |
832
|
63
|
50
|
|
|
|
149
|
} |
833
|
|
|
|
|
|
|
local $Level = $Level + 1; |
834
|
63
|
|
|
|
|
147
|
my $ok = $self->ok( $test, $name ); |
835
|
|
|
|
|
|
|
|
836
|
63
|
|
|
|
|
83
|
# Treat overloaded objects as numbers if we're asked to do a |
837
|
63
|
|
|
|
|
163
|
# numeric comparison. |
838
|
|
|
|
|
|
|
my $unoverload |
839
|
63
|
100
|
|
|
|
143
|
= $numeric_cmps{$type} |
840
|
3
|
|
|
|
|
8
|
? '_unoverload_num' |
841
|
3
|
50
|
|
|
|
12
|
: '_unoverload_str'; |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
$self->diag(<<"END") if $error; |
844
|
60
|
|
|
|
|
204
|
An error occurred while using $type: |
845
|
|
|
|
|
|
|
------------------------------------ |
846
|
|
|
|
|
|
|
$error |
847
|
63
|
|
|
|
|
116
|
------------------------------------ |
848
|
63
|
50
|
|
|
|
161
|
END |
849
|
|
|
|
|
|
|
|
850
|
63
|
50
|
|
|
|
136
|
unless($ok) { |
851
|
63
|
|
|
|
|
117
|
$self->$unoverload( \$got, \$expect ); |
852
|
63
|
|
|
|
|
113
|
|
853
|
63
|
|
|
|
|
138
|
if( $type =~ /^(eq|==)$/ ) { |
854
|
|
|
|
|
|
|
$self->_is_diag( $got, $type, $expect ); |
855
|
|
|
|
|
|
|
} |
856
|
0
|
|
|
|
|
0
|
elsif( $type =~ /^(ne|!=)$/ ) { |
857
|
|
|
|
|
|
|
$self->_isnt_diag( $got, $type ); |
858
|
|
|
|
|
|
|
} |
859
|
63
|
50
|
|
|
|
128
|
else { |
860
|
0
|
|
|
|
|
0
|
$self->_cmp_diag( $got, $type, $expect ); |
861
|
0
|
|
|
|
|
0
|
} |
862
|
0
|
|
|
|
|
0
|
} |
863
|
|
|
|
|
|
|
return $ok; |
864
|
|
|
|
|
|
|
} |
865
|
63
|
|
|
|
|
142
|
|
866
|
63
|
|
|
|
|
128
|
sub _cmp_diag { |
867
|
|
|
|
|
|
|
my( $self, $got, $type, $expect ) = @_; |
868
|
|
|
|
|
|
|
|
869
|
63
|
|
|
|
|
194
|
$got = defined $got ? "'$got'" : 'undef'; |
870
|
63
|
|
|
|
|
86
|
$expect = defined $expect ? "'$expect'" : 'undef'; |
871
|
|
|
|
|
|
|
|
872
|
63
|
|
|
|
|
160
|
local $Level = $Level + 1; |
873
|
|
|
|
|
|
|
return $self->diag(<<"DIAGNOSTIC"); |
874
|
63
|
100
|
|
|
|
190
|
$got |
875
|
3
|
50
|
|
|
|
9
|
$type |
876
|
3
|
50
|
|
|
|
26
|
$expect |
877
|
|
|
|
|
|
|
DIAGNOSTIC |
878
|
3
|
|
|
|
|
14
|
} |
879
|
3
|
50
|
|
|
|
14
|
|
880
|
3
|
|
|
|
|
20
|
sub _caller_context { |
881
|
3
|
|
|
|
|
34
|
my $self = shift; |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
my( $pack, $file, $line ) = $self->caller(1); |
884
|
0
|
|
|
|
|
0
|
|
885
|
|
|
|
|
|
|
my $code = ''; |
886
|
|
|
|
|
|
|
$code .= "#line $line $file\n" if defined $file and defined $line; |
887
|
|
|
|
|
|
|
|
888
|
63
|
100
|
66
|
|
|
170
|
return $code; |
889
|
|
|
|
|
|
|
} |
890
|
|
|
|
|
|
|
|
891
|
63
|
|
|
|
|
159
|
#line 1255 |
892
|
|
|
|
|
|
|
|
893
|
63
|
100
|
|
|
|
218
|
sub BAIL_OUT { |
894
|
|
|
|
|
|
|
my( $self, $reason ) = @_; |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
$self->{Bailed_Out} = 1; |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
if ($self->parent) { |
899
|
|
|
|
|
|
|
$self->{Bailed_Out_Reason} = $reason; |
900
|
63
|
|
|
63
|
|
82
|
$self->no_ending(1); |
901
|
|
|
|
|
|
|
die bless {} => 'Test::Builder::Exception'; |
902
|
63
|
|
|
|
|
155
|
} |
903
|
63
|
50
|
|
|
|
148
|
|
904
|
63
|
50
|
|
|
|
198
|
$self->_print("Bail out! $reason"); |
905
|
63
|
50
|
|
|
|
187
|
exit 255; |
906
|
|
|
|
|
|
|
} |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
#line 1275 |
909
|
|
|
|
|
|
|
|
910
|
126
|
|
|
126
|
|
3882
|
{ |
911
|
126
|
|
|
|
|
176
|
no warnings 'once'; |
912
|
|
|
|
|
|
|
*BAILOUT = \&BAIL_OUT; |
913
|
126
|
|
|
126
|
|
729
|
} |
|
126
|
|
|
|
|
2684
|
|
914
|
|
|
|
|
|
|
|
915
|
126
|
|
|
|
|
408
|
#line 1289 |
916
|
126
|
50
|
|
|
|
492
|
|
917
|
0
|
0
|
|
|
|
0
|
sub skip { |
918
|
0
|
|
|
|
|
0
|
my( $self, $why ) = @_; |
919
|
|
|
|
|
|
|
$why ||= ''; |
920
|
|
|
|
|
|
|
$self->_unoverload_str( \$why ); |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
lock( $self->{Curr_Test} ); |
923
|
126
|
|
|
|
|
269
|
$self->{Curr_Test}++; |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
$self->{Test_Results}[ $self->{Curr_Test} - 1 ] = &share( |
926
|
|
|
|
|
|
|
{ |
927
|
126
|
|
|
126
|
|
199
|
'ok' => 1, |
928
|
|
|
|
|
|
|
actual_ok => 1, |
929
|
126
|
50
|
|
126
|
|
477
|
name => '', |
|
126
|
50
|
|
|
|
466
|
|
930
|
|
|
|
|
|
|
type => 'skip', |
931
|
|
|
|
|
|
|
reason => $why, |
932
|
|
|
|
|
|
|
} |
933
|
126
|
|
|
126
|
|
167
|
); |
934
|
|
|
|
|
|
|
|
935
|
126
|
|
|
|
|
299
|
my $out = "ok"; |
936
|
|
|
|
|
|
|
$out .= " $self->{Curr_Test}" if $self->use_numbers; |
937
|
|
|
|
|
|
|
$out .= " # skip"; |
938
|
|
|
|
|
|
|
$out .= " $why" if length $why; |
939
|
0
|
|
|
0
|
|
0
|
$out .= "\n"; |
940
|
|
|
|
|
|
|
|
941
|
0
|
|
|
|
|
0
|
$self->_print($out); |
942
|
|
|
|
|
|
|
|
943
|
0
|
|
|
|
|
0
|
return 1; |
944
|
0
|
0
|
|
|
|
0
|
} |
945
|
0
|
|
|
|
|
0
|
|
946
|
|
|
|
|
|
|
#line 1330 |
947
|
|
|
|
|
|
|
|
948
|
0
|
|
|
|
|
0
|
sub todo_skip { |
949
|
|
|
|
|
|
|
my( $self, $why ) = @_; |
950
|
|
|
|
|
|
|
$why ||= ''; |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
lock( $self->{Curr_Test} ); |
953
|
0
|
|
|
0
|
|
0
|
$self->{Curr_Test}++; |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
$self->{Test_Results}[ $self->{Curr_Test} - 1 ] = &share( |
956
|
0
|
0
|
|
|
|
0
|
{ |
957
|
|
|
|
|
|
|
'ok' => 1, |
958
|
14
|
|
|
14
|
|
397
|
actual_ok => 0, |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
34431
|
|
959
|
0
|
|
|
|
|
0
|
name => '', |
960
|
0
|
|
0
|
|
|
0
|
type => 'todo_skip', |
961
|
|
|
|
|
|
|
reason => $why, |
962
|
|
|
|
|
|
|
} |
963
|
|
|
|
|
|
|
); |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
my $out = "not ok"; |
966
|
|
|
|
|
|
|
$out .= " $self->{Curr_Test}" if $self->use_numbers; |
967
|
|
|
|
|
|
|
$out .= " # TODO & SKIP $why\n"; |
968
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
$self->_print($out); |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
return 1; |
972
|
|
|
|
|
|
|
} |
973
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
#line 1410 |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
sub maybe_regex { |
977
|
|
|
|
|
|
|
my( $self, $regex ) = @_; |
978
|
|
|
|
|
|
|
my $usable_regex = undef; |
979
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
return $usable_regex unless defined $regex; |
981
|
|
|
|
|
|
|
|
982
|
|
|
|
|
|
|
my( $re, $opts ); |
983
|
|
|
|
|
|
|
|
984
|
53
|
|
|
53
|
1
|
118
|
# Check for qr/foo/ |
985
|
53
|
|
|
|
|
96
|
if( _is_qr($regex) ) { |
986
|
|
|
|
|
|
|
$usable_regex = $regex; |
987
|
53
|
50
|
33
|
|
|
242
|
} |
988
|
|
|
|
|
|
|
# Check for '/foo/' or 'm,foo,' |
989
|
0
|
|
0
|
|
|
0
|
elsif(( $re, $opts ) = $regex =~ m{^ /(.*)/ (\w*) $ }sx or |
990
|
|
|
|
|
|
|
( undef, $re, $opts ) = $regex =~ m,^ m([^\w\s]) (.+) \1 (\w*) $,sx |
991
|
0
|
|
|
|
|
0
|
) |
992
|
0
|
0
|
|
|
|
0
|
{ |
993
|
0
|
|
|
|
|
0
|
$usable_regex = length $opts ? "(?$opts)$re" : $re; |
994
|
|
|
|
|
|
|
} |
995
|
|
|
|
|
|
|
|
996
|
53
|
|
|
|
|
151
|
return $usable_regex; |
997
|
|
|
|
|
|
|
} |
998
|
|
|
|
|
|
|
|
999
|
|
|
|
|
|
|
sub _is_qr { |
1000
|
0
|
|
|
0
|
1
|
0
|
my $regex = shift; |
1001
|
0
|
|
|
|
|
0
|
|
1002
|
|
|
|
|
|
|
# is_regexp() checks for regexes in a robust manner, say if they're |
1003
|
0
|
0
|
0
|
|
|
0
|
# blessed. |
1004
|
|
|
|
|
|
|
return re::is_regexp($regex) if defined &re::is_regexp; |
1005
|
0
|
|
0
|
|
|
0
|
return ref $regex eq 'Regexp'; |
1006
|
|
|
|
|
|
|
} |
1007
|
0
|
|
|
|
|
0
|
|
1008
|
0
|
0
|
|
|
|
0
|
sub _regex_ok { |
1009
|
0
|
|
|
|
|
0
|
my( $self, $thing, $regex, $cmp, $name ) = @_; |
1010
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
my $ok = 0; |
1012
|
0
|
|
|
|
|
0
|
my $usable_regex = $self->maybe_regex($regex); |
1013
|
|
|
|
|
|
|
unless( defined $usable_regex ) { |
1014
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1015
|
|
|
|
|
|
|
$ok = $self->ok( 0, $name ); |
1016
|
0
|
|
|
0
|
|
0
|
$self->diag(" '$regex' doesn't look much like a regex to me."); |
1017
|
|
|
|
|
|
|
return $ok; |
1018
|
0
|
0
|
|
|
|
0
|
} |
1019
|
0
|
0
|
0
|
|
|
0
|
|
1020
|
|
|
|
|
|
|
{ |
1021
|
0
|
|
|
|
|
0
|
my $test; |
1022
|
|
|
|
|
|
|
my $context = $self->_caller_context; |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
{ |
1025
|
0
|
|
|
|
|
0
|
## no critic (BuiltinFunctions::ProhibitStringyEval) |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
local( $@, $!, $SIG{__DIE__} ); # isolate eval |
1028
|
|
|
|
|
|
|
|
1029
|
0
|
|
|
|
|
0
|
# No point in issuing an uninit warning, they'll see it in the diagnostics |
1030
|
|
|
|
|
|
|
no warnings 'uninitialized'; |
1031
|
|
|
|
|
|
|
|
1032
|
0
|
|
|
|
|
0
|
$test = eval $context . q{$test = $thing =~ /$usable_regex/ ? 1 : 0}; |
1033
|
|
|
|
|
|
|
} |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
$test = !$test if $cmp eq '!~'; |
1036
|
0
|
|
|
0
|
|
0
|
|
1037
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1038
|
0
|
|
|
|
|
0
|
$ok = $self->ok( $test, $name ); |
1039
|
|
|
|
|
|
|
} |
1040
|
0
|
|
|
|
|
0
|
|
1041
|
0
|
|
|
|
|
0
|
unless($ok) { |
1042
|
|
|
|
|
|
|
$thing = defined $thing ? "'$thing'" : 'undef'; |
1043
|
|
|
|
|
|
|
my $match = $cmp eq '=~' ? "doesn't match" : "matches"; |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1046
|
|
|
|
|
|
|
$self->diag( sprintf <<'DIAGNOSTIC', $thing, $match, $regex ); |
1047
|
|
|
|
|
|
|
%s |
1048
|
|
|
|
|
|
|
%13s '%s' |
1049
|
0
|
|
|
0
|
|
0
|
DIAGNOSTIC |
1050
|
|
|
|
|
|
|
|
1051
|
0
|
|
|
|
|
0
|
} |
1052
|
|
|
|
|
|
|
|
1053
|
0
|
|
|
|
|
0
|
return $ok; |
1054
|
0
|
|
|
|
|
0
|
} |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
# I'm not ready to publish this. It doesn't deal with array return |
1057
|
|
|
|
|
|
|
# values from the code or context. |
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
#line 1511 |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
sub _try { |
1062
|
|
|
|
|
|
|
my( $self, $code, %opts ) = @_; |
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
my $error; |
1065
|
|
|
|
|
|
|
my $return; |
1066
|
|
|
|
|
|
|
{ |
1067
|
|
|
|
|
|
|
local $!; # eval can mess up $! |
1068
|
|
|
|
|
|
|
local $@; # don't set $@ in the test |
1069
|
|
|
|
|
|
|
local $SIG{__DIE__}; # don't trip an outside DIE handler. |
1070
|
|
|
|
|
|
|
$return = eval { $code->() }; |
1071
|
|
|
|
|
|
|
$error = $@; |
1072
|
|
|
|
|
|
|
} |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
die $error if $error and $opts{die_on_fail}; |
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
return wantarray ? ( $return, $error ) : $return; |
1077
|
0
|
|
|
0
|
1
|
0
|
} |
1078
|
0
|
|
|
|
|
0
|
|
1079
|
|
|
|
|
|
|
#line 1540 |
1080
|
0
|
0
|
0
|
|
|
0
|
|
1081
|
|
|
|
|
|
|
sub is_fh { |
1082
|
0
|
|
0
|
|
|
0
|
my $self = shift; |
1083
|
|
|
|
|
|
|
my $maybe_fh = shift; |
1084
|
0
|
|
|
|
|
0
|
return 0 unless defined $maybe_fh; |
1085
|
0
|
0
|
|
|
|
0
|
|
1086
|
0
|
|
|
|
|
0
|
return 1 if ref $maybe_fh eq 'GLOB'; # its a glob ref |
1087
|
|
|
|
|
|
|
return 1 if ref \$maybe_fh eq 'GLOB'; # its a glob |
1088
|
|
|
|
|
|
|
|
1089
|
0
|
|
|
|
|
0
|
return eval { $maybe_fh->isa("IO::Handle") } || |
1090
|
|
|
|
|
|
|
eval { tied($maybe_fh)->can('TIEHANDLE') }; |
1091
|
|
|
|
|
|
|
} |
1092
|
|
|
|
|
|
|
|
1093
|
0
|
|
|
0
|
1
|
0
|
#line 1583 |
1094
|
0
|
|
|
|
|
0
|
|
1095
|
|
|
|
|
|
|
sub level { |
1096
|
0
|
0
|
0
|
|
|
0
|
my( $self, $level ) = @_; |
1097
|
|
|
|
|
|
|
|
1098
|
0
|
|
0
|
|
|
0
|
if( defined $level ) { |
1099
|
|
|
|
|
|
|
$Level = $level; |
1100
|
0
|
|
|
|
|
0
|
} |
1101
|
0
|
0
|
|
|
|
0
|
return $Level; |
1102
|
0
|
|
|
|
|
0
|
} |
1103
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
#line 1615 |
1105
|
0
|
|
|
|
|
0
|
|
1106
|
|
|
|
|
|
|
sub use_numbers { |
1107
|
|
|
|
|
|
|
my( $self, $use_nums ) = @_; |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
if( defined $use_nums ) { |
1110
|
|
|
|
|
|
|
$self->{Use_Nums} = $use_nums; |
1111
|
|
|
|
|
|
|
} |
1112
|
|
|
|
|
|
|
return $self->{Use_Nums}; |
1113
|
|
|
|
|
|
|
} |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
#line 1648 |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
foreach my $attribute (qw(No_Header No_Ending No_Diag)) { |
1118
|
|
|
|
|
|
|
my $method = lc $attribute; |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
my $code = sub { |
1121
|
|
|
|
|
|
|
my( $self, $no ) = @_; |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
if( defined $no ) { |
1124
|
|
|
|
|
|
|
$self->{$attribute} = $no; |
1125
|
|
|
|
|
|
|
} |
1126
|
0
|
|
|
0
|
1
|
0
|
return $self->{$attribute}; |
1127
|
|
|
|
|
|
|
}; |
1128
|
0
|
|
|
|
|
0
|
|
1129
|
0
|
|
|
|
|
0
|
no strict 'refs'; ## no critic |
1130
|
|
|
|
|
|
|
*{ __PACKAGE__ . '::' . $method } = $code; |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
|
1133
|
0
|
|
|
0
|
1
|
0
|
#line 1701 |
1134
|
|
|
|
|
|
|
|
1135
|
0
|
|
|
|
|
0
|
sub diag { |
1136
|
0
|
|
|
|
|
0
|
my $self = shift; |
1137
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
$self->_print_comment( $self->_diag_fh, @_ ); |
1139
|
|
|
|
|
|
|
} |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
#line 1716 |
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
sub note { |
1144
|
|
|
|
|
|
|
my $self = shift; |
1145
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
$self->_print_comment( $self->output, @_ ); |
1147
|
|
|
|
|
|
|
} |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
sub _diag_fh { |
1150
|
|
|
|
|
|
|
my $self = shift; |
1151
|
|
|
|
|
|
|
|
1152
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1153
|
|
|
|
|
|
|
return $self->in_todo ? $self->todo_output : $self->failure_output; |
1154
|
|
|
|
|
|
|
} |
1155
|
53
|
|
|
53
|
1
|
98
|
|
1156
|
|
|
|
|
|
|
sub _print_comment { |
1157
|
53
|
50
|
|
|
|
147
|
my( $self, $fh, @msgs ) = @_; |
1158
|
0
|
|
|
|
|
0
|
|
1159
|
|
|
|
|
|
|
return if $self->no_diag; |
1160
|
|
|
|
|
|
|
return unless @msgs; |
1161
|
53
|
|
|
|
|
58
|
|
1162
|
|
|
|
|
|
|
# Prevent printing headers when compiling (i.e. -c) |
1163
|
|
|
|
|
|
|
return if $^C; |
1164
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
# Smash args together like print does. |
1166
|
53
|
|
|
|
|
116
|
# Convert undef to 'undef' so its readable. |
|
53
|
|
|
|
|
316
|
|
1167
|
|
|
|
|
|
|
my $msg = join '', map { defined($_) ? $_ : 'undef' } @msgs; |
1168
|
53
|
|
|
|
|
145
|
|
1169
|
|
|
|
|
|
|
# Escape the beginning, _print will take care of the rest. |
1170
|
|
|
|
|
|
|
$msg =~ s/^/# /; |
1171
|
53
|
|
|
|
|
3153
|
|
1172
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1173
|
|
|
|
|
|
|
$self->_print_to_fh( $fh, $msg ); |
1174
|
|
|
|
|
|
|
|
1175
|
53
|
|
|
|
|
1873
|
return 0; |
1176
|
|
|
|
|
|
|
} |
1177
|
53
|
|
|
|
|
98
|
|
1178
|
53
|
|
|
|
|
139
|
#line 1766 |
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
sub explain { |
1181
|
|
|
|
|
|
|
my $self = shift; |
1182
|
53
|
50
|
|
|
|
149
|
|
1183
|
|
|
|
|
|
|
return map { |
1184
|
|
|
|
|
|
|
ref $_ |
1185
|
|
|
|
|
|
|
? do { |
1186
|
|
|
|
|
|
|
$self->_try(sub { require Data::Dumper }, die_on_fail => 1); |
1187
|
53
|
50
|
|
|
|
108
|
|
1188
|
|
|
|
|
|
|
my $dumper = Data::Dumper->new( [$_] ); |
1189
|
|
|
|
|
|
|
$dumper->Indent(1)->Terse(1); |
1190
|
|
|
|
|
|
|
$dumper->Sortkeys(1) if $dumper->can("Sortkeys"); |
1191
|
|
|
|
|
|
|
$dumper->Dump; |
1192
|
|
|
|
|
|
|
} |
1193
|
|
|
|
|
|
|
: $_ |
1194
|
53
|
50
|
|
|
|
106
|
} @_; |
1195
|
0
|
|
|
|
|
0
|
} |
1196
|
|
|
|
|
|
|
|
1197
|
0
|
0
|
|
|
|
0
|
#line 1795 |
|
|
0
|
|
|
|
|
|
1198
|
0
|
|
|
|
|
0
|
|
1199
|
|
|
|
|
|
|
sub _print { |
1200
|
|
|
|
|
|
|
my $self = shift; |
1201
|
0
|
|
|
|
|
0
|
return $self->_print_to_fh( $self->output, @_ ); |
1202
|
|
|
|
|
|
|
} |
1203
|
|
|
|
|
|
|
|
1204
|
0
|
|
|
|
|
0
|
sub _print_to_fh { |
1205
|
|
|
|
|
|
|
my( $self, $fh, @msgs ) = @_; |
1206
|
|
|
|
|
|
|
|
1207
|
53
|
|
|
|
|
531
|
# Prevent printing headers when only compiling. Mostly for when |
1208
|
|
|
|
|
|
|
# tests are deparsed with B::Deparse |
1209
|
|
|
|
|
|
|
return if $^C; |
1210
|
|
|
|
|
|
|
|
1211
|
0
|
|
|
0
|
|
0
|
my $msg = join '', @msgs; |
1212
|
|
|
|
|
|
|
my $indent = $self->_indent; |
1213
|
0
|
0
|
|
|
|
0
|
|
1214
|
0
|
0
|
|
|
|
0
|
local( $\, $", $, ) = ( undef, ' ', '' ); |
1215
|
|
|
|
|
|
|
|
1216
|
0
|
|
|
|
|
0
|
# Escape each line after the first with a # so we don't |
1217
|
0
|
|
|
|
|
0
|
# confuse Test::Harness. |
1218
|
|
|
|
|
|
|
$msg =~ s{\n(?!\z)}{\n$indent# }sg; |
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
# Stick a newline on the end if it needs it. |
1221
|
|
|
|
|
|
|
$msg .= "\n" unless $msg =~ /\n\z/; |
1222
|
|
|
|
|
|
|
|
1223
|
|
|
|
|
|
|
return print $fh $indent, $msg; |
1224
|
|
|
|
|
|
|
} |
1225
|
0
|
|
|
0
|
|
0
|
|
1226
|
|
|
|
|
|
|
#line 1855 |
1227
|
0
|
|
|
|
|
0
|
|
1228
|
|
|
|
|
|
|
sub output { |
1229
|
0
|
|
|
|
|
0
|
my( $self, $fh ) = @_; |
1230
|
0
|
0
|
0
|
|
|
0
|
|
1231
|
|
|
|
|
|
|
if( defined $fh ) { |
1232
|
0
|
|
|
|
|
0
|
$self->{Out_FH} = $self->_new_fh($fh); |
1233
|
|
|
|
|
|
|
} |
1234
|
|
|
|
|
|
|
return $self->{Out_FH}; |
1235
|
|
|
|
|
|
|
} |
1236
|
|
|
|
|
|
|
|
1237
|
|
|
|
|
|
|
sub failure_output { |
1238
|
|
|
|
|
|
|
my( $self, $fh ) = @_; |
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
if( defined $fh ) { |
1241
|
|
|
|
|
|
|
$self->{Fail_FH} = $self->_new_fh($fh); |
1242
|
|
|
|
|
|
|
} |
1243
|
|
|
|
|
|
|
return $self->{Fail_FH}; |
1244
|
|
|
|
|
|
|
} |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
sub todo_output { |
1247
|
|
|
|
|
|
|
my( $self, $fh ) = @_; |
1248
|
|
|
|
|
|
|
|
1249
|
|
|
|
|
|
|
if( defined $fh ) { |
1250
|
|
|
|
|
|
|
$self->{Todo_FH} = $self->_new_fh($fh); |
1251
|
|
|
|
|
|
|
} |
1252
|
|
|
|
|
|
|
return $self->{Todo_FH}; |
1253
|
|
|
|
|
|
|
} |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
sub _new_fh { |
1256
|
|
|
|
|
|
|
my $self = shift; |
1257
|
0
|
|
|
0
|
1
|
0
|
my($file_or_fh) = shift; |
1258
|
|
|
|
|
|
|
|
1259
|
0
|
|
|
|
|
0
|
my $fh; |
1260
|
|
|
|
|
|
|
if( $self->is_fh($file_or_fh) ) { |
1261
|
0
|
0
|
|
|
|
0
|
$fh = $file_or_fh; |
1262
|
0
|
|
|
|
|
0
|
} |
1263
|
0
|
|
|
|
|
0
|
elsif( ref $file_or_fh eq 'SCALAR' ) { |
1264
|
0
|
|
|
|
|
0
|
# Scalar refs as filehandles was added in 5.8. |
1265
|
|
|
|
|
|
|
if( $] >= 5.008 ) { |
1266
|
|
|
|
|
|
|
open $fh, ">>", $file_or_fh |
1267
|
0
|
|
|
|
|
0
|
or $self->croak("Can't open scalar ref $file_or_fh: $!"); |
1268
|
0
|
|
|
|
|
0
|
} |
1269
|
|
|
|
|
|
|
# Emulate scalar ref filehandles with a tie. |
1270
|
|
|
|
|
|
|
else { |
1271
|
|
|
|
|
|
|
$fh = Test::Builder::IO::Scalar->new($file_or_fh) |
1272
|
|
|
|
|
|
|
or $self->croak("Can't tie scalar ref $file_or_fh"); |
1273
|
|
|
|
|
|
|
} |
1274
|
|
|
|
|
|
|
} |
1275
|
|
|
|
|
|
|
else { |
1276
|
|
|
|
|
|
|
open $fh, ">", $file_or_fh |
1277
|
14
|
|
|
14
|
|
547
|
or $self->croak("Can't open test output log $file_or_fh: $!"); |
|
14
|
|
|
|
|
35
|
|
|
14
|
|
|
|
|
21056
|
|
1278
|
|
|
|
|
|
|
_autoflush($fh); |
1279
|
|
|
|
|
|
|
} |
1280
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
return $fh; |
1282
|
|
|
|
|
|
|
} |
1283
|
|
|
|
|
|
|
|
1284
|
|
|
|
|
|
|
sub _autoflush { |
1285
|
|
|
|
|
|
|
my($fh) = shift; |
1286
|
|
|
|
|
|
|
my $old_fh = select $fh; |
1287
|
|
|
|
|
|
|
$| = 1; |
1288
|
|
|
|
|
|
|
select $old_fh; |
1289
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
return; |
1291
|
0
|
|
|
0
|
1
|
0
|
} |
1292
|
0
|
|
0
|
|
|
0
|
|
1293
|
0
|
|
|
|
|
0
|
my( $Testout, $Testerr ); |
1294
|
|
|
|
|
|
|
|
1295
|
0
|
|
|
|
|
0
|
sub _dup_stdhandles { |
1296
|
0
|
|
|
|
|
0
|
my $self = shift; |
1297
|
|
|
|
|
|
|
|
1298
|
0
|
|
|
|
|
0
|
$self->_open_testhandles; |
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
# Set everything to unbuffered else plain prints to STDOUT will |
1301
|
|
|
|
|
|
|
# come out in the wrong order from our own prints. |
1302
|
|
|
|
|
|
|
_autoflush($Testout); |
1303
|
|
|
|
|
|
|
_autoflush( \*STDOUT ); |
1304
|
|
|
|
|
|
|
_autoflush($Testerr); |
1305
|
|
|
|
|
|
|
_autoflush( \*STDERR ); |
1306
|
|
|
|
|
|
|
|
1307
|
|
|
|
|
|
|
$self->reset_outputs; |
1308
|
0
|
|
|
|
|
0
|
|
1309
|
0
|
0
|
|
|
|
0
|
return; |
1310
|
0
|
|
|
|
|
0
|
} |
1311
|
0
|
0
|
|
|
|
0
|
|
1312
|
0
|
|
|
|
|
0
|
sub _open_testhandles { |
1313
|
|
|
|
|
|
|
my $self = shift; |
1314
|
0
|
|
|
|
|
0
|
|
1315
|
|
|
|
|
|
|
return if $self->{Opened_Testhandles}; |
1316
|
0
|
|
|
|
|
0
|
|
1317
|
|
|
|
|
|
|
# We dup STDOUT and STDERR so people can change them in their |
1318
|
|
|
|
|
|
|
# test suites while still getting normal test output. |
1319
|
|
|
|
|
|
|
open( $Testout, ">&STDOUT" ) or die "Can't dup STDOUT: $!"; |
1320
|
|
|
|
|
|
|
open( $Testerr, ">&STDERR" ) or die "Can't dup STDERR: $!"; |
1321
|
|
|
|
|
|
|
|
1322
|
|
|
|
|
|
|
$self->_copy_io_layers( \*STDOUT, $Testout ); |
1323
|
|
|
|
|
|
|
$self->_copy_io_layers( \*STDERR, $Testerr ); |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
$self->{Opened_Testhandles} = 1; |
1326
|
|
|
|
|
|
|
|
1327
|
|
|
|
|
|
|
return; |
1328
|
|
|
|
|
|
|
} |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
sub _copy_io_layers { |
1331
|
|
|
|
|
|
|
my( $self, $src, $dst ) = @_; |
1332
|
0
|
|
|
0
|
1
|
0
|
|
1333
|
0
|
|
0
|
|
|
0
|
$self->_try( |
1334
|
|
|
|
|
|
|
sub { |
1335
|
0
|
|
|
|
|
0
|
require PerlIO; |
1336
|
0
|
|
|
|
|
0
|
my @src_layers = PerlIO::get_layers($src); |
1337
|
|
|
|
|
|
|
|
1338
|
0
|
|
|
|
|
0
|
_apply_layers($dst, @src_layers) if @src_layers; |
1339
|
|
|
|
|
|
|
} |
1340
|
|
|
|
|
|
|
); |
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
return; |
1343
|
|
|
|
|
|
|
} |
1344
|
|
|
|
|
|
|
|
1345
|
|
|
|
|
|
|
sub _apply_layers { |
1346
|
|
|
|
|
|
|
my ($fh, @layers) = @_; |
1347
|
|
|
|
|
|
|
my %seen; |
1348
|
0
|
|
|
|
|
0
|
my @unique = grep { $_ ne 'unix' and !$seen{$_}++ } @layers; |
1349
|
0
|
0
|
|
|
|
0
|
binmode($fh, join(":", "", "raw", @unique)); |
1350
|
0
|
|
|
|
|
0
|
} |
1351
|
|
|
|
|
|
|
|
1352
|
0
|
|
|
|
|
0
|
|
1353
|
|
|
|
|
|
|
#line 1988 |
1354
|
0
|
|
|
|
|
0
|
|
1355
|
|
|
|
|
|
|
sub reset_outputs { |
1356
|
|
|
|
|
|
|
my $self = shift; |
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
$self->output ($Testout); |
1359
|
|
|
|
|
|
|
$self->failure_output($Testerr); |
1360
|
|
|
|
|
|
|
$self->todo_output ($Testout); |
1361
|
|
|
|
|
|
|
|
1362
|
|
|
|
|
|
|
return; |
1363
|
|
|
|
|
|
|
} |
1364
|
|
|
|
|
|
|
|
1365
|
|
|
|
|
|
|
#line 2014 |
1366
|
|
|
|
|
|
|
|
1367
|
|
|
|
|
|
|
sub _message_at_caller { |
1368
|
|
|
|
|
|
|
my $self = shift; |
1369
|
|
|
|
|
|
|
|
1370
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1371
|
|
|
|
|
|
|
my( $pack, $file, $line ) = $self->caller; |
1372
|
|
|
|
|
|
|
return join( "", @_ ) . " at $file line $line.\n"; |
1373
|
|
|
|
|
|
|
} |
1374
|
|
|
|
|
|
|
|
1375
|
|
|
|
|
|
|
sub carp { |
1376
|
|
|
|
|
|
|
my $self = shift; |
1377
|
|
|
|
|
|
|
return warn $self->_message_at_caller(@_); |
1378
|
|
|
|
|
|
|
} |
1379
|
|
|
|
|
|
|
|
1380
|
|
|
|
|
|
|
sub croak { |
1381
|
|
|
|
|
|
|
my $self = shift; |
1382
|
|
|
|
|
|
|
return die $self->_message_at_caller(@_); |
1383
|
|
|
|
|
|
|
} |
1384
|
|
|
|
|
|
|
|
1385
|
|
|
|
|
|
|
|
1386
|
|
|
|
|
|
|
#line 2054 |
1387
|
|
|
|
|
|
|
|
1388
|
|
|
|
|
|
|
sub current_test { |
1389
|
|
|
|
|
|
|
my( $self, $num ) = @_; |
1390
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
lock( $self->{Curr_Test} ); |
1392
|
|
|
|
|
|
|
if( defined $num ) { |
1393
|
|
|
|
|
|
|
$self->{Curr_Test} = $num; |
1394
|
|
|
|
|
|
|
|
1395
|
|
|
|
|
|
|
# If the test counter is being pushed forward fill in the details. |
1396
|
|
|
|
|
|
|
my $test_results = $self->{Test_Results}; |
1397
|
|
|
|
|
|
|
if( $num > @$test_results ) { |
1398
|
|
|
|
|
|
|
my $start = @$test_results ? @$test_results : 0; |
1399
|
|
|
|
|
|
|
for( $start .. $num - 1 ) { |
1400
|
|
|
|
|
|
|
$test_results->[$_] = &share( |
1401
|
|
|
|
|
|
|
{ |
1402
|
|
|
|
|
|
|
'ok' => 1, |
1403
|
|
|
|
|
|
|
actual_ok => undef, |
1404
|
|
|
|
|
|
|
reason => 'incrementing test number', |
1405
|
|
|
|
|
|
|
type => 'unknown', |
1406
|
|
|
|
|
|
|
name => undef |
1407
|
|
|
|
|
|
|
} |
1408
|
|
|
|
|
|
|
); |
1409
|
|
|
|
|
|
|
} |
1410
|
|
|
|
|
|
|
} |
1411
|
|
|
|
|
|
|
# If backward, wipe history. Its their funeral. |
1412
|
0
|
|
|
0
|
1
|
0
|
elsif( $num < @$test_results ) { |
1413
|
0
|
|
|
|
|
0
|
$#{$test_results} = $num - 1; |
1414
|
|
|
|
|
|
|
} |
1415
|
0
|
0
|
|
|
|
0
|
} |
1416
|
|
|
|
|
|
|
return $self->{Curr_Test}; |
1417
|
0
|
|
|
|
|
0
|
} |
1418
|
|
|
|
|
|
|
|
1419
|
|
|
|
|
|
|
#line 2102 |
1420
|
0
|
0
|
0
|
|
|
0
|
|
|
|
0
|
|
|
|
|
|
1421
|
0
|
|
|
|
|
0
|
sub is_passing { |
1422
|
|
|
|
|
|
|
my $self = shift; |
1423
|
|
|
|
|
|
|
|
1424
|
|
|
|
|
|
|
if( @_ ) { |
1425
|
|
|
|
|
|
|
$self->{Is_Passing} = shift; |
1426
|
|
|
|
|
|
|
} |
1427
|
|
|
|
|
|
|
|
1428
|
0
|
0
|
|
|
|
0
|
return $self->{Is_Passing}; |
1429
|
|
|
|
|
|
|
} |
1430
|
|
|
|
|
|
|
|
1431
|
0
|
|
|
|
|
0
|
|
1432
|
|
|
|
|
|
|
#line 2124 |
1433
|
|
|
|
|
|
|
|
1434
|
|
|
|
|
|
|
sub summary { |
1435
|
0
|
|
|
0
|
|
0
|
my($self) = shift; |
1436
|
|
|
|
|
|
|
|
1437
|
|
|
|
|
|
|
return map { $_->{'ok'} } @{ $self->{Test_Results} }; |
1438
|
|
|
|
|
|
|
} |
1439
|
0
|
0
|
|
|
|
0
|
|
1440
|
0
|
|
|
|
|
0
|
#line 2179 |
1441
|
|
|
|
|
|
|
|
1442
|
|
|
|
|
|
|
sub details { |
1443
|
|
|
|
|
|
|
my $self = shift; |
1444
|
0
|
|
|
0
|
|
0
|
return @{ $self->{Test_Results} }; |
1445
|
|
|
|
|
|
|
} |
1446
|
0
|
|
|
|
|
0
|
|
1447
|
0
|
|
|
|
|
0
|
#line 2208 |
1448
|
0
|
0
|
|
|
|
0
|
|
1449
|
0
|
|
|
|
|
0
|
sub todo { |
1450
|
0
|
|
|
|
|
0
|
my( $self, $pack ) = @_; |
1451
|
0
|
|
|
|
|
0
|
|
1452
|
0
|
|
|
|
|
0
|
return $self->{Todo} if defined $self->{Todo}; |
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1455
|
|
|
|
|
|
|
my $todo = $self->find_TODO($pack); |
1456
|
0
|
|
|
|
|
0
|
return $todo if defined $todo; |
|
0
|
|
|
|
|
0
|
|
1457
|
0
|
|
|
|
|
0
|
|
1458
|
|
|
|
|
|
|
return ''; |
1459
|
|
|
|
|
|
|
} |
1460
|
|
|
|
|
|
|
|
1461
|
|
|
|
|
|
|
#line 2235 |
1462
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1463
|
|
|
|
|
|
|
sub find_TODO { |
1464
|
|
|
|
|
|
|
my( $self, $pack, $set, $new_value ) = @_; |
1465
|
14
|
|
|
14
|
|
93
|
|
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
23166
|
|
1466
|
|
|
|
|
|
|
$pack = $pack || $self->caller(1) || $self->exported_to; |
1467
|
0
|
|
|
|
|
0
|
return unless $pack; |
1468
|
|
|
|
|
|
|
|
1469
|
|
|
|
|
|
|
no strict 'refs'; ## no critic |
1470
|
0
|
0
|
|
|
|
0
|
my $old_value = ${ $pack . '::TODO' }; |
1471
|
|
|
|
|
|
|
$set and ${ $pack . '::TODO' } = $new_value; |
1472
|
0
|
|
|
|
|
0
|
return $old_value; |
1473
|
0
|
|
|
|
|
0
|
} |
1474
|
|
|
|
|
|
|
|
1475
|
|
|
|
|
|
|
#line 2255 |
1476
|
0
|
0
|
|
|
|
0
|
|
1477
|
0
|
0
|
|
|
|
0
|
sub in_todo { |
1478
|
0
|
0
|
|
|
|
0
|
my $self = shift; |
1479
|
|
|
|
|
|
|
|
1480
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
1481
|
0
|
|
|
|
|
0
|
return( defined $self->{Todo} || $self->find_TODO ) ? 1 : 0; |
1482
|
|
|
|
|
|
|
} |
1483
|
|
|
|
|
|
|
|
1484
|
|
|
|
|
|
|
#line 2305 |
1485
|
|
|
|
|
|
|
|
1486
|
|
|
|
|
|
|
sub todo_start { |
1487
|
|
|
|
|
|
|
my $self = shift; |
1488
|
0
|
|
|
|
|
0
|
my $message = @_ ? shift : ''; |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
$self->{Start_Todo}++; |
1491
|
|
|
|
|
|
|
if( $self->in_todo ) { |
1492
|
|
|
|
|
|
|
push @{ $self->{Todo_Stack} } => $self->todo; |
1493
|
|
|
|
|
|
|
} |
1494
|
|
|
|
|
|
|
$self->{Todo} = $message; |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
return; |
1497
|
|
|
|
|
|
|
} |
1498
|
|
|
|
|
|
|
|
1499
|
|
|
|
|
|
|
#line 2327 |
1500
|
|
|
|
|
|
|
|
1501
|
|
|
|
|
|
|
sub todo_end { |
1502
|
|
|
|
|
|
|
my $self = shift; |
1503
|
|
|
|
|
|
|
|
1504
|
|
|
|
|
|
|
if( !$self->{Start_Todo} ) { |
1505
|
|
|
|
|
|
|
$self->croak('todo_end() called without todo_start()'); |
1506
|
|
|
|
|
|
|
} |
1507
|
|
|
|
|
|
|
|
1508
|
|
|
|
|
|
|
$self->{Start_Todo}--; |
1509
|
|
|
|
|
|
|
|
1510
|
|
|
|
|
|
|
if( $self->{Start_Todo} && @{ $self->{Todo_Stack} } ) { |
1511
|
|
|
|
|
|
|
$self->{Todo} = pop @{ $self->{Todo_Stack} }; |
1512
|
|
|
|
|
|
|
} |
1513
|
286
|
|
|
286
|
|
653
|
else { |
1514
|
|
|
|
|
|
|
delete $self->{Todo}; |
1515
|
286
|
|
|
|
|
624
|
} |
1516
|
|
|
|
|
|
|
|
1517
|
|
|
|
|
|
|
return; |
1518
|
286
|
|
|
|
|
345
|
} |
|
286
|
|
|
|
|
1259
|
|
1519
|
286
|
|
|
|
|
323
|
|
1520
|
286
|
|
|
|
|
1040
|
#line 2360 |
1521
|
286
|
|
|
|
|
627
|
|
|
286
|
|
|
|
|
520
|
|
1522
|
286
|
|
|
|
|
2966
|
sub caller { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
1523
|
|
|
|
|
|
|
my( $self, $height ) = @_; |
1524
|
|
|
|
|
|
|
$height ||= 0; |
1525
|
286
|
50
|
33
|
|
|
722
|
|
1526
|
|
|
|
|
|
|
my $level = $self->level + $height + 1; |
1527
|
286
|
100
|
|
|
|
1732
|
my @caller; |
1528
|
|
|
|
|
|
|
do { |
1529
|
|
|
|
|
|
|
@caller = CORE::caller( $level ); |
1530
|
|
|
|
|
|
|
$level--; |
1531
|
|
|
|
|
|
|
} until @caller; |
1532
|
|
|
|
|
|
|
return wantarray ? @caller : $caller[0]; |
1533
|
|
|
|
|
|
|
} |
1534
|
|
|
|
|
|
|
|
1535
|
|
|
|
|
|
|
#line 2377 |
1536
|
|
|
|
|
|
|
|
1537
|
|
|
|
|
|
|
#line 2391 |
1538
|
|
|
|
|
|
|
|
1539
|
|
|
|
|
|
|
#'# |
1540
|
|
|
|
|
|
|
sub _sanity_check { |
1541
|
|
|
|
|
|
|
my $self = shift; |
1542
|
42
|
|
|
42
|
1
|
57
|
|
1543
|
42
|
|
|
|
|
50
|
$self->_whoa( $self->{Curr_Test} < 0, 'Says here you ran a negative number of tests!' ); |
1544
|
42
|
50
|
|
|
|
196
|
$self->_whoa( $self->{Curr_Test} != @{ $self->{Test_Results} }, |
1545
|
|
|
|
|
|
|
'Somehow you got a different number of results than tests ran!' ); |
1546
|
42
|
50
|
|
|
|
297
|
|
1547
|
0
|
0
|
|
|
|
0
|
return; |
1548
|
|
|
|
|
|
|
} |
1549
|
|
|
|
|
|
|
|
1550
|
0
|
|
0
|
|
|
0
|
#line 2412 |
1551
|
|
|
|
|
|
|
|
1552
|
|
|
|
|
|
|
sub _whoa { |
1553
|
|
|
|
|
|
|
my( $self, $check, $desc ) = @_; |
1554
|
|
|
|
|
|
|
if($check) { |
1555
|
|
|
|
|
|
|
local $Level = $Level + 1; |
1556
|
|
|
|
|
|
|
$self->croak(<<"WHOA"); |
1557
|
|
|
|
|
|
|
WHOA! $desc |
1558
|
|
|
|
|
|
|
This should never happen! Please contact the author immediately! |
1559
|
|
|
|
|
|
|
WHOA |
1560
|
|
|
|
|
|
|
} |
1561
|
|
|
|
|
|
|
|
1562
|
|
|
|
|
|
|
return; |
1563
|
|
|
|
|
|
|
} |
1564
|
|
|
|
|
|
|
|
1565
|
|
|
|
|
|
|
#line 2436 |
1566
|
|
|
|
|
|
|
|
1567
|
|
|
|
|
|
|
sub _my_exit { |
1568
|
|
|
|
|
|
|
$? = $_[0]; ## no critic (Variables::RequireLocalizedPunctuationVars) |
1569
|
|
|
|
|
|
|
|
1570
|
|
|
|
|
|
|
return 1; |
1571
|
|
|
|
|
|
|
} |
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
#line 2448 |
1574
|
|
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
sub _ending { |
1576
|
|
|
|
|
|
|
my $self = shift; |
1577
|
|
|
|
|
|
|
return if $self->no_ending; |
1578
|
|
|
|
|
|
|
return if $self->{Ending}++; |
1579
|
|
|
|
|
|
|
|
1580
|
|
|
|
|
|
|
my $real_exit_code = $?; |
1581
|
|
|
|
|
|
|
|
1582
|
|
|
|
|
|
|
# Don't bother with an ending if this is a forked copy. Only the parent |
1583
|
|
|
|
|
|
|
# should do the ending. |
1584
|
|
|
|
|
|
|
if( $self->{Original_Pid} != $$ ) { |
1585
|
281
|
|
|
281
|
1
|
409
|
return; |
1586
|
|
|
|
|
|
|
} |
1587
|
281
|
50
|
|
|
|
862
|
|
1588
|
0
|
|
|
|
|
0
|
# Ran tests but never declared a plan or hit done_testing |
1589
|
|
|
|
|
|
|
if( !$self->{Have_Plan} and $self->{Curr_Test} ) { |
1590
|
281
|
|
|
|
|
601
|
$self->is_passing(0); |
1591
|
|
|
|
|
|
|
$self->diag("Tests were run but no plan was declared and done_testing() was not seen."); |
1592
|
|
|
|
|
|
|
|
1593
|
|
|
|
|
|
|
if($real_exit_code) { |
1594
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
1595
|
|
|
|
|
|
|
Looks like your test exited with $real_exit_code just after $self->{Curr_Test}. |
1596
|
|
|
|
|
|
|
FAIL |
1597
|
|
|
|
|
|
|
$self->is_passing(0); |
1598
|
|
|
|
|
|
|
_my_exit($real_exit_code) && return; |
1599
|
|
|
|
|
|
|
} |
1600
|
|
|
|
|
|
|
|
1601
|
|
|
|
|
|
|
# But if the tests ran, handle exit code. |
1602
|
|
|
|
|
|
|
my $test_results = $self->{Test_Results}; |
1603
|
|
|
|
|
|
|
if(@$test_results) { |
1604
|
|
|
|
|
|
|
my $num_failed = grep !$_->{'ok'}, @{$test_results}[ 0 .. $self->{Curr_Test} - 1 ]; |
1605
|
|
|
|
|
|
|
if ($num_failed > 0) { |
1606
|
|
|
|
|
|
|
|
1607
|
|
|
|
|
|
|
my $exit_code = $num_failed <= 254 ? $num_failed : 254; |
1608
|
|
|
|
|
|
|
_my_exit($exit_code) && return; |
1609
|
|
|
|
|
|
|
} |
1610
|
|
|
|
|
|
|
} |
1611
|
|
|
|
|
|
|
_my_exit(254) && return; |
1612
|
|
|
|
|
|
|
} |
1613
|
|
|
|
|
|
|
|
1614
|
|
|
|
|
|
|
# Exit if plan() was never called. This is so "require Test::Simple" |
1615
|
|
|
|
|
|
|
# doesn't puke. |
1616
|
|
|
|
|
|
|
if( !$self->{Have_Plan} ) { |
1617
|
63
|
|
|
63
|
1
|
84
|
return; |
1618
|
|
|
|
|
|
|
} |
1619
|
63
|
50
|
|
|
|
148
|
|
1620
|
0
|
|
|
|
|
0
|
# Don't do an ending if we bailed out. |
1621
|
|
|
|
|
|
|
if( $self->{Bailed_Out} ) { |
1622
|
63
|
|
|
|
|
268
|
$self->is_passing(0); |
1623
|
|
|
|
|
|
|
return; |
1624
|
|
|
|
|
|
|
} |
1625
|
|
|
|
|
|
|
# Figure out if we passed or failed and print helpful messages. |
1626
|
|
|
|
|
|
|
my $test_results = $self->{Test_Results}; |
1627
|
|
|
|
|
|
|
if(@$test_results) { |
1628
|
|
|
|
|
|
|
# The plan? We have no plan. |
1629
|
|
|
|
|
|
|
if( $self->{No_Plan} ) { |
1630
|
|
|
|
|
|
|
$self->_output_plan($self->{Curr_Test}) unless $self->no_header; |
1631
|
|
|
|
|
|
|
$self->{Expected_Tests} = $self->{Curr_Test}; |
1632
|
|
|
|
|
|
|
} |
1633
|
|
|
|
|
|
|
|
1634
|
|
|
|
|
|
|
# Auto-extended arrays and elements which aren't explicitly |
1635
|
|
|
|
|
|
|
# filled in with a shared reference will puke under 5.8.0 |
1636
|
|
|
|
|
|
|
# ithreads. So we have to fill them in by hand. :( |
1637
|
|
|
|
|
|
|
my $empty_result = &share( {} ); |
1638
|
|
|
|
|
|
|
for my $idx ( 0 .. $self->{Expected_Tests} - 1 ) { |
1639
|
|
|
|
|
|
|
$test_results->[$idx] = $empty_result |
1640
|
|
|
|
|
|
|
unless defined $test_results->[$idx]; |
1641
|
|
|
|
|
|
|
} |
1642
|
|
|
|
|
|
|
|
1643
|
|
|
|
|
|
|
my $num_failed = grep !$_->{'ok'}, @{$test_results}[ 0 .. $self->{Curr_Test} - 1 ]; |
1644
|
|
|
|
|
|
|
|
1645
|
|
|
|
|
|
|
my $num_extra = $self->{Curr_Test} - $self->{Expected_Tests}; |
1646
|
|
|
|
|
|
|
|
1647
|
|
|
|
|
|
|
if( $num_extra != 0 ) { |
1648
|
|
|
|
|
|
|
my $s = $self->{Expected_Tests} == 1 ? '' : 's'; |
1649
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
1650
|
|
|
|
|
|
|
Looks like you planned $self->{Expected_Tests} test$s but ran $self->{Curr_Test}. |
1651
|
|
|
|
|
|
|
FAIL |
1652
|
|
|
|
|
|
|
$self->is_passing(0); |
1653
|
50
|
|
|
50
|
|
110
|
} |
1654
|
|
|
|
|
|
|
|
1655
|
50
|
50
|
|
|
|
160
|
if($num_failed) { |
1656
|
0
|
|
|
|
|
0
|
my $num_tests = $self->{Curr_Test}; |
1657
|
|
|
|
|
|
|
my $s = $num_failed == 1 ? '' : 's'; |
1658
|
50
|
|
|
|
|
330
|
|
1659
|
|
|
|
|
|
|
my $qualifier = $num_extra == 0 ? '' : ' run'; |
1660
|
|
|
|
|
|
|
|
1661
|
14
|
|
|
14
|
|
107
|
$self->diag(<<"FAIL"); |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
53333
|
|
1662
|
|
|
|
|
|
|
Looks like you failed $num_failed test$s of $num_tests$qualifier. |
1663
|
|
|
|
|
|
|
FAIL |
1664
|
|
|
|
|
|
|
$self->is_passing(0); |
1665
|
|
|
|
|
|
|
} |
1666
|
|
|
|
|
|
|
|
1667
|
|
|
|
|
|
|
if($real_exit_code) { |
1668
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
1669
|
|
|
|
|
|
|
Looks like your test exited with $real_exit_code just after $self->{Curr_Test}. |
1670
|
|
|
|
|
|
|
FAIL |
1671
|
|
|
|
|
|
|
$self->is_passing(0); |
1672
|
|
|
|
|
|
|
_my_exit($real_exit_code) && return; |
1673
|
|
|
|
|
|
|
} |
1674
|
|
|
|
|
|
|
|
1675
|
|
|
|
|
|
|
my $exit_code; |
1676
|
|
|
|
|
|
|
if($num_failed) { |
1677
|
|
|
|
|
|
|
$exit_code = $num_failed <= 254 ? $num_failed : 254; |
1678
|
|
|
|
|
|
|
} |
1679
|
|
|
|
|
|
|
elsif( $num_extra != 0 ) { |
1680
|
|
|
|
|
|
|
$exit_code = 255; |
1681
|
|
|
|
|
|
|
} |
1682
|
|
|
|
|
|
|
else { |
1683
|
|
|
|
|
|
|
$exit_code = 0; |
1684
|
|
|
|
|
|
|
} |
1685
|
|
|
|
|
|
|
|
1686
|
|
|
|
|
|
|
_my_exit($exit_code) && return; |
1687
|
|
|
|
|
|
|
} |
1688
|
|
|
|
|
|
|
elsif( $self->{Skip_All} ) { |
1689
|
|
|
|
|
|
|
_my_exit(0) && return; |
1690
|
|
|
|
|
|
|
} |
1691
|
|
|
|
|
|
|
elsif($real_exit_code) { |
1692
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
1693
|
|
|
|
|
|
|
Looks like your test exited with $real_exit_code before it could output anything. |
1694
|
|
|
|
|
|
|
FAIL |
1695
|
|
|
|
|
|
|
$self->is_passing(0); |
1696
|
|
|
|
|
|
|
_my_exit($real_exit_code) && return; |
1697
|
|
|
|
|
|
|
} |
1698
|
|
|
|
|
|
|
else { |
1699
|
|
|
|
|
|
|
$self->diag("No tests run!\n"); |
1700
|
|
|
|
|
|
|
$self->is_passing(0); |
1701
|
|
|
|
|
|
|
_my_exit(255) && return; |
1702
|
|
|
|
|
|
|
} |
1703
|
24
|
|
|
24
|
1
|
45
|
|
1704
|
|
|
|
|
|
|
$self->is_passing(0); |
1705
|
24
|
|
|
|
|
81
|
$self->_whoa( 1, "We fell off the end of _ending()" ); |
1706
|
|
|
|
|
|
|
} |
1707
|
|
|
|
|
|
|
|
1708
|
|
|
|
|
|
|
END { |
1709
|
|
|
|
|
|
|
$Test->_ending if defined $Test; |
1710
|
|
|
|
|
|
|
} |
1711
|
|
|
|
|
|
|
|
1712
|
|
|
|
|
|
|
#line 2656 |
1713
|
|
|
|
|
|
|
|
1714
|
|
|
|
|
|
|
1; |
1715
|
|
|
|
|
|
|
|