| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#line 1 |
|
2
|
|
|
|
|
|
|
package Test::Builder; |
|
3
|
5
|
|
|
5
|
|
77
|
|
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
235
|
|
|
4
|
|
|
|
|
|
|
use 5.004; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# $^C was only introduced in 5.005-ish. We do this to prevent |
|
7
|
|
|
|
|
|
|
# use of uninitialized value warnings in older perls. |
|
8
|
|
|
|
|
|
|
$^C ||= 0; |
|
9
|
5
|
|
|
5
|
|
23
|
|
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
133
|
|
|
10
|
5
|
|
|
5
|
|
21
|
use strict; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
373
|
|
|
11
|
|
|
|
|
|
|
use vars qw($VERSION); |
|
12
|
|
|
|
|
|
|
$VERSION = '0.22'; |
|
13
|
|
|
|
|
|
|
$VERSION = eval $VERSION; # make the alpha version come out as a number |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Make Test::Builder thread-safe for ithreads. |
|
16
|
5
|
|
|
5
|
|
24
|
BEGIN { |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
1600
|
|
|
17
|
|
|
|
|
|
|
use Config; |
|
18
|
5
|
50
|
33
|
5
|
|
116
|
# Load threads::shared when threads are turned on |
|
|
|
|
33
|
|
|
|
|
|
19
|
0
|
|
|
|
|
0
|
if( $] >= 5.008 && $Config{useithreads} && $INC{'threads.pm'}) { |
|
20
|
|
|
|
|
|
|
require threads::shared; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Hack around YET ANOTHER threads::shared bug. It would |
|
23
|
|
|
|
|
|
|
# occassionally forget the contents of the variable when sharing it. |
|
24
|
|
|
|
|
|
|
# So we first copy the data, then share, then put our copy back. |
|
25
|
0
|
|
|
|
|
0
|
*share = sub (\[$@%]) { |
|
26
|
0
|
|
|
|
|
0
|
my $type = ref $_[0]; |
|
27
|
|
|
|
|
|
|
my $data; |
|
28
|
0
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
if( $type eq 'HASH' ) { |
|
|
0
|
|
|
|
|
0
|
|
|
30
|
|
|
|
|
|
|
%$data = %{$_[0]}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
0
|
|
|
|
|
0
|
elsif( $type eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
0
|
|
|
33
|
|
|
|
|
|
|
@$data = @{$_[0]}; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
0
|
|
|
|
|
0
|
elsif( $type eq 'SCALAR' ) { |
|
|
0
|
|
|
|
|
0
|
|
|
36
|
|
|
|
|
|
|
$$data = ${$_[0]}; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
0
|
|
|
|
|
0
|
else { |
|
39
|
|
|
|
|
|
|
die "Unknown type: ".$type; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
0
|
|
|
|
|
0
|
|
|
42
|
|
|
|
|
|
|
$_[0] = &threads::shared::share($_[0]); |
|
43
|
0
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
if( $type eq 'HASH' ) { |
|
|
0
|
|
|
|
|
0
|
|
|
45
|
|
|
|
|
|
|
%{$_[0]} = %$data; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
0
|
|
|
|
|
0
|
elsif( $type eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
0
|
|
|
48
|
|
|
|
|
|
|
@{$_[0]} = @$data; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
|
|
|
|
0
|
elsif( $type eq 'SCALAR' ) { |
|
|
0
|
|
|
|
|
0
|
|
|
51
|
|
|
|
|
|
|
${$_[0]} = $$data; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
0
|
|
|
|
|
0
|
else { |
|
54
|
|
|
|
|
|
|
die "Unknown type: ".$type; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
0
|
|
|
|
|
0
|
|
|
57
|
0
|
|
|
|
|
0
|
return $_[0]; |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
# 5.8.0's threads::shared is busted when threads are off. |
|
61
|
|
|
|
|
|
|
# We emulate it here. |
|
62
|
5
|
|
|
30
|
|
20
|
else { |
|
|
30
|
|
|
|
|
55
|
|
|
63
|
5
|
|
|
17
|
|
585
|
*share = sub { return $_[0] }; |
|
|
17
|
|
|
|
|
22
|
|
|
64
|
|
|
|
|
|
|
*lock = sub { 0 }; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#line 122 |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
|
72
|
|
|
|
|
|
|
sub new { |
|
73
|
|
|
|
|
|
|
my($class) = shift; |
|
74
|
|
|
|
|
|
|
$Test ||= bless ['Move along, nothing to see here'], $class; |
|
75
|
|
|
|
|
|
|
return $Test; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#line 139 |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $Test_Died; |
|
81
|
|
|
|
|
|
|
my $Have_Plan; |
|
82
|
|
|
|
|
|
|
my $No_Plan; |
|
83
|
|
|
|
|
|
|
my $Curr_Test; share($Curr_Test); |
|
84
|
|
|
|
|
|
|
use vars qw($Level); |
|
85
|
|
|
|
|
|
|
my $Original_Pid; |
|
86
|
|
|
|
|
|
|
my @Test_Results; share(@Test_Results); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $Exported_To; |
|
89
|
|
|
|
|
|
|
my $Expected_Tests; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $Skip_All; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $Use_Nums; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my($No_Header, $No_Ending); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$Test->reset; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub reset { |
|
100
|
|
|
|
|
|
|
my ($self) = @_; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$Test_Died = 0; |
|
103
|
|
|
|
|
|
|
$Have_Plan = 0; |
|
104
|
|
|
|
|
|
|
$No_Plan = 0; |
|
105
|
|
|
|
|
|
|
$Curr_Test = 0; |
|
106
|
|
|
|
|
|
|
$Level = 1; |
|
107
|
|
|
|
|
|
|
$Original_Pid = $$; |
|
108
|
|
|
|
|
|
|
@Test_Results = (); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$Exported_To = undef; |
|
111
|
|
|
|
|
|
|
$Expected_Tests = 0; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$Skip_All = 0; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$Use_Nums = 1; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
($No_Header, $No_Ending) = (0,0); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$self->_dup_stdhandles unless $^C; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return undef; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#line 202 |
|
125
|
10
|
|
|
10
|
1
|
22
|
|
|
126
|
10
|
|
100
|
|
|
84
|
sub exported_to { |
|
127
|
10
|
|
|
|
|
23
|
my($self, $pack) = @_; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
if( defined $pack ) { |
|
130
|
|
|
|
|
|
|
$Exported_To = $pack; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
return $Exported_To; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#line 224 |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub plan { |
|
138
|
|
|
|
|
|
|
my($self, $cmd, $arg) = @_; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
return unless $cmd; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
if( $Have_Plan ) { |
|
143
|
|
|
|
|
|
|
die sprintf "You tried to plan twice! Second plan at %s line %d\n", |
|
144
|
5
|
|
|
5
|
|
26
|
($self->caller)[1,2]; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
24405
|
|
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
if( $cmd eq 'no_plan' ) { |
|
148
|
|
|
|
|
|
|
$self->no_plan; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
elsif( $cmd eq 'skip_all' ) { |
|
151
|
|
|
|
|
|
|
return $self->skip_all($arg); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
elsif( $cmd eq 'tests' ) { |
|
154
|
|
|
|
|
|
|
if( $arg ) { |
|
155
|
|
|
|
|
|
|
return $self->expected_tests($arg); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
elsif( !defined $arg ) { |
|
158
|
|
|
|
|
|
|
die "Got an undefined number of tests. Looks like you tried to ". |
|
159
|
|
|
|
|
|
|
"say how many tests you plan to run but made a mistake.\n"; |
|
160
|
5
|
|
|
5
|
1
|
10
|
} |
|
161
|
|
|
|
|
|
|
elsif( !$arg ) { |
|
162
|
5
|
|
|
|
|
9
|
die "You said to run 0 tests! You've got to run something.\n"; |
|
163
|
5
|
|
|
|
|
11
|
} |
|
164
|
5
|
|
|
|
|
7
|
} |
|
165
|
5
|
|
|
|
|
8
|
else { |
|
166
|
5
|
|
|
|
|
7
|
require Carp; |
|
167
|
5
|
|
|
|
|
64
|
my @args = grep { defined } ($cmd, $arg); |
|
168
|
5
|
|
|
|
|
13
|
Carp::croak("plan() doesn't understand @args"); |
|
169
|
|
|
|
|
|
|
} |
|
170
|
5
|
|
|
|
|
10
|
|
|
171
|
5
|
|
|
|
|
9
|
return 1; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
5
|
|
|
|
|
9
|
|
|
174
|
|
|
|
|
|
|
#line 271 |
|
175
|
5
|
|
|
|
|
7
|
|
|
176
|
|
|
|
|
|
|
sub expected_tests { |
|
177
|
5
|
|
|
|
|
11
|
my $self = shift; |
|
178
|
|
|
|
|
|
|
my($max) = @_; |
|
179
|
5
|
50
|
|
|
|
29
|
|
|
180
|
|
|
|
|
|
|
if( @_ ) { |
|
181
|
5
|
|
|
|
|
7
|
die "Number of tests must be a postive integer. You gave it '$max'.\n" |
|
182
|
|
|
|
|
|
|
unless $max =~ /^\+?\d+$/ and $max > 0; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
$Expected_Tests = $max; |
|
185
|
|
|
|
|
|
|
$Have_Plan = 1; |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$self->_print("1..$max\n") unless $self->no_header; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
return $Expected_Tests; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
#line 296 |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub no_plan { |
|
196
|
|
|
|
|
|
|
$No_Plan = 1; |
|
197
|
|
|
|
|
|
|
$Have_Plan = 1; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
#line 309 |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub has_plan { |
|
203
|
|
|
|
|
|
|
return($Expected_Tests) if $Expected_Tests; |
|
204
|
6
|
|
|
6
|
1
|
12
|
return('no_plan') if $No_Plan; |
|
205
|
|
|
|
|
|
|
return(undef); |
|
206
|
6
|
100
|
|
|
|
22
|
}; |
|
207
|
5
|
|
|
|
|
12
|
|
|
208
|
|
|
|
|
|
|
|
|
209
|
6
|
|
|
|
|
19
|
#line 325 |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub skip_all { |
|
212
|
|
|
|
|
|
|
my($self, $reason) = @_; |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
my $out = "1..0"; |
|
215
|
|
|
|
|
|
|
$out .= " # Skip $reason" if $reason; |
|
216
|
|
|
|
|
|
|
$out .= "\n"; |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
$Skip_All = 1; |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
$self->_print($out) unless $self->no_header; |
|
221
|
|
|
|
|
|
|
exit(0); |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
#line 358 |
|
225
|
|
|
|
|
|
|
|
|
226
|
7
|
|
|
7
|
1
|
14
|
sub ok { |
|
227
|
|
|
|
|
|
|
my($self, $test, $name) = @_; |
|
228
|
7
|
100
|
|
|
|
24
|
|
|
229
|
|
|
|
|
|
|
# $test might contain an object which we don't want to accidentally |
|
230
|
5
|
50
|
|
|
|
18
|
# store, so we turn it into a boolean. |
|
231
|
0
|
|
|
|
|
0
|
$test = $test ? 1 : 0; |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
unless( $Have_Plan ) { |
|
234
|
|
|
|
|
|
|
require Carp; |
|
235
|
5
|
50
|
|
|
|
32
|
Carp::croak("You tried to run a test without a plan! Gotta have a plan."); |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
0
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
lock $Curr_Test; |
|
239
|
2
|
|
|
|
|
9
|
$Curr_Test++; |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# In case $name is a string overloaded object, force it to stringify. |
|
242
|
3
|
50
|
|
|
|
10
|
$self->_unoverload(\$name); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
243
|
3
|
|
|
|
|
13
|
|
|
244
|
|
|
|
|
|
|
$self->diag(<
|
|
245
|
|
|
|
|
|
|
You named your test '$name'. You shouldn't use numbers for your test names. |
|
246
|
0
|
|
|
|
|
0
|
Very confusing. |
|
247
|
|
|
|
|
|
|
ERR |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
my($pack, $file, $line) = $self->caller; |
|
250
|
0
|
|
|
|
|
0
|
|
|
251
|
|
|
|
|
|
|
my $todo = $self->todo($pack); |
|
252
|
|
|
|
|
|
|
$self->_unoverload(\$todo); |
|
253
|
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
0
|
my $out; |
|
255
|
0
|
|
|
|
|
0
|
my $result = &share({}); |
|
|
0
|
|
|
|
|
0
|
|
|
256
|
0
|
|
|
|
|
0
|
|
|
257
|
|
|
|
|
|
|
unless( $test ) { |
|
258
|
|
|
|
|
|
|
$out .= "not "; |
|
259
|
0
|
|
|
|
|
0
|
@$result{ 'ok', 'actual_ok' } = ( ( $todo ? 1 : 0 ), 0 ); |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
else { |
|
262
|
|
|
|
|
|
|
@$result{ 'ok', 'actual_ok' } = ( 1, $test ); |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
$out .= "ok"; |
|
266
|
|
|
|
|
|
|
$out .= " $Curr_Test" if $self->use_numbers; |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
if( defined $name ) { |
|
269
|
|
|
|
|
|
|
$name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. |
|
270
|
|
|
|
|
|
|
$out .= " - $name"; |
|
271
|
|
|
|
|
|
|
$result->{name} = $name; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
3
|
|
|
3
|
1
|
6
|
else { |
|
274
|
3
|
|
|
|
|
6
|
$result->{name} = ''; |
|
275
|
|
|
|
|
|
|
} |
|
276
|
3
|
50
|
|
|
|
11
|
|
|
277
|
3
|
50
|
33
|
|
|
37
|
if( $todo ) { |
|
278
|
|
|
|
|
|
|
$out .= " # TODO $todo"; |
|
279
|
|
|
|
|
|
|
$result->{reason} = $todo; |
|
280
|
3
|
|
|
|
|
6
|
$result->{type} = 'todo'; |
|
281
|
3
|
|
|
|
|
3
|
} |
|
282
|
|
|
|
|
|
|
else { |
|
283
|
3
|
50
|
|
|
|
13
|
$result->{reason} = ''; |
|
284
|
|
|
|
|
|
|
$result->{type} = ''; |
|
285
|
3
|
|
|
|
|
18
|
} |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
$Test_Results[$Curr_Test-1] = $result; |
|
288
|
|
|
|
|
|
|
$out .= "\n"; |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
$self->_print($out); |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
unless( $test ) { |
|
293
|
|
|
|
|
|
|
my $msg = $todo ? "Failed (TODO)" : "Failed"; |
|
294
|
|
|
|
|
|
|
$self->_print_diag("\n") if $ENV{HARNESS_ACTIVE}; |
|
295
|
|
|
|
|
|
|
$self->diag(" $msg test ($file at line $line)\n"); |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
|
|
298
|
0
|
|
|
0
|
1
|
0
|
return $test ? 1 : 0; |
|
299
|
0
|
|
|
|
|
0
|
} |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub _unoverload { |
|
303
|
|
|
|
|
|
|
my $self = shift; |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
local($@,$!); |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
eval { require overload } || return; |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
foreach my $thing (@_) { |
|
310
|
|
|
|
|
|
|
eval { |
|
311
|
0
|
0
|
|
0
|
1
|
0
|
if( defined $$thing ) { |
|
312
|
0
|
0
|
|
|
|
0
|
if( my $string_meth = overload::Method($$thing, '""') ) { |
|
313
|
0
|
|
|
|
|
0
|
$$thing = $$thing->$string_meth(); |
|
314
|
|
|
|
|
|
|
} |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
}; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
#line 469 |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
sub is_eq { |
|
324
|
|
|
|
|
|
|
my($self, $got, $expect, $name) = @_; |
|
325
|
|
|
|
|
|
|
local $Level = $Level + 1; |
|
326
|
|
|
|
|
|
|
|
|
327
|
2
|
|
|
2
|
1
|
4
|
if( !defined $got || !defined $expect ) { |
|
328
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
|
329
|
2
|
|
|
|
|
3
|
my $test = !defined $got && !defined $expect; |
|
330
|
2
|
50
|
|
|
|
9
|
|
|
331
|
2
|
|
|
|
|
4
|
$self->ok($test, $name); |
|
332
|
|
|
|
|
|
|
$self->_is_diag($got, 'eq', $expect) unless $test; |
|
333
|
2
|
|
|
|
|
3
|
return $test; |
|
334
|
|
|
|
|
|
|
} |
|
335
|
2
|
50
|
|
|
|
9
|
|
|
336
|
2
|
|
|
|
|
200
|
return $self->cmp_ok($got, 'eq', $expect, $name); |
|
337
|
|
|
|
|
|
|
} |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
sub is_num { |
|
340
|
|
|
|
|
|
|
my($self, $got, $expect, $name) = @_; |
|
341
|
|
|
|
|
|
|
local $Level = $Level + 1; |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
if( !defined $got || !defined $expect ) { |
|
344
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
|
345
|
|
|
|
|
|
|
my $test = !defined $got && !defined $expect; |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
$self->ok($test, $name); |
|
348
|
|
|
|
|
|
|
$self->_is_diag($got, '==', $expect) unless $test; |
|
349
|
|
|
|
|
|
|
return $test; |
|
350
|
|
|
|
|
|
|
} |
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
return $self->cmp_ok($got, '==', $expect, $name); |
|
353
|
|
|
|
|
|
|
} |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub _is_diag { |
|
356
|
|
|
|
|
|
|
my($self, $got, $type, $expect) = @_; |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
foreach my $val (\$got, \$expect) { |
|
359
|
|
|
|
|
|
|
if( defined $$val ) { |
|
360
|
17
|
|
|
17
|
1
|
32
|
if( $type eq 'eq' ) { |
|
361
|
|
|
|
|
|
|
# quote and force string context |
|
362
|
|
|
|
|
|
|
$$val = "'$$val'" |
|
363
|
|
|
|
|
|
|
} |
|
364
|
17
|
50
|
|
|
|
231
|
else { |
|
365
|
|
|
|
|
|
|
# force numeric context |
|
366
|
17
|
50
|
|
|
|
63
|
$$val = $$val+0; |
|
367
|
0
|
|
|
|
|
0
|
} |
|
368
|
0
|
|
|
|
|
0
|
} |
|
369
|
|
|
|
|
|
|
else { |
|
370
|
|
|
|
|
|
|
$$val = 'undef'; |
|
371
|
17
|
|
|
|
|
40
|
} |
|
372
|
17
|
|
|
|
|
23
|
} |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
return $self->diag(sprintf <
|
|
375
|
17
|
|
|
|
|
47
|
got: %s |
|
376
|
|
|
|
|
|
|
expected: %s |
|
377
|
17
|
50
|
66
|
|
|
3170
|
DIAGNOSTIC |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
} |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
#line 543 |
|
382
|
17
|
|
|
|
|
45
|
|
|
383
|
|
|
|
|
|
|
sub isnt_eq { |
|
384
|
17
|
|
|
|
|
51
|
my($self, $got, $dont_expect, $name) = @_; |
|
385
|
17
|
|
|
|
|
38
|
local $Level = $Level + 1; |
|
386
|
|
|
|
|
|
|
|
|
387
|
17
|
|
|
|
|
4107
|
if( !defined $got || !defined $dont_expect ) { |
|
388
|
17
|
|
|
|
|
46
|
# undef only matches undef and nothing else |
|
389
|
|
|
|
|
|
|
my $test = defined $got || defined $dont_expect; |
|
390
|
17
|
50
|
|
|
|
50
|
|
|
391
|
0
|
|
|
|
|
0
|
$self->ok($test, $name); |
|
392
|
0
|
0
|
|
|
|
0
|
$self->_cmp_diag($got, 'ne', $dont_expect) unless $test; |
|
393
|
|
|
|
|
|
|
return $test; |
|
394
|
|
|
|
|
|
|
} |
|
395
|
17
|
|
|
|
|
55
|
|
|
396
|
|
|
|
|
|
|
return $self->cmp_ok($got, 'ne', $dont_expect, $name); |
|
397
|
|
|
|
|
|
|
} |
|
398
|
17
|
|
|
|
|
26
|
|
|
399
|
17
|
50
|
|
|
|
95
|
sub isnt_num { |
|
400
|
|
|
|
|
|
|
my($self, $got, $dont_expect, $name) = @_; |
|
401
|
17
|
100
|
|
|
|
37
|
local $Level = $Level + 1; |
|
402
|
1
|
|
|
|
|
3
|
|
|
403
|
1
|
|
|
|
|
3
|
if( !defined $got || !defined $dont_expect ) { |
|
404
|
1
|
|
|
|
|
3
|
# undef only matches undef and nothing else |
|
405
|
|
|
|
|
|
|
my $test = defined $got || defined $dont_expect; |
|
406
|
|
|
|
|
|
|
|
|
407
|
16
|
|
|
|
|
36
|
$self->ok($test, $name); |
|
408
|
|
|
|
|
|
|
$self->_cmp_diag($got, '!=', $dont_expect) unless $test; |
|
409
|
|
|
|
|
|
|
return $test; |
|
410
|
17
|
50
|
|
|
|
30
|
} |
|
411
|
0
|
|
|
|
|
0
|
|
|
412
|
0
|
|
|
|
|
0
|
return $self->cmp_ok($got, '!=', $dont_expect, $name); |
|
413
|
0
|
|
|
|
|
0
|
} |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
|
|
416
|
17
|
|
|
|
|
30
|
#line 595 |
|
417
|
17
|
|
|
|
|
34
|
|
|
418
|
|
|
|
|
|
|
sub like { |
|
419
|
|
|
|
|
|
|
my($self, $this, $regex, $name) = @_; |
|
420
|
17
|
|
|
|
|
31
|
|
|
421
|
17
|
|
|
|
|
25
|
local $Level = $Level + 1; |
|
422
|
|
|
|
|
|
|
$self->_regex_ok($this, $regex, '=~', $name); |
|
423
|
17
|
|
|
|
|
40
|
} |
|
424
|
|
|
|
|
|
|
|
|
425
|
17
|
50
|
|
|
|
59
|
sub unlike { |
|
426
|
0
|
0
|
|
|
|
0
|
my($self, $this, $regex, $name) = @_; |
|
427
|
0
|
0
|
|
|
|
0
|
|
|
428
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
|
429
|
|
|
|
|
|
|
$self->_regex_ok($this, $regex, '!~', $name); |
|
430
|
|
|
|
|
|
|
} |
|
431
|
17
|
50
|
|
|
|
69
|
|
|
432
|
|
|
|
|
|
|
#line 636 |
|
433
|
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
sub maybe_regex { |
|
436
|
34
|
|
|
34
|
|
46
|
my ($self, $regex) = @_; |
|
437
|
|
|
|
|
|
|
my $usable_regex = undef; |
|
438
|
34
|
|
|
|
|
87
|
|
|
439
|
|
|
|
|
|
|
return $usable_regex unless defined $regex; |
|
440
|
34
|
50
|
|
|
|
44
|
|
|
|
34
|
|
|
|
|
201
|
|
|
441
|
|
|
|
|
|
|
my($re, $opts); |
|
442
|
34
|
|
|
|
|
71
|
|
|
443
|
34
|
|
|
|
|
37
|
# Check for qr/foo/ |
|
444
|
34
|
100
|
|
|
|
108
|
if( ref $regex eq 'Regexp' ) { |
|
445
|
18
|
50
|
|
|
|
55
|
$usable_regex = $regex; |
|
446
|
0
|
|
|
|
|
0
|
} |
|
447
|
|
|
|
|
|
|
# Check for '/foo/' or 'm,foo,' |
|
448
|
|
|
|
|
|
|
elsif( ($re, $opts) = $regex =~ m{^ /(.*)/ (\w*) $ }sx or |
|
449
|
|
|
|
|
|
|
(undef, $re, $opts) = $regex =~ m,^ m([^\w\s]) (.+) \1 (\w*) $,sx |
|
450
|
|
|
|
|
|
|
) |
|
451
|
|
|
|
|
|
|
{ |
|
452
|
|
|
|
|
|
|
$usable_regex = length $opts ? "(?$opts)$re" : $re; |
|
453
|
|
|
|
|
|
|
} |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
return $usable_regex; |
|
456
|
|
|
|
|
|
|
}; |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
sub _regex_ok { |
|
459
|
|
|
|
|
|
|
my($self, $this, $regex, $cmp, $name) = @_; |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
local $Level = $Level + 1; |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
my $ok = 0; |
|
464
|
|
|
|
|
|
|
my $usable_regex = $self->maybe_regex($regex); |
|
465
|
|
|
|
|
|
|
unless (defined $usable_regex) { |
|
466
|
|
|
|
|
|
|
$ok = $self->ok( 0, $name ); |
|
467
|
|
|
|
|
|
|
$self->diag(" '$regex' doesn't look much like a regex to me."); |
|
468
|
|
|
|
|
|
|
return $ok; |
|
469
|
|
|
|
|
|
|
} |
|
470
|
|
|
|
|
|
|
|
|
471
|
10
|
|
|
10
|
1
|
20
|
{ |
|
472
|
10
|
|
|
|
|
17
|
local $^W = 0; |
|
473
|
|
|
|
|
|
|
my $test = $this =~ /$usable_regex/ ? 1 : 0; |
|
474
|
10
|
50
|
33
|
|
|
45
|
$test = !$test if $cmp eq '!~'; |
|
475
|
|
|
|
|
|
|
$ok = $self->ok( $test, $name ); |
|
476
|
0
|
|
0
|
|
|
0
|
} |
|
477
|
|
|
|
|
|
|
|
|
478
|
0
|
|
|
|
|
0
|
unless( $ok ) { |
|
479
|
0
|
0
|
|
|
|
0
|
$this = defined $this ? "'$this'" : 'undef'; |
|
480
|
0
|
|
|
|
|
0
|
my $match = $cmp eq '=~' ? "doesn't match" : "matches"; |
|
481
|
|
|
|
|
|
|
$self->diag(sprintf <
|
|
482
|
|
|
|
|
|
|
%s |
|
483
|
10
|
|
|
|
|
26
|
%13s '%s' |
|
484
|
|
|
|
|
|
|
DIAGNOSTIC |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
} |
|
487
|
0
|
|
|
0
|
1
|
0
|
|
|
488
|
0
|
|
|
|
|
0
|
return $ok; |
|
489
|
|
|
|
|
|
|
} |
|
490
|
0
|
0
|
0
|
|
|
0
|
|
|
491
|
|
|
|
|
|
|
#line 703 |
|
492
|
0
|
|
0
|
|
|
0
|
|
|
493
|
|
|
|
|
|
|
sub cmp_ok { |
|
494
|
0
|
|
|
|
|
0
|
my($self, $got, $type, $expect, $name) = @_; |
|
495
|
0
|
0
|
|
|
|
0
|
|
|
496
|
0
|
|
|
|
|
0
|
my $test; |
|
497
|
|
|
|
|
|
|
{ |
|
498
|
|
|
|
|
|
|
local $^W = 0; |
|
499
|
0
|
|
|
|
|
0
|
local($@,$!); # don't interfere with $@ |
|
500
|
|
|
|
|
|
|
# eval() sometimes resets $! |
|
501
|
|
|
|
|
|
|
$test = eval "\$got $type \$expect"; |
|
502
|
|
|
|
|
|
|
} |
|
503
|
0
|
|
|
0
|
|
0
|
local $Level = $Level + 1; |
|
504
|
|
|
|
|
|
|
my $ok = $self->ok($test, $name); |
|
505
|
0
|
|
|
|
|
0
|
|
|
506
|
0
|
0
|
|
|
|
0
|
unless( $ok ) { |
|
507
|
0
|
0
|
|
|
|
0
|
if( $type =~ /^(eq|==)$/ ) { |
|
508
|
|
|
|
|
|
|
$self->_is_diag($got, $type, $expect); |
|
509
|
0
|
|
|
|
|
0
|
} |
|
510
|
|
|
|
|
|
|
else { |
|
511
|
|
|
|
|
|
|
$self->_cmp_diag($got, $type, $expect); |
|
512
|
|
|
|
|
|
|
} |
|
513
|
0
|
|
|
|
|
0
|
} |
|
514
|
|
|
|
|
|
|
return $ok; |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
|
|
517
|
0
|
|
|
|
|
0
|
sub _cmp_diag { |
|
518
|
|
|
|
|
|
|
my($self, $got, $type, $expect) = @_; |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
$got = defined $got ? "'$got'" : 'undef'; |
|
521
|
0
|
|
|
|
|
0
|
$expect = defined $expect ? "'$expect'" : 'undef'; |
|
522
|
|
|
|
|
|
|
return $self->diag(sprintf <
|
|
523
|
|
|
|
|
|
|
%s |
|
524
|
|
|
|
|
|
|
%s |
|
525
|
|
|
|
|
|
|
%s |
|
526
|
|
|
|
|
|
|
DIAGNOSTIC |
|
527
|
|
|
|
|
|
|
} |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
#line 751 |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
sub BAILOUT { |
|
532
|
|
|
|
|
|
|
my($self, $reason) = @_; |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
$self->_print("Bail out! $reason"); |
|
535
|
|
|
|
|
|
|
exit 255; |
|
536
|
|
|
|
|
|
|
} |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
#line 767 |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
sub skip { |
|
541
|
|
|
|
|
|
|
my($self, $why) = @_; |
|
542
|
|
|
|
|
|
|
$why ||= ''; |
|
543
|
|
|
|
|
|
|
$self->_unoverload(\$why); |
|
544
|
|
|
|
|
|
|
|
|
545
|
0
|
|
|
0
|
1
|
0
|
unless( $Have_Plan ) { |
|
546
|
0
|
|
|
|
|
0
|
require Carp; |
|
547
|
|
|
|
|
|
|
Carp::croak("You tried to run tests without a plan! Gotta have a plan."); |
|
548
|
0
|
0
|
0
|
|
|
0
|
} |
|
549
|
|
|
|
|
|
|
|
|
550
|
0
|
|
0
|
|
|
0
|
lock($Curr_Test); |
|
551
|
|
|
|
|
|
|
$Curr_Test++; |
|
552
|
0
|
|
|
|
|
0
|
|
|
553
|
0
|
0
|
|
|
|
0
|
$Test_Results[$Curr_Test-1] = &share({ |
|
554
|
0
|
|
|
|
|
0
|
'ok' => 1, |
|
555
|
|
|
|
|
|
|
actual_ok => 1, |
|
556
|
|
|
|
|
|
|
name => '', |
|
557
|
0
|
|
|
|
|
0
|
type => 'skip', |
|
558
|
|
|
|
|
|
|
reason => $why, |
|
559
|
|
|
|
|
|
|
}); |
|
560
|
|
|
|
|
|
|
|
|
561
|
0
|
|
|
0
|
1
|
0
|
my $out = "ok"; |
|
562
|
0
|
|
|
|
|
0
|
$out .= " $Curr_Test" if $self->use_numbers; |
|
563
|
|
|
|
|
|
|
$out .= " # skip"; |
|
564
|
0
|
0
|
0
|
|
|
0
|
$out .= " $why" if length $why; |
|
565
|
|
|
|
|
|
|
$out .= "\n"; |
|
566
|
0
|
|
0
|
|
|
0
|
|
|
567
|
|
|
|
|
|
|
$Test->_print($out); |
|
568
|
0
|
|
|
|
|
0
|
|
|
569
|
0
|
0
|
|
|
|
0
|
return 1; |
|
570
|
0
|
|
|
|
|
0
|
} |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
|
|
573
|
0
|
|
|
|
|
0
|
#line 812 |
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
sub todo_skip { |
|
576
|
|
|
|
|
|
|
my($self, $why) = @_; |
|
577
|
|
|
|
|
|
|
$why ||= ''; |
|
578
|
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
unless( $Have_Plan ) { |
|
580
|
|
|
|
|
|
|
require Carp; |
|
581
|
|
|
|
|
|
|
Carp::croak("You tried to run tests without a plan! Gotta have a plan."); |
|
582
|
|
|
|
|
|
|
} |
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
lock($Curr_Test); |
|
585
|
|
|
|
|
|
|
$Curr_Test++; |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
$Test_Results[$Curr_Test-1] = &share({ |
|
588
|
|
|
|
|
|
|
'ok' => 1, |
|
589
|
|
|
|
|
|
|
actual_ok => 0, |
|
590
|
|
|
|
|
|
|
name => '', |
|
591
|
|
|
|
|
|
|
type => 'todo_skip', |
|
592
|
|
|
|
|
|
|
reason => $why, |
|
593
|
|
|
|
|
|
|
}); |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
my $out = "not ok"; |
|
596
|
|
|
|
|
|
|
$out .= " $Curr_Test" if $self->use_numbers; |
|
597
|
0
|
|
|
0
|
1
|
0
|
$out .= " # TODO & SKIP $why\n"; |
|
598
|
|
|
|
|
|
|
|
|
599
|
0
|
|
|
|
|
0
|
$Test->_print($out); |
|
600
|
0
|
|
|
|
|
0
|
|
|
601
|
|
|
|
|
|
|
return 1; |
|
602
|
|
|
|
|
|
|
} |
|
603
|
|
|
|
|
|
|
|
|
604
|
0
|
|
|
0
|
1
|
0
|
|
|
605
|
|
|
|
|
|
|
#line 883 |
|
606
|
0
|
|
|
|
|
0
|
|
|
607
|
0
|
|
|
|
|
0
|
sub level { |
|
608
|
|
|
|
|
|
|
my($self, $level) = @_; |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
if( defined $level ) { |
|
611
|
|
|
|
|
|
|
$Level = $level; |
|
612
|
|
|
|
|
|
|
} |
|
613
|
|
|
|
|
|
|
return $Level; |
|
614
|
|
|
|
|
|
|
} |
|
615
|
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
#line 918 |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
sub use_numbers { |
|
620
|
|
|
|
|
|
|
my($self, $use_nums) = @_; |
|
621
|
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
if( defined $use_nums ) { |
|
623
|
|
|
|
|
|
|
$Use_Nums = $use_nums; |
|
624
|
|
|
|
|
|
|
} |
|
625
|
|
|
|
|
|
|
return $Use_Nums; |
|
626
|
|
|
|
|
|
|
} |
|
627
|
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
#line 944 |
|
629
|
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
sub no_header { |
|
631
|
|
|
|
|
|
|
my($self, $no_header) = @_; |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
if( defined $no_header ) { |
|
634
|
|
|
|
|
|
|
$No_Header = $no_header; |
|
635
|
|
|
|
|
|
|
} |
|
636
|
|
|
|
|
|
|
return $No_Header; |
|
637
|
|
|
|
|
|
|
} |
|
638
|
|
|
|
|
|
|
|
|
639
|
0
|
|
|
0
|
1
|
0
|
sub no_ending { |
|
640
|
0
|
|
|
|
|
0
|
my($self, $no_ending) = @_; |
|
641
|
|
|
|
|
|
|
|
|
642
|
0
|
0
|
|
|
|
0
|
if( defined $no_ending ) { |
|
643
|
|
|
|
|
|
|
$No_Ending = $no_ending; |
|
644
|
0
|
|
|
|
|
0
|
} |
|
645
|
|
|
|
|
|
|
return $No_Ending; |
|
646
|
|
|
|
|
|
|
} |
|
647
|
0
|
0
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
648
|
0
|
|
|
|
|
0
|
|
|
649
|
|
|
|
|
|
|
#line 1000 |
|
650
|
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub diag { |
|
652
|
|
|
|
|
|
|
my($self, @msgs) = @_; |
|
653
|
|
|
|
|
|
|
return unless @msgs; |
|
654
|
|
|
|
|
|
|
|
|
655
|
0
|
0
|
|
|
|
0
|
# Prevent printing headers when compiling (i.e. -c) |
|
656
|
|
|
|
|
|
|
return if $^C; |
|
657
|
|
|
|
|
|
|
|
|
658
|
0
|
|
|
|
|
0
|
# Smash args together like print does. |
|
659
|
|
|
|
|
|
|
# Convert undef to 'undef' so its readable. |
|
660
|
|
|
|
|
|
|
my $msg = join '', map { defined($_) ? $_ : 'undef' } @msgs; |
|
661
|
|
|
|
|
|
|
|
|
662
|
0
|
|
|
0
|
|
0
|
# Escape each line with a #. |
|
663
|
|
|
|
|
|
|
$msg =~ s/^/# /gm; |
|
664
|
0
|
|
|
|
|
0
|
|
|
665
|
|
|
|
|
|
|
# Stick a newline on the end if it needs it. |
|
666
|
0
|
|
|
|
|
0
|
$msg .= "\n" unless $msg =~ /\n\Z/; |
|
667
|
0
|
|
|
|
|
0
|
|
|
668
|
0
|
0
|
|
|
|
0
|
local $Level = $Level + 1; |
|
669
|
0
|
|
|
|
|
0
|
$self->_print_diag($msg); |
|
670
|
0
|
|
|
|
|
0
|
|
|
671
|
0
|
|
|
|
|
0
|
return 0; |
|
672
|
|
|
|
|
|
|
} |
|
673
|
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
#line 1035 |
|
675
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
676
|
0
|
0
|
|
|
|
0
|
sub _print { |
|
677
|
0
|
0
|
|
|
|
0
|
my($self, @msgs) = @_; |
|
678
|
0
|
|
|
|
|
0
|
|
|
679
|
|
|
|
|
|
|
# Prevent printing headers when only compiling. Mostly for when |
|
680
|
|
|
|
|
|
|
# tests are deparsed with B::Deparse |
|
681
|
0
|
0
|
|
|
|
0
|
return if $^C; |
|
682
|
0
|
0
|
|
|
|
0
|
|
|
683
|
0
|
0
|
|
|
|
0
|
my $msg = join '', @msgs; |
|
684
|
0
|
|
|
|
|
0
|
|
|
685
|
|
|
|
|
|
|
local($\, $", $,) = (undef, ' ', ''); |
|
686
|
|
|
|
|
|
|
my $fh = $self->output; |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
# Escape each line after the first with a # so we don't |
|
689
|
|
|
|
|
|
|
# confuse Test::Harness. |
|
690
|
|
|
|
|
|
|
$msg =~ s/\n(.)/\n# $1/sg; |
|
691
|
0
|
|
|
|
|
0
|
|
|
692
|
|
|
|
|
|
|
# Stick a newline on the end if it needs it. |
|
693
|
|
|
|
|
|
|
$msg .= "\n" unless $msg =~ /\n\Z/; |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
print $fh $msg; |
|
696
|
|
|
|
|
|
|
} |
|
697
|
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
#line 1066 |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
sub _print_diag { |
|
702
|
|
|
|
|
|
|
my $self = shift; |
|
703
|
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
local($\, $", $,) = (undef, ' ', ''); |
|
705
|
10
|
|
|
10
|
1
|
19
|
my $fh = $self->todo ? $self->todo_output : $self->failure_output; |
|
706
|
|
|
|
|
|
|
print $fh @_; |
|
707
|
10
|
|
|
|
|
11
|
} |
|
708
|
|
|
|
|
|
|
|
|
709
|
10
|
|
|
|
|
10
|
#line 1103 |
|
|
10
|
|
|
|
|
38
|
|
|
710
|
10
|
|
|
|
|
23
|
|
|
711
|
|
|
|
|
|
|
my($Out_FH, $Fail_FH, $Todo_FH); |
|
712
|
10
|
|
|
|
|
593
|
sub output { |
|
713
|
|
|
|
|
|
|
my($self, $fh) = @_; |
|
714
|
10
|
|
|
|
|
31
|
|
|
715
|
10
|
|
|
|
|
26
|
if( defined $fh ) { |
|
716
|
|
|
|
|
|
|
$Out_FH = _new_fh($fh); |
|
717
|
10
|
50
|
|
|
|
25
|
} |
|
718
|
0
|
0
|
|
|
|
0
|
return $Out_FH; |
|
719
|
0
|
|
|
|
|
0
|
} |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
sub failure_output { |
|
722
|
0
|
|
|
|
|
0
|
my($self, $fh) = @_; |
|
723
|
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
if( defined $fh ) { |
|
725
|
10
|
|
|
|
|
262
|
$Fail_FH = _new_fh($fh); |
|
726
|
|
|
|
|
|
|
} |
|
727
|
|
|
|
|
|
|
return $Fail_FH; |
|
728
|
|
|
|
|
|
|
} |
|
729
|
0
|
|
|
0
|
|
0
|
|
|
730
|
|
|
|
|
|
|
sub todo_output { |
|
731
|
0
|
0
|
|
|
|
0
|
my($self, $fh) = @_; |
|
732
|
0
|
0
|
|
|
|
0
|
|
|
733
|
0
|
|
|
|
|
0
|
if( defined $fh ) { |
|
734
|
|
|
|
|
|
|
$Todo_FH = _new_fh($fh); |
|
735
|
|
|
|
|
|
|
} |
|
736
|
|
|
|
|
|
|
return $Todo_FH; |
|
737
|
|
|
|
|
|
|
} |
|
738
|
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
sub _new_fh { |
|
741
|
|
|
|
|
|
|
my($file_or_fh) = shift; |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
my $fh; |
|
744
|
|
|
|
|
|
|
if( _is_fh($file_or_fh) ) { |
|
745
|
|
|
|
|
|
|
$fh = $file_or_fh; |
|
746
|
|
|
|
|
|
|
} |
|
747
|
|
|
|
|
|
|
else { |
|
748
|
|
|
|
|
|
|
$fh = do { local *FH }; |
|
749
|
|
|
|
|
|
|
open $fh, ">$file_or_fh" or |
|
750
|
|
|
|
|
|
|
die "Can't open test output log $file_or_fh: $!"; |
|
751
|
|
|
|
|
|
|
} |
|
752
|
|
|
|
|
|
|
|
|
753
|
0
|
|
|
0
|
0
|
0
|
return $fh; |
|
754
|
|
|
|
|
|
|
} |
|
755
|
0
|
|
|
|
|
0
|
|
|
756
|
0
|
|
|
|
|
0
|
|
|
757
|
|
|
|
|
|
|
sub _is_fh { |
|
758
|
|
|
|
|
|
|
my $maybe_fh = shift; |
|
759
|
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
return 1 if ref \$maybe_fh eq 'GLOB'; # its a glob |
|
761
|
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
return UNIVERSAL::isa($maybe_fh, 'GLOB') || |
|
763
|
|
|
|
|
|
|
UNIVERSAL::isa($maybe_fh, 'IO::Handle') || |
|
764
|
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
# 5.5.4's tied() and can() doesn't like getting undef |
|
766
|
|
|
|
|
|
|
UNIVERSAL::can((tied($maybe_fh) || ''), 'TIEHANDLE'); |
|
767
|
|
|
|
|
|
|
} |
|
768
|
|
|
|
|
|
|
|
|
769
|
0
|
|
|
0
|
1
|
0
|
|
|
770
|
0
|
|
0
|
|
|
0
|
sub _autoflush { |
|
771
|
0
|
|
|
|
|
0
|
my($fh) = shift; |
|
772
|
|
|
|
|
|
|
my $old_fh = select $fh; |
|
773
|
0
|
0
|
|
|
|
0
|
$| = 1; |
|
774
|
0
|
|
|
|
|
0
|
select $old_fh; |
|
775
|
0
|
|
|
|
|
0
|
} |
|
776
|
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
|
|
778
|
0
|
|
|
|
|
0
|
my $Opened_Testhandles = 0; |
|
779
|
0
|
|
|
|
|
0
|
sub _dup_stdhandles { |
|
780
|
|
|
|
|
|
|
my $self = shift; |
|
781
|
0
|
|
|
|
|
0
|
|
|
782
|
|
|
|
|
|
|
$self->_open_testhandles unless $Opened_Testhandles; |
|
783
|
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
# Set everything to unbuffered else plain prints to STDOUT will |
|
785
|
|
|
|
|
|
|
# come out in the wrong order from our own prints. |
|
786
|
|
|
|
|
|
|
_autoflush(\*TESTOUT); |
|
787
|
|
|
|
|
|
|
_autoflush(\*STDOUT); |
|
788
|
|
|
|
|
|
|
_autoflush(\*TESTERR); |
|
789
|
0
|
|
|
|
|
0
|
_autoflush(\*STDERR); |
|
790
|
0
|
0
|
|
|
|
0
|
|
|
791
|
0
|
|
|
|
|
0
|
$Test->output(\*TESTOUT); |
|
792
|
0
|
0
|
|
|
|
0
|
$Test->failure_output(\*TESTERR); |
|
793
|
0
|
|
|
|
|
0
|
$Test->todo_output(\*TESTOUT); |
|
794
|
|
|
|
|
|
|
} |
|
795
|
0
|
|
|
|
|
0
|
|
|
796
|
|
|
|
|
|
|
sub _open_testhandles { |
|
797
|
0
|
|
|
|
|
0
|
# We dup STDOUT and STDERR so people can change them in their |
|
798
|
|
|
|
|
|
|
# test suites while still getting normal test output. |
|
799
|
|
|
|
|
|
|
open(TESTOUT, ">&STDOUT") or die "Can't dup STDOUT: $!"; |
|
800
|
|
|
|
|
|
|
open(TESTERR, ">&STDERR") or die "Can't dup STDERR: $!"; |
|
801
|
|
|
|
|
|
|
$Opened_Testhandles = 1; |
|
802
|
|
|
|
|
|
|
} |
|
803
|
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
#line 1218 |
|
806
|
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
sub current_test { |
|
808
|
|
|
|
|
|
|
my($self, $num) = @_; |
|
809
|
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
lock($Curr_Test); |
|
811
|
|
|
|
|
|
|
if( defined $num ) { |
|
812
|
|
|
|
|
|
|
unless( $Have_Plan ) { |
|
813
|
|
|
|
|
|
|
require Carp; |
|
814
|
0
|
|
|
0
|
1
|
0
|
Carp::croak("Can't change the current test number without a plan!"); |
|
815
|
0
|
|
0
|
|
|
0
|
} |
|
816
|
|
|
|
|
|
|
|
|
817
|
0
|
0
|
|
|
|
0
|
$Curr_Test = $num; |
|
818
|
0
|
|
|
|
|
0
|
|
|
819
|
0
|
|
|
|
|
0
|
# If the test counter is being pushed forward fill in the details. |
|
820
|
|
|
|
|
|
|
if( $num > @Test_Results ) { |
|
821
|
|
|
|
|
|
|
my $start = @Test_Results ? $#Test_Results + 1 : 0; |
|
822
|
0
|
|
|
|
|
0
|
for ($start..$num-1) { |
|
823
|
0
|
|
|
|
|
0
|
$Test_Results[$_] = &share({ |
|
824
|
|
|
|
|
|
|
'ok' => 1, |
|
825
|
0
|
|
|
|
|
0
|
actual_ok => undef, |
|
826
|
|
|
|
|
|
|
reason => 'incrementing test number', |
|
827
|
|
|
|
|
|
|
type => 'unknown', |
|
828
|
|
|
|
|
|
|
name => undef |
|
829
|
|
|
|
|
|
|
}); |
|
830
|
|
|
|
|
|
|
} |
|
831
|
|
|
|
|
|
|
} |
|
832
|
|
|
|
|
|
|
# If backward, wipe history. Its their funeral. |
|
833
|
0
|
|
|
|
|
0
|
elsif( $num < @Test_Results ) { |
|
834
|
0
|
0
|
|
|
|
0
|
$#Test_Results = $num - 1; |
|
835
|
0
|
|
|
|
|
0
|
} |
|
836
|
|
|
|
|
|
|
} |
|
837
|
0
|
|
|
|
|
0
|
return $Curr_Test; |
|
838
|
|
|
|
|
|
|
} |
|
839
|
0
|
|
|
|
|
0
|
|
|
840
|
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
#line 1263 |
|
842
|
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
sub summary { |
|
844
|
|
|
|
|
|
|
my($self) = shift; |
|
845
|
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
return map { $_->{'ok'} } @Test_Results; |
|
847
|
|
|
|
|
|
|
} |
|
848
|
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
#line 1318 |
|
850
|
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
sub details { |
|
852
|
|
|
|
|
|
|
return @Test_Results; |
|
853
|
|
|
|
|
|
|
} |
|
854
|
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
#line 1342 |
|
856
|
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
sub todo { |
|
858
|
|
|
|
|
|
|
my($self, $pack) = @_; |
|
859
|
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
$pack = $pack || $self->exported_to || $self->caller(1); |
|
861
|
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
no strict 'refs'; |
|
863
|
|
|
|
|
|
|
return defined ${$pack.'::TODO'} ? ${$pack.'::TODO'} |
|
864
|
|
|
|
|
|
|
: 0; |
|
865
|
|
|
|
|
|
|
} |
|
866
|
|
|
|
|
|
|
|
|
867
|
|
|
|
|
|
|
#line 1362 |
|
868
|
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
sub caller { |
|
870
|
|
|
|
|
|
|
my($self, $height) = @_; |
|
871
|
|
|
|
|
|
|
$height ||= 0; |
|
872
|
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
my @caller = CORE::caller($self->level + $height + 1); |
|
874
|
|
|
|
|
|
|
return wantarray ? @caller : $caller[0]; |
|
875
|
|
|
|
|
|
|
} |
|
876
|
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
#line 1374 |
|
878
|
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
#line 1388 |
|
880
|
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
#'# |
|
882
|
|
|
|
|
|
|
sub _sanity_check { |
|
883
|
|
|
|
|
|
|
_whoa($Curr_Test < 0, 'Says here you ran a negative number of tests!'); |
|
884
|
|
|
|
|
|
|
_whoa(!$Have_Plan and $Curr_Test, |
|
885
|
17
|
|
|
17
|
1
|
24
|
'Somehow your tests ran without a plan!'); |
|
886
|
|
|
|
|
|
|
_whoa($Curr_Test != @Test_Results, |
|
887
|
17
|
50
|
|
|
|
46
|
'Somehow you got a different number of results than tests ran!'); |
|
888
|
0
|
|
|
|
|
0
|
} |
|
889
|
|
|
|
|
|
|
|
|
890
|
17
|
|
|
|
|
122
|
#line 1407 |
|
891
|
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
sub _whoa { |
|
893
|
|
|
|
|
|
|
my($check, $desc) = @_; |
|
894
|
|
|
|
|
|
|
if( $check ) { |
|
895
|
|
|
|
|
|
|
die <
|
|
896
|
|
|
|
|
|
|
WHOA! $desc |
|
897
|
|
|
|
|
|
|
This should never happen! Please contact the author immediately! |
|
898
|
|
|
|
|
|
|
WHOA |
|
899
|
|
|
|
|
|
|
} |
|
900
|
|
|
|
|
|
|
} |
|
901
|
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
#line 1428 |
|
903
|
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
sub _my_exit { |
|
905
|
|
|
|
|
|
|
$? = $_[0]; |
|
906
|
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
return 1; |
|
908
|
|
|
|
|
|
|
} |
|
909
|
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
#line 1441 |
|
912
|
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
$SIG{__DIE__} = sub { |
|
914
|
|
|
|
|
|
|
# We don't want to muck with death in an eval, but $^S isn't |
|
915
|
|
|
|
|
|
|
# totally reliable. 5.005_03 and 5.6.1 both do the wrong thing |
|
916
|
|
|
|
|
|
|
# with it. Instead, we use caller. This also means it runs under |
|
917
|
|
|
|
|
|
|
# 5.004! |
|
918
|
|
|
|
|
|
|
my $in_eval = 0; |
|
919
|
|
|
|
|
|
|
for( my $stack = 1; my $sub = (CORE::caller($stack))[3]; $stack++ ) { |
|
920
|
17
|
|
|
17
|
1
|
24
|
$in_eval = 1 if $sub =~ /^\(eval\)/; |
|
921
|
|
|
|
|
|
|
} |
|
922
|
17
|
50
|
|
|
|
43
|
$Test_Died = 1 unless $in_eval; |
|
923
|
0
|
|
|
|
|
0
|
}; |
|
924
|
|
|
|
|
|
|
|
|
925
|
17
|
|
|
|
|
62
|
sub _ending { |
|
926
|
|
|
|
|
|
|
my $self = shift; |
|
927
|
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
_sanity_check(); |
|
929
|
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
# Don't bother with an ending if this is a forked copy. Only the parent |
|
931
|
|
|
|
|
|
|
# should do the ending. |
|
932
|
|
|
|
|
|
|
do{ _my_exit($?) && return } if $Original_Pid != $$; |
|
933
|
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
# Bailout if plan() was never called. This is so |
|
935
|
|
|
|
|
|
|
# "require Test::Simple" doesn't puke. |
|
936
|
|
|
|
|
|
|
do{ _my_exit(0) && return } if !$Have_Plan && !$Test_Died; |
|
937
|
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
# Figure out if we passed or failed and print helpful messages. |
|
939
|
|
|
|
|
|
|
if( @Test_Results ) { |
|
940
|
|
|
|
|
|
|
# The plan? We have no plan. |
|
941
|
|
|
|
|
|
|
if( $No_Plan ) { |
|
942
|
|
|
|
|
|
|
$self->_print("1..$Curr_Test\n") unless $self->no_header; |
|
943
|
|
|
|
|
|
|
$Expected_Tests = $Curr_Test; |
|
944
|
|
|
|
|
|
|
} |
|
945
|
|
|
|
|
|
|
|
|
946
|
5
|
|
|
5
|
1
|
9
|
# Auto-extended arrays and elements which aren't explicitly |
|
947
|
|
|
|
|
|
|
# filled in with a shared reference will puke under 5.8.0 |
|
948
|
5
|
50
|
|
|
|
18
|
# ithreads. So we have to fill them in by hand. :( |
|
949
|
0
|
|
|
|
|
0
|
my $empty_result = &share({}); |
|
950
|
|
|
|
|
|
|
for my $idx ( 0..$Expected_Tests-1 ) { |
|
951
|
5
|
|
|
|
|
37
|
$Test_Results[$idx] = $empty_result |
|
952
|
|
|
|
|
|
|
unless defined $Test_Results[$idx]; |
|
953
|
|
|
|
|
|
|
} |
|
954
|
|
|
|
|
|
|
|
|
955
|
5
|
|
|
5
|
1
|
13
|
my $num_failed = grep !$_->{'ok'}, @Test_Results[0..$Expected_Tests-1]; |
|
956
|
|
|
|
|
|
|
$num_failed += abs($Expected_Tests - @Test_Results); |
|
957
|
5
|
50
|
|
|
|
20
|
|
|
958
|
0
|
|
|
|
|
0
|
if( $Curr_Test < $Expected_Tests ) { |
|
959
|
|
|
|
|
|
|
my $s = $Expected_Tests == 1 ? '' : 's'; |
|
960
|
5
|
|
|
|
|
41
|
$self->diag(<<"FAIL"); |
|
961
|
|
|
|
|
|
|
Looks like you planned $Expected_Tests test$s but only ran $Curr_Test. |
|
962
|
|
|
|
|
|
|
FAIL |
|
963
|
|
|
|
|
|
|
} |
|
964
|
|
|
|
|
|
|
elsif( $Curr_Test > $Expected_Tests ) { |
|
965
|
|
|
|
|
|
|
my $num_extra = $Curr_Test - $Expected_Tests; |
|
966
|
|
|
|
|
|
|
my $s = $Expected_Tests == 1 ? '' : 's'; |
|
967
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
|
968
|
|
|
|
|
|
|
Looks like you planned $Expected_Tests test$s but ran $num_extra extra. |
|
969
|
|
|
|
|
|
|
FAIL |
|
970
|
|
|
|
|
|
|
} |
|
971
|
|
|
|
|
|
|
elsif ( $num_failed ) { |
|
972
|
|
|
|
|
|
|
my $s = $num_failed == 1 ? '' : 's'; |
|
973
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
|
974
|
|
|
|
|
|
|
Looks like you failed $num_failed test$s of $Expected_Tests. |
|
975
|
|
|
|
|
|
|
FAIL |
|
976
|
|
|
|
|
|
|
} |
|
977
|
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
if( $Test_Died ) { |
|
979
|
|
|
|
|
|
|
$self->diag(<<"FAIL"); |
|
980
|
|
|
|
|
|
|
Looks like your test died just after $Curr_Test. |
|
981
|
|
|
|
|
|
|
FAIL |
|
982
|
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
_my_exit( 255 ) && return; |
|
984
|
|
|
|
|
|
|
} |
|
985
|
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
_my_exit( $num_failed <= 254 ? $num_failed : 254 ) && return; |
|
987
|
|
|
|
|
|
|
} |
|
988
|
|
|
|
|
|
|
elsif ( $Skip_All ) { |
|
989
|
|
|
|
|
|
|
_my_exit( 0 ) && return; |
|
990
|
|
|
|
|
|
|
} |
|
991
|
|
|
|
|
|
|
elsif ( $Test_Died ) { |
|
992
|
|
|
|
|
|
|
$self->diag(<<'FAIL'); |
|
993
|
|
|
|
|
|
|
Looks like your test died before it could output anything. |
|
994
|
|
|
|
|
|
|
FAIL |
|
995
|
|
|
|
|
|
|
_my_exit( 255 ) && return; |
|
996
|
|
|
|
|
|
|
} |
|
997
|
|
|
|
|
|
|
else { |
|
998
|
|
|
|
|
|
|
$self->diag("No tests run!\n"); |
|
999
|
|
|
|
|
|
|
_my_exit( 255 ) && return; |
|
1000
|
|
|
|
|
|
|
} |
|
1001
|
|
|
|
|
|
|
} |
|
1002
|
1
|
|
|
1
|
1
|
4
|
|
|
1003
|
1
|
50
|
|
|
|
4
|
END { |
|
1004
|
|
|
|
|
|
|
$Test->_ending if defined $Test and !$Test->no_ending; |
|
1005
|
|
|
|
|
|
|
} |
|
1006
|
1
|
50
|
|
|
|
6
|
|
|
1007
|
|
|
|
|
|
|
#line 1589 |
|
1008
|
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
1; |