line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Test::Legacy - Test.pm workalike that plays well with other Test modules |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# use Test; |
9
|
|
|
|
|
|
|
use Test::Legacy; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
...leave all else the same... |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Test.pm suffers from the problem of not working well with other Test |
17
|
|
|
|
|
|
|
modules. If you have a test written using Test.pm and want to use another |
18
|
|
|
|
|
|
|
module, Test::Exception for example, you cannot. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Test::Legacy is a reimplementation of Test.pm using Test::Builder. |
21
|
|
|
|
|
|
|
What this means is Test::Legacy can be used with other Test::Builder |
22
|
|
|
|
|
|
|
derived modules (such as Test::More, Test::Exception, and most |
23
|
|
|
|
|
|
|
everything released in the last couple years) in the same test script. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Test::Legacy strives to work as much like Test.pm as possible. It |
26
|
|
|
|
|
|
|
allows one to continue to take advantage of additional Test modules |
27
|
|
|
|
|
|
|
without having to immediately rewrite all your tests to use Test::More. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 Test::Legacy and Test::More |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
You're often going to be wanting to use Test::Legacy in conjunction |
33
|
|
|
|
|
|
|
with Test::More. Because they export a bunch of the same functions |
34
|
|
|
|
|
|
|
they can get a little annoying to deal with. Fortunately, |
35
|
|
|
|
|
|
|
L is provided to smooth things out. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DIFFERENCES |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Test::Legacy does have some differences from Test.pm. Here are the known |
41
|
|
|
|
|
|
|
ones. Patches welcome. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item * diagnostics |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Because Test::Legacy uses Test::Builder for most of the work, failure |
48
|
|
|
|
|
|
|
diagnostics are not the same as Test.pm and are unlikely to ever be. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item * onfail |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Currently the onfail subroutine does not get passed a description of test |
54
|
|
|
|
|
|
|
failures. This is slated to be fixed in the future. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Michael G Schwern Eschwern@pobox.comE |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 COPYRIGHT |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Copyright 2004, 2005 by Michael G Schwern Eschwern@pobox.comE. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
69
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
See F |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NOTES |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This is an emulation of Test.pm 1.25. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SEE ALSO |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L, L, L |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
package Test::Legacy; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
require 5.004_05; |
88
|
|
|
|
|
|
|
|
89
|
13
|
|
|
13
|
|
8532
|
use strict; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
502
|
|
90
|
13
|
|
|
|
|
7983
|
use vars qw($VERSION |
91
|
|
|
|
|
|
|
@ISA @EXPORT @EXPORT_OK |
92
|
|
|
|
|
|
|
$TESTERR $TESTOUT |
93
|
|
|
|
|
|
|
$ntest |
94
|
13
|
|
|
13
|
|
71
|
); |
|
13
|
|
|
|
|
24
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$VERSION = '1.2502'; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
require Exporter; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
102
|
|
|
|
|
|
|
@EXPORT = qw(plan ok skip); |
103
|
|
|
|
|
|
|
@EXPORT_OK = qw($ntest $TESTOUT $TESTERR); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
13
|
|
|
13
|
|
176
|
use Carp; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
1116
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
13
|
|
|
13
|
|
15013
|
use Test::Builder; |
|
13
|
|
|
|
|
165533
|
|
|
13
|
|
|
|
|
9483
|
|
110
|
|
|
|
|
|
|
my $TB = Test::Builder->new; |
111
|
|
|
|
|
|
|
my $Self = { todo => {}, onfail => sub {} }; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
tie $TESTOUT, 'Test::Legacy::FH', $TB, 'output', 'todo_output'; |
115
|
|
|
|
|
|
|
tie $TESTERR, 'Test::Legacy::FH', $TB, 'failure_output'; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
tie $ntest, 'Test::Legacy::ntest', $TB; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _print { |
121
|
45
|
|
|
45
|
|
156
|
local($\, $,); # guard against -l and other things that screw with |
122
|
|
|
|
|
|
|
# print |
123
|
|
|
|
|
|
|
|
124
|
45
|
|
|
|
|
169
|
print $TESTOUT @_ |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub import { |
129
|
13
|
|
|
13
|
|
100
|
my $class = shift; |
130
|
|
|
|
|
|
|
|
131
|
13
|
|
|
|
|
34
|
my $caller = caller; |
132
|
|
|
|
|
|
|
|
133
|
13
|
|
|
|
|
68
|
$TB->exported_to($caller); |
134
|
|
|
|
|
|
|
|
135
|
13
|
|
|
|
|
16126
|
$class->export_to_level(1, $class, @_); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my %Plan_Keys = map { $_ => 1 } qw(test tests todo onfail); |
140
|
|
|
|
|
|
|
sub plan { |
141
|
15
|
|
|
15
|
0
|
1468
|
my %args = @_; |
142
|
|
|
|
|
|
|
|
143
|
15
|
50
|
|
|
|
88
|
croak "Test::plan(%args): odd number of arguments" if @_ & 1; |
144
|
|
|
|
|
|
|
|
145
|
15
|
50
|
|
|
|
176
|
if( my @unrecognized = grep !$Plan_Keys{$_}, keys %args ) { |
146
|
0
|
|
|
|
|
0
|
carp "Test::plan(): skipping unrecognized directive(s) @unrecognized"; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
15
|
100
|
|
|
|
92
|
$Self->{todo} = { map { $_ => 1 } @{$args{todo}} } if $args{todo}; |
|
14
|
|
|
|
|
55
|
|
|
4
|
|
|
|
|
16
|
|
150
|
15
|
100
|
|
|
|
69
|
$Self->{onfail} = $args{onfail} if $args{onfail}; |
151
|
|
|
|
|
|
|
|
152
|
15
|
|
66
|
|
|
195
|
$TB->plan( tests => $args{test} || $args{tests} ); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#### Taken from Test.pm 1.25 |
155
|
15
|
|
|
|
|
6864
|
_print "# Running under perl version $] for $^O", |
156
|
|
|
|
|
|
|
(chr(65) eq 'A') ? "\n" : " in a non-ASCII world\n"; |
157
|
|
|
|
|
|
|
|
158
|
15
|
50
|
33
|
|
|
1896
|
_print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n" |
159
|
|
|
|
|
|
|
if defined(&Win32::BuildNumber) and defined &Win32::BuildNumber(); |
160
|
|
|
|
|
|
|
|
161
|
15
|
50
|
|
|
|
80
|
_print "# MacPerl version $MacPerl::Version\n" |
162
|
|
|
|
|
|
|
if defined $MacPerl::Version; |
163
|
|
|
|
|
|
|
|
164
|
15
|
|
|
|
|
3799
|
_print sprintf |
165
|
|
|
|
|
|
|
"# Current time local: %s\n# Current time GMT: %s\n", |
166
|
|
|
|
|
|
|
scalar(localtime($^T)), scalar(gmtime($^T)); |
167
|
|
|
|
|
|
|
### End |
168
|
|
|
|
|
|
|
|
169
|
15
|
|
|
|
|
2108
|
_print "# Using Test::Legacy version $VERSION\n"; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
END { |
174
|
13
|
100
|
66
|
13
|
|
3081
|
$Self->{onfail}->() if $Self->{onfail} and _is_failing($TB); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub _is_failing { |
178
|
13
|
|
|
13
|
|
35
|
my $tb = shift; |
179
|
|
|
|
|
|
|
|
180
|
13
|
100
|
|
|
|
76
|
return grep(!$_, $tb->summary) ? 1 : 0; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _make_faildetail { |
184
|
0
|
|
|
0
|
|
0
|
my $tb = shift; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# package, repetition, result |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Taken from Test.pm 1.25 |
192
|
|
|
|
|
|
|
sub _to_value { |
193
|
147
|
|
|
147
|
|
252
|
my ($v) = @_; |
194
|
147
|
100
|
|
|
|
640
|
return ref $v eq 'CODE' ? $v->() : $v; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub ok ($;$$) { |
199
|
70
|
|
|
70
|
0
|
11915
|
my($got, $expected, $diag) = @_; |
200
|
70
|
|
|
|
|
234
|
($got, $expected) = map _to_value($_), ($got, $expected); |
201
|
|
|
|
|
|
|
|
202
|
70
|
|
|
|
|
238
|
my($caller, $file, $line) = caller; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# local doesn't work with soft refs in 5.5.4. So we do it manually. |
205
|
70
|
|
|
|
|
98
|
my $todo; |
206
|
|
|
|
|
|
|
{ |
207
|
13
|
|
|
13
|
|
151
|
no strict 'refs'; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
8133
|
|
|
70
|
|
|
|
|
91
|
|
208
|
70
|
|
|
|
|
688
|
$todo = \${ $caller .'::TODO' }; |
|
70
|
|
|
|
|
817
|
|
209
|
|
|
|
|
|
|
} |
210
|
70
|
|
|
|
|
107
|
my $orig_todo = $$todo; |
211
|
|
|
|
|
|
|
|
212
|
70
|
100
|
|
|
|
292
|
if( $Self->{todo}{$TB->current_test + 1} ) { |
213
|
14
|
|
|
|
|
169
|
$$todo = "set in plan, $file at line $line"; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
70
|
|
|
|
|
664
|
my $ok = 0; |
217
|
70
|
100
|
100
|
|
|
484
|
if( @_ == 1 ) { |
|
|
100
|
|
|
|
|
|
218
|
19
|
|
|
|
|
93
|
$ok = $TB->ok(@_) |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
elsif( defined $expected && $TB->maybe_regex($expected) ) { |
221
|
4
|
|
|
|
|
112
|
$ok = $TB->like($got, $expected); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
else { |
224
|
47
|
|
|
|
|
912
|
$ok = $TB->is_eq($got, $expected); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
70
|
|
|
|
|
46758
|
$$todo = $orig_todo; |
228
|
|
|
|
|
|
|
|
229
|
70
|
|
|
|
|
1015
|
return $ok; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub skip ($;$$$) { |
234
|
7
|
|
|
7
|
0
|
368
|
my $reason = _to_value(shift); |
235
|
|
|
|
|
|
|
|
236
|
7
|
100
|
|
|
|
50
|
if( $reason ) { |
237
|
6
|
100
|
|
|
|
27
|
$reason = '' if $reason !~ /\D/; |
238
|
6
|
|
|
|
|
23
|
return $TB->skip($reason); |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
else { |
241
|
1
|
|
|
|
|
5
|
goto &ok; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
package Test::Legacy::FH; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub TIESCALAR { |
249
|
26
|
|
|
26
|
|
64
|
my($class, $tb, @methods) = @_; |
250
|
26
|
|
|
|
|
120
|
bless { tb => $tb, methods => \@methods }, $_[0]; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub STORE { |
254
|
20
|
|
|
20
|
|
49724
|
my($self, $arg) = @_; |
255
|
|
|
|
|
|
|
|
256
|
20
|
|
|
|
|
99
|
my $tb = $self->{tb}; |
257
|
20
|
|
|
|
|
30
|
my @meths = @{ $self->{methods} }; |
|
20
|
|
|
|
|
103
|
|
258
|
|
|
|
|
|
|
|
259
|
20
|
|
|
|
|
46
|
foreach my $meth (@meths) { |
260
|
30
|
|
|
|
|
483
|
$tb->$meth($arg); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
20
|
|
|
|
|
457
|
return $arg; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub FETCH { |
267
|
45
|
|
|
45
|
|
75
|
my $self = shift; |
268
|
|
|
|
|
|
|
|
269
|
45
|
|
|
|
|
137
|
my $tb = $self->{tb}; |
270
|
45
|
|
|
|
|
66
|
my($meth) = @{ $self->{methods} }; |
|
45
|
|
|
|
|
539
|
|
271
|
|
|
|
|
|
|
|
272
|
45
|
|
|
|
|
180
|
return $tb->$meth(); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
package Test::Legacy::ntest; |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub TIESCALAR { |
279
|
13
|
|
|
13
|
|
28
|
my($class, $tb) = @_; |
280
|
|
|
|
|
|
|
|
281
|
13
|
|
|
|
|
56
|
bless { tb => $tb }, $class; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub FETCH { |
285
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
0
|
return $self->{tb}->current_test; |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub STORE { |
291
|
5
|
|
|
5
|
|
55
|
my($self, $val) = @_; |
292
|
|
|
|
|
|
|
|
293
|
5
|
|
|
|
|
56
|
return $self->{tb}->current_test($val - 1); |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
1; |