line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
6
|
|
|
6
|
|
4999
|
use strict; |
|
6
|
|
|
|
|
38
|
|
|
6
|
|
|
|
|
319
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Test::Tester; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN |
6
|
|
|
|
|
|
|
{ |
7
|
6
|
100
|
|
6
|
|
103
|
if (*Test::Builder::new{CODE}) |
8
|
|
|
|
|
|
|
{ |
9
|
1
|
|
|
|
|
28
|
warn "You should load Test::Tester before Test::Builder (or anything that loads Test::Builder)" |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
2918
|
use Test::Builder; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
189
|
|
14
|
6
|
|
|
6
|
|
2632
|
use Test::Tester::CaptureRunner; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
177
|
|
15
|
6
|
|
|
6
|
|
2126
|
use Test::Tester::Delegate; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
206
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
require Exporter; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
|
37
|
use vars qw( @ISA @EXPORT ); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
8680
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '1.302180'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
@EXPORT = qw( run_tests check_tests check_test cmp_results show_space ); |
24
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
27
|
|
|
|
|
|
|
my $Capture = Test::Tester::Capture->new; |
28
|
|
|
|
|
|
|
my $Delegator = Test::Tester::Delegate->new; |
29
|
|
|
|
|
|
|
$Delegator->{Object} = $Test; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $runner = Test::Tester::CaptureRunner->new; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $want_space = $ENV{TESTTESTERSPACE}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub show_space |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
1
|
0
|
$want_space = 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $colour = ''; |
41
|
|
|
|
|
|
|
my $reset = ''; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if (my $want_colour = $ENV{TESTTESTERCOLOUR} || $ENV{TESTTESTERCOLOR}) |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
if (eval { require Term::ANSIColor; 1 }) |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
eval { require Win32::Console::ANSI } if 'MSWin32' eq $^O; # support color on windows platforms |
48
|
|
|
|
|
|
|
my ($f, $b) = split(",", $want_colour); |
49
|
|
|
|
|
|
|
$colour = Term::ANSIColor::color($f).Term::ANSIColor::color("on_$b"); |
50
|
|
|
|
|
|
|
$reset = Term::ANSIColor::color("reset"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new_new |
56
|
|
|
|
|
|
|
{ |
57
|
7
|
|
|
7
|
0
|
1414
|
return $Delegator; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub capture |
61
|
|
|
|
|
|
|
{ |
62
|
3
|
|
|
3
|
0
|
45
|
return Test::Tester::Capture->new; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub fh |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
# experiment with capturing output, I don't like it |
68
|
0
|
|
|
0
|
0
|
0
|
$runner = Test::Tester::FHRunner->new; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
return $Test; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub find_run_tests |
74
|
|
|
|
|
|
|
{ |
75
|
26
|
|
|
26
|
0
|
38
|
my $d = 1; |
76
|
26
|
|
|
|
|
39
|
my $found = 0; |
77
|
26
|
|
66
|
|
|
180
|
while ((not $found) and (my ($sub) = (caller($d))[3]) ) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
# print "$d: $sub\n"; |
80
|
109
|
|
|
|
|
166
|
$found = ($sub eq "Test::Tester::run_tests"); |
81
|
109
|
|
|
|
|
432
|
$d++; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# die "Didn't find 'run_tests' in caller stack" unless $found; |
85
|
26
|
|
|
|
|
111
|
return $d; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub run_tests |
89
|
|
|
|
|
|
|
{ |
90
|
18
|
|
|
18
|
1
|
125
|
local($Delegator->{Object}) = $Capture; |
91
|
|
|
|
|
|
|
|
92
|
18
|
|
|
|
|
79
|
$runner->run_tests(@_); |
93
|
|
|
|
|
|
|
|
94
|
18
|
|
|
|
|
66
|
return ($runner->get_premature, $runner->get_results); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub check_test |
98
|
|
|
|
|
|
|
{ |
99
|
8
|
|
|
8
|
1
|
883
|
my $test = shift; |
100
|
8
|
|
|
|
|
10
|
my $expect = shift; |
101
|
8
|
|
|
|
|
16
|
my $name = shift; |
102
|
8
|
50
|
|
|
|
19
|
$name = "" unless defined($name); |
103
|
|
|
|
|
|
|
|
104
|
8
|
|
|
|
|
27
|
@_ = ($test, [$expect], $name); |
105
|
8
|
|
|
|
|
25
|
goto &check_tests; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub check_tests |
109
|
|
|
|
|
|
|
{ |
110
|
9
|
|
|
9
|
1
|
196
|
my $test = shift; |
111
|
9
|
|
|
|
|
15
|
my $expects = shift; |
112
|
9
|
|
|
|
|
15
|
my $name = shift; |
113
|
9
|
50
|
|
|
|
20
|
$name = "" unless defined($name); |
114
|
|
|
|
|
|
|
|
115
|
9
|
|
|
|
|
13
|
my ($prem, @results) = eval { run_tests($test, $name) }; |
|
9
|
|
|
|
|
18
|
|
116
|
|
|
|
|
|
|
|
117
|
9
|
50
|
|
|
|
89
|
$Test->ok(! $@, "Test '$name' completed") || $Test->diag($@); |
118
|
9
|
50
|
|
|
|
44
|
$Test->ok(! length($prem), "Test '$name' no premature diagnostication") || |
119
|
|
|
|
|
|
|
$Test->diag("Before any testing anything, your tests said\n$prem"); |
120
|
|
|
|
|
|
|
|
121
|
9
|
|
|
|
|
22
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
122
|
9
|
|
|
|
|
37
|
cmp_results(\@results, $expects, $name); |
123
|
9
|
|
|
|
|
327
|
return ($prem, @results); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub cmp_field |
127
|
|
|
|
|
|
|
{ |
128
|
80
|
|
|
80
|
0
|
164
|
my ($result, $expect, $field, $desc) = @_; |
129
|
|
|
|
|
|
|
|
130
|
80
|
50
|
|
|
|
222
|
if (defined $expect->{$field}) |
131
|
|
|
|
|
|
|
{ |
132
|
80
|
|
|
|
|
327
|
$Test->is_eq($result->{$field}, $expect->{$field}, |
133
|
|
|
|
|
|
|
"$desc compare $field"); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub cmp_result |
138
|
|
|
|
|
|
|
{ |
139
|
16
|
|
|
16
|
1
|
36
|
my ($result, $expect, $name) = @_; |
140
|
|
|
|
|
|
|
|
141
|
16
|
|
|
|
|
44
|
my $sub_name = $result->{name}; |
142
|
16
|
50
|
|
|
|
35
|
$sub_name = "" unless defined($name); |
143
|
|
|
|
|
|
|
|
144
|
16
|
|
|
|
|
48
|
my $desc = "subtest '$sub_name' of '$name'"; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
{ |
147
|
16
|
|
|
|
|
24
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
16
|
|
|
|
|
23
|
|
148
|
|
|
|
|
|
|
|
149
|
16
|
|
|
|
|
41
|
cmp_field($result, $expect, "ok", $desc); |
150
|
|
|
|
|
|
|
|
151
|
16
|
|
|
|
|
46
|
cmp_field($result, $expect, "actual_ok", $desc); |
152
|
|
|
|
|
|
|
|
153
|
16
|
|
|
|
|
86
|
cmp_field($result, $expect, "type", $desc); |
154
|
|
|
|
|
|
|
|
155
|
16
|
|
|
|
|
59
|
cmp_field($result, $expect, "reason", $desc); |
156
|
|
|
|
|
|
|
|
157
|
16
|
|
|
|
|
60
|
cmp_field($result, $expect, "name", $desc); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# if we got no depth then default to 1 |
161
|
16
|
|
|
|
|
50
|
my $depth = 1; |
162
|
16
|
50
|
|
|
|
48
|
if (exists $expect->{depth}) |
163
|
|
|
|
|
|
|
{ |
164
|
16
|
|
|
|
|
32
|
$depth = $expect->{depth}; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# if depth was explicitly undef then don't test it |
168
|
16
|
50
|
|
|
|
43
|
if (defined $depth) |
169
|
|
|
|
|
|
|
{ |
170
|
16
|
50
|
|
|
|
47
|
$Test->is_eq($result->{depth}, $depth, "checking depth") || |
171
|
|
|
|
|
|
|
$Test->diag('You need to change $Test::Builder::Level'); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
16
|
50
|
|
|
|
62
|
if (defined(my $exp = $expect->{diag})) |
175
|
|
|
|
|
|
|
{ |
176
|
|
|
|
|
|
|
|
177
|
16
|
|
|
|
|
24
|
my $got = ''; |
178
|
16
|
100
|
|
|
|
49
|
if (ref $exp eq 'Regexp') { |
179
|
|
|
|
|
|
|
|
180
|
4
|
50
|
|
|
|
30
|
if (not $Test->like($result->{diag}, $exp, |
181
|
|
|
|
|
|
|
"subtest '$sub_name' of '$name' compare diag")) |
182
|
|
|
|
|
|
|
{ |
183
|
0
|
|
|
|
|
0
|
$got = $result->{diag}; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} else { |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# if there actually is some diag then put a \n on the end if it's not |
189
|
|
|
|
|
|
|
# there already |
190
|
12
|
100
|
100
|
|
|
90
|
$exp .= "\n" if (length($exp) and $exp !~ /\n$/); |
191
|
|
|
|
|
|
|
|
192
|
12
|
50
|
|
|
|
59
|
if (not $Test->ok($result->{diag} eq $exp, |
193
|
|
|
|
|
|
|
"subtest '$sub_name' of '$name' compare diag")) |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
|
|
0
|
$got = $result->{diag}; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
16
|
50
|
|
|
|
120
|
if ($got) { |
200
|
0
|
|
|
|
|
0
|
my $glen = length($got); |
201
|
0
|
|
|
|
|
0
|
my $elen = length($exp); |
202
|
0
|
|
|
|
|
0
|
for ($got, $exp) |
203
|
|
|
|
|
|
|
{ |
204
|
0
|
|
|
|
|
0
|
my @lines = split("\n", $_); |
205
|
|
|
|
|
|
|
$_ = join("\n", map { |
206
|
0
|
0
|
|
|
|
0
|
if ($want_space) |
|
0
|
|
|
|
|
0
|
|
207
|
|
|
|
|
|
|
{ |
208
|
0
|
|
|
|
|
0
|
$_ = $colour.escape($_).$reset; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
else |
211
|
|
|
|
|
|
|
{ |
212
|
0
|
|
|
|
|
0
|
"'$colour$_$reset'" |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} @lines); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
0
|
$Test->diag(<
|
218
|
|
|
|
|
|
|
Got diag ($glen bytes): |
219
|
|
|
|
|
|
|
$got |
220
|
|
|
|
|
|
|
Expected diag ($elen bytes): |
221
|
|
|
|
|
|
|
$exp |
222
|
|
|
|
|
|
|
EOM |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub escape |
228
|
|
|
|
|
|
|
{ |
229
|
0
|
|
|
0
|
0
|
0
|
my $str = shift; |
230
|
0
|
|
|
|
|
0
|
my $res = ''; |
231
|
0
|
|
|
|
|
0
|
for my $char (split("", $str)) |
232
|
|
|
|
|
|
|
{ |
233
|
0
|
|
|
|
|
0
|
my $c = ord($char); |
234
|
0
|
0
|
0
|
|
|
0
|
if(($c>32 and $c<125) or $c == 10) |
|
|
|
0
|
|
|
|
|
235
|
|
|
|
|
|
|
{ |
236
|
0
|
|
|
|
|
0
|
$res .= $char; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
else |
239
|
|
|
|
|
|
|
{ |
240
|
0
|
|
|
|
|
0
|
$res .= sprintf('\x{%x}', $c) |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
} |
243
|
0
|
|
|
|
|
0
|
return $res; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub cmp_results |
247
|
|
|
|
|
|
|
{ |
248
|
9
|
|
|
9
|
1
|
20
|
my ($results, $expects, $name) = @_; |
249
|
|
|
|
|
|
|
|
250
|
9
|
|
|
|
|
42
|
$Test->is_num(scalar @$results, scalar @$expects, "Test '$name' result count"); |
251
|
|
|
|
|
|
|
|
252
|
9
|
|
|
|
|
34
|
for (my $i = 0; $i < @$expects; $i++) |
253
|
|
|
|
|
|
|
{ |
254
|
16
|
|
|
|
|
33
|
my $expect = $expects->[$i]; |
255
|
16
|
|
|
|
|
28
|
my $result = $results->[$i]; |
256
|
|
|
|
|
|
|
|
257
|
16
|
|
|
|
|
34
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
258
|
16
|
|
|
|
|
36
|
cmp_result($result, $expect, $name); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
######## nicked from Test::More |
263
|
|
|
|
|
|
|
sub plan { |
264
|
5
|
|
|
5
|
0
|
11
|
my(@plan) = @_; |
265
|
|
|
|
|
|
|
|
266
|
5
|
|
|
|
|
12
|
my $caller = caller; |
267
|
|
|
|
|
|
|
|
268
|
5
|
|
|
|
|
25
|
$Test->exported_to($caller); |
269
|
|
|
|
|
|
|
|
270
|
5
|
|
|
|
|
10
|
my @imports = (); |
271
|
5
|
|
|
|
|
29
|
foreach my $idx (0..$#plan) { |
272
|
2
|
50
|
|
|
|
6
|
if( $plan[$idx] eq 'import' ) { |
273
|
0
|
|
|
|
|
0
|
my($tag, $imports) = splice @plan, $idx, 2; |
274
|
0
|
|
|
|
|
0
|
@imports = @$imports; |
275
|
0
|
|
|
|
|
0
|
last; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
5
|
|
|
|
|
25
|
$Test->plan(@plan); |
280
|
|
|
|
|
|
|
|
281
|
5
|
|
|
|
|
27
|
__PACKAGE__->_export_to_level(1, __PACKAGE__, @imports); |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub import { |
285
|
5
|
|
|
5
|
|
48
|
my($class) = shift; |
286
|
|
|
|
|
|
|
{ |
287
|
6
|
|
|
6
|
|
59
|
no warnings 'redefine'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
918
|
|
|
5
|
|
|
|
|
10
|
|
288
|
5
|
|
|
|
|
28
|
*Test::Builder::new = \&new_new; |
289
|
|
|
|
|
|
|
} |
290
|
5
|
|
|
|
|
29
|
goto &plan; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub _export_to_level |
294
|
|
|
|
|
|
|
{ |
295
|
5
|
|
|
5
|
|
11
|
my $pkg = shift; |
296
|
5
|
|
|
|
|
9
|
my $level = shift; |
297
|
5
|
|
|
|
|
11
|
(undef) = shift; # redundant arg |
298
|
5
|
|
|
|
|
12
|
my $callpkg = caller($level); |
299
|
5
|
|
|
|
|
612
|
$pkg->export($callpkg, @_); |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
############ |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
1; |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
__END__ |