line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
16
|
|
|
16
|
|
20503
|
use 5.006001; |
|
16
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
519
|
|
2
|
16
|
|
|
16
|
|
54
|
use strict; |
|
16
|
|
|
|
|
18
|
|
|
16
|
|
|
|
|
386
|
|
3
|
16
|
|
|
16
|
|
57
|
use warnings; |
|
16
|
|
|
|
|
15
|
|
|
16
|
|
|
|
|
1048
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Test::Modern; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.013'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERBOSE; |
11
|
|
|
|
|
|
|
|
12
|
16
|
|
|
16
|
|
68
|
use Cwd 0 qw(); |
|
16
|
|
|
|
|
224
|
|
|
16
|
|
|
|
|
358
|
|
13
|
16
|
|
|
16
|
|
8146
|
use Exporter::Tiny 0.030 qw(); |
|
16
|
|
|
|
|
37517
|
|
|
16
|
|
|
|
|
359
|
|
14
|
16
|
|
|
16
|
|
82
|
use File::Spec 0 qw(); |
|
16
|
|
|
|
|
197
|
|
|
16
|
|
|
|
|
263
|
|
15
|
16
|
|
|
16
|
|
7652
|
use IO::File 1.08 qw(); |
|
16
|
|
|
|
|
114128
|
|
|
16
|
|
|
|
|
437
|
|
16
|
16
|
|
|
16
|
|
91
|
use IO::Handle 1.21 qw(); |
|
16
|
|
|
|
|
191
|
|
|
16
|
|
|
|
|
282
|
|
17
|
16
|
|
|
16
|
|
7321
|
use Import::Into 1.002 qw(); |
|
16
|
|
|
|
|
34299
|
|
|
16
|
|
|
|
|
396
|
|
18
|
16
|
|
|
16
|
|
178
|
use Module::Runtime 0.012 qw( require_module module_notional_filename ); |
|
16
|
|
|
|
|
195
|
|
|
16
|
|
|
|
|
63
|
|
19
|
16
|
|
|
16
|
|
8689
|
use Test::More 0.96; |
|
16
|
|
|
|
|
191232
|
|
|
16
|
|
|
|
|
132
|
|
20
|
16
|
|
|
16
|
|
11142
|
use Test::API 0.004; |
|
16
|
|
|
|
|
21247
|
|
|
16
|
|
|
|
|
102
|
|
21
|
16
|
|
|
16
|
|
8658
|
use Test::Fatal 0.007; |
|
16
|
|
|
|
|
46498
|
|
|
16
|
|
|
|
|
955
|
|
22
|
16
|
50
|
|
16
|
|
6891
|
use Test::Warnings 0.009 qw( warning warnings ), ($ENV{PERL_TEST_MODERN_ALLOW_WARNINGS} ? ':no_end_test' : ()); |
|
16
|
|
|
|
|
21990
|
|
|
16
|
|
|
|
|
113
|
|
23
|
16
|
|
|
16
|
|
10823
|
use Test::Deep 0.111 qw( :v1 ); |
|
16
|
|
|
|
|
128509
|
|
|
16
|
|
|
|
|
4581
|
|
24
|
16
|
|
|
16
|
|
102
|
use Try::Tiny 0.15 qw( try catch ); |
|
16
|
|
|
|
|
224
|
|
|
16
|
|
|
|
|
16614
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %HINTS; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$HINTS{ extended } = sub |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
return if $ENV{EXTENDED_TESTING}; |
31
|
|
|
|
|
|
|
plan skip_all => 'Not running extended tests'; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$HINTS{ author } = sub |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
return if $ENV{AUTHOR_TESTING}; |
37
|
|
|
|
|
|
|
plan skip_all => 'Not running author tests'; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$HINTS{ release } = sub |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
return if $ENV{RELEASE_TESTING}; |
43
|
|
|
|
|
|
|
plan skip_all => 'Not running release tests'; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$HINTS{ interactive } = sub |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
return unless $ENV{AUTOMATED_TESTING}; |
49
|
|
|
|
|
|
|
plan skip_all => 'Not running interactive tests'; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$HINTS{ requires } = sub |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
my %requires = %{ $_[2] }; |
55
|
|
|
|
|
|
|
for my $module (sort keys %requires) |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
if ($module eq 'perl') |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
next if !defined($requires{$module}); |
60
|
|
|
|
|
|
|
next if $] >= $requires{$module}; |
61
|
|
|
|
|
|
|
return plan skip_all => sprintf( |
62
|
|
|
|
|
|
|
"Test requires Perl %s", |
63
|
|
|
|
|
|
|
$requires{$module}, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
try { |
68
|
|
|
|
|
|
|
&require_module( |
69
|
|
|
|
|
|
|
$module, |
70
|
|
|
|
|
|
|
defined($requires{$module}) ? $requires{$module} : (), |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
catch { |
74
|
|
|
|
|
|
|
plan skip_all => sprintf( |
75
|
|
|
|
|
|
|
"Test requires %s%s", |
76
|
|
|
|
|
|
|
$module, |
77
|
|
|
|
|
|
|
defined($requires{$module}) ? " $requires{$module}" : "", |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$HINTS{ lib } = sub { $_[3]{lib}++; () }; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
my ($installed, %hide) = 0; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# This implementation stolen from Devel::Hide. Keep the |
90
|
|
|
|
|
|
|
# Perl-5.6 compatible implementation, because one day it |
91
|
|
|
|
|
|
|
# might be nice if this module could support Perl 5.6. |
92
|
|
|
|
|
|
|
my $_scalar_as_io = ($] >= 5.008) |
93
|
|
|
|
|
|
|
? sub { |
94
|
1
|
|
|
1
|
|
4
|
open(my($io), '<', \$_[0]) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
95
|
|
|
|
|
|
|
or die("Cannot open scalarref for IO?!"); |
96
|
|
|
|
|
|
|
return $io; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
: sub { |
99
|
|
|
|
|
|
|
my $scalar = shift; |
100
|
|
|
|
|
|
|
require File::Temp; |
101
|
|
|
|
|
|
|
my $io = File::Temp::tempfile(); |
102
|
|
|
|
|
|
|
print {$io} $scalar; |
103
|
|
|
|
|
|
|
seek $io, 0, 0; # rewind the handle |
104
|
|
|
|
|
|
|
return $io; |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $inc = sub |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
my (undef, $file) = @_; |
110
|
|
|
|
|
|
|
if ($hide{$file}) |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
my $oops = sprintf( |
113
|
|
|
|
|
|
|
qq{die "Can't locate %s (hidden by %s)\\n";}, |
114
|
|
|
|
|
|
|
$file, |
115
|
|
|
|
|
|
|
__PACKAGE__, |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
return $_scalar_as_io->($oops); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
return; |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$HINTS{ without } = sub |
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
unless ($installed) |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
unshift(@INC, $inc); |
127
|
|
|
|
|
|
|
++$installed; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my @without = @{ $_[2] }; |
131
|
|
|
|
|
|
|
for my $module (@without) |
132
|
|
|
|
|
|
|
{ |
133
|
|
|
|
|
|
|
my $file = module_notional_filename($module); |
134
|
|
|
|
|
|
|
exists($INC{$file}) |
135
|
|
|
|
|
|
|
? plan(skip_all => sprintf("cannot prevent $module from loading (it is already loaded)")) |
136
|
|
|
|
|
|
|
: ++$hide{$file}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
return; |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
{ |
143
|
|
|
|
|
|
|
my $checker; |
144
|
|
|
|
|
|
|
$checker = sub { |
145
|
|
|
|
|
|
|
$checker = eval q{ |
146
|
|
|
|
|
|
|
package # |
147
|
|
|
|
|
|
|
Dummy::Test::RequiresInternet; |
148
|
|
|
|
|
|
|
use Socket; |
149
|
|
|
|
|
|
|
sub { |
150
|
|
|
|
|
|
|
my ($host, $port) = @_; |
151
|
|
|
|
|
|
|
my $portnum = ($port =~ /[^0-9]/) ? getservbyname($port, "tcp") : $port; |
152
|
|
|
|
|
|
|
die "Could not find a port number for $port\n" if not $portnum; |
153
|
|
|
|
|
|
|
my $iaddr = inet_aton($host) or die "no host: $host\n"; |
154
|
|
|
|
|
|
|
my $paddr = sockaddr_in($portnum, $iaddr); |
155
|
|
|
|
|
|
|
my $proto = getprotobyname("tcp"); |
156
|
|
|
|
|
|
|
socket(my $sock, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n"; |
157
|
|
|
|
|
|
|
connect($sock, $paddr) or die "connect: $!\n"; |
158
|
|
|
|
|
|
|
close($sock) or die "close: $!\n"; |
159
|
|
|
|
|
|
|
!!1; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
goto($checker); |
163
|
|
|
|
|
|
|
}; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$HINTS{ internet } = sub |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
plan skip_all => 'Not running network tests' |
168
|
|
|
|
|
|
|
if $ENV{NO_NETWORK_TESTING}; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $arg = $_[2]; |
171
|
|
|
|
|
|
|
my @hosts = |
172
|
|
|
|
|
|
|
ref($arg) eq q(HASH) ? %$arg : |
173
|
|
|
|
|
|
|
ref($arg) eq q(ARRAY) ? @$arg : |
174
|
|
|
|
|
|
|
ref($arg) eq q(SCALAR) ? ( $$arg => 80 ) : |
175
|
|
|
|
|
|
|
( 'www.google.com' => 80 ); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
while (@hosts) { |
178
|
|
|
|
|
|
|
my ($host, $port) = splice(@hosts, 0, 2); |
179
|
|
|
|
|
|
|
defined($host) && defined($port) |
180
|
|
|
|
|
|
|
or BAIL_OUT("Expected host+port pair (not undef)"); |
181
|
|
|
|
|
|
|
eval { $checker->($host, $port); 1 } or plan skip_all => "$@"; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
return; |
185
|
|
|
|
|
|
|
}; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$HINTS{ benchmark } = sub |
189
|
|
|
|
|
|
|
{ |
190
|
|
|
|
|
|
|
return qw(is_fastest) |
191
|
|
|
|
|
|
|
if $ENV{RELEASE_TESTING} || $ENV{EXTENDED_TESTING}; |
192
|
|
|
|
|
|
|
plan skip_all => 'Not running benchmarks'; |
193
|
|
|
|
|
|
|
}; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$HINTS{ verbose } = sub { $VERBOSE = 1; () }; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
our @ISA = qw(Exporter::Tiny); |
198
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
199
|
|
|
|
|
|
|
more => [qw( |
200
|
|
|
|
|
|
|
ok is isnt like unlike is_deeply cmp_ok new_ok isa_ok can_ok |
201
|
|
|
|
|
|
|
pass fail |
202
|
|
|
|
|
|
|
diag note explain |
203
|
|
|
|
|
|
|
subtest |
204
|
|
|
|
|
|
|
skip todo_skip plan done_testing BAIL_OUT |
205
|
|
|
|
|
|
|
)], |
206
|
|
|
|
|
|
|
fatal => [qw( exception )], |
207
|
|
|
|
|
|
|
warnings => [qw( warnings warning )], |
208
|
|
|
|
|
|
|
api => [qw( public_ok import_ok class_api_ok )], |
209
|
|
|
|
|
|
|
moose => [qw( does_ok )], |
210
|
|
|
|
|
|
|
pod => [qw( |
211
|
|
|
|
|
|
|
pod_file_ok all_pod_files_ok |
212
|
|
|
|
|
|
|
pod_coverage_ok all_pod_coverage_ok |
213
|
|
|
|
|
|
|
)], |
214
|
|
|
|
|
|
|
versions => [qw( version_ok version_all_ok version_all_same )], |
215
|
|
|
|
|
|
|
strings => [qw( |
216
|
|
|
|
|
|
|
is_string is_string_nows like_string unlike_string |
217
|
|
|
|
|
|
|
contains_string lacks_string |
218
|
|
|
|
|
|
|
)], |
219
|
|
|
|
|
|
|
clean => [qw( namespaces_clean )], |
220
|
|
|
|
|
|
|
deep => [qw( cmp_deeply TD )], |
221
|
|
|
|
|
|
|
deeper => [qw( |
222
|
|
|
|
|
|
|
cmp_deeply TD |
223
|
|
|
|
|
|
|
ignore methods listmethods shallow noclass useclass |
224
|
|
|
|
|
|
|
re superhashof subhashof bag superbagof subbagof |
225
|
|
|
|
|
|
|
set supersetof subsetof all any obj_isa array_each |
226
|
|
|
|
|
|
|
str num bool code |
227
|
|
|
|
|
|
|
)], |
228
|
|
|
|
|
|
|
deprecated => [qw( use_ok require_ok eq_array eq_hash eq_set )], |
229
|
|
|
|
|
|
|
%HINTS, |
230
|
|
|
|
|
|
|
); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
233
|
|
|
|
|
|
|
'object_ok', 'shouldnt_warn', 'is_fastest', |
234
|
|
|
|
|
|
|
map(@$_, grep { ref($_) eq 'ARRAY' } values(%EXPORT_TAGS)), |
235
|
|
|
|
|
|
|
); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
our @EXPORT = ( |
238
|
|
|
|
|
|
|
'object_ok', |
239
|
|
|
|
|
|
|
map(@{$EXPORT_TAGS{$_}}, qw(more fatal warnings api moose strings deep clean)), |
240
|
|
|
|
|
|
|
); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
# Here we check to see if the import list consists |
243
|
|
|
|
|
|
|
# only of hints. If so, we add @EXPORT to the list. |
244
|
|
|
|
|
|
|
# This means that `use Test::Modern -extended;` |
245
|
|
|
|
|
|
|
# won't result in the standard exports getting |
246
|
|
|
|
|
|
|
# suppressed. |
247
|
|
|
|
|
|
|
# |
248
|
|
|
|
|
|
|
sub import |
249
|
|
|
|
|
|
|
{ |
250
|
20
|
|
|
20
|
|
3241
|
my $me = shift; |
251
|
38
|
100
|
100
|
|
|
263
|
my $symbols = grep { |
|
|
100
|
|
|
|
|
|
252
|
20
|
|
|
|
|
30
|
ref($_) ? 0 : # refs are not symbols |
253
|
|
|
|
|
|
|
/\A[:-](\w+)\z/ && $HINTS{$1} ? 0 : # hints are not symbols |
254
|
|
|
|
|
|
|
1; # everything else is |
255
|
|
|
|
|
|
|
} @_; |
256
|
|
|
|
|
|
|
|
257
|
20
|
100
|
|
|
|
773
|
push @_, @EXPORT if $symbols == 0; |
258
|
|
|
|
|
|
|
|
259
|
20
|
100
|
|
|
|
1414
|
my $globals = ref($_[0]) eq 'HASH' ? shift() : {}; |
260
|
20
|
100
|
|
|
|
742
|
$globals->{into_file} = (caller)[1] unless ref($globals->{into}); |
261
|
|
|
|
|
|
|
|
262
|
20
|
|
|
|
|
705
|
unshift @_, $me, $globals; |
263
|
20
|
|
|
|
|
94
|
goto \&Exporter::Tiny::import; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub _exporter_validate_opts |
267
|
|
|
|
|
|
|
{ |
268
|
16
|
|
|
16
|
|
14950
|
my $me = shift; |
269
|
16
|
|
|
|
|
27
|
my ($opts) = @_; |
270
|
16
|
|
|
|
|
27
|
my $caller = $opts->{into}; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
# Exporter::Tiny can't handle exporting variables |
273
|
|
|
|
|
|
|
# at the moment. :-( |
274
|
|
|
|
|
|
|
# |
275
|
|
|
|
|
|
|
{ |
276
|
16
|
|
|
16
|
|
83
|
no strict qw(refs); |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
20137
|
|
|
16
|
|
|
|
|
15
|
|
277
|
16
|
100
|
|
|
|
51
|
(ref($caller) ? $caller->{'$TODO'} : *{"$caller\::TODO"}) |
|
10
|
|
|
|
|
52
|
|
278
|
|
|
|
|
|
|
= \$Test::More::TODO; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
16
|
100
|
|
|
|
43
|
return if ref $caller; |
282
|
10
|
|
|
|
|
66
|
'strict'->import::into($caller); |
283
|
10
|
|
|
|
|
1964
|
'warnings'->import::into($caller); |
284
|
10
|
|
|
|
|
1389
|
$me->_setup_inc($opts); |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub _setup_inc |
288
|
|
|
|
|
|
|
{ |
289
|
10
|
|
|
10
|
|
17
|
shift; |
290
|
10
|
|
|
|
|
17
|
my ($opts) = @_; |
291
|
|
|
|
|
|
|
|
292
|
10
|
50
|
|
|
|
34
|
return unless exists($opts->{into_file}); |
293
|
|
|
|
|
|
|
|
294
|
10
|
|
|
|
|
12
|
my $dir = do { |
295
|
10
|
|
|
|
|
181
|
my ($v, $d) = 'File::Spec'->splitpath($opts->{into_file}); |
296
|
10
|
|
|
|
|
163
|
'File::Spec'->catpath($v, $d, ''); |
297
|
|
|
|
|
|
|
}; |
298
|
|
|
|
|
|
|
|
299
|
10
|
|
|
|
|
16
|
my $found; |
300
|
10
|
|
|
|
|
27
|
LEVEL: for my $i (0..5) |
301
|
|
|
|
|
|
|
{ |
302
|
20
|
|
|
|
|
159
|
my $t_dir = 'File::Spec'->catdir($dir, (('File::Spec'->updir) x $i), 't'); |
303
|
20
|
|
|
|
|
82
|
my $xt_dir = 'File::Spec'->catdir($dir, (('File::Spec'->updir) x $i), 'xt'); |
304
|
|
|
|
|
|
|
|
305
|
20
|
100
|
66
|
|
|
385
|
-d $t_dir or -d $xt_dir or next LEVEL; |
306
|
|
|
|
|
|
|
|
307
|
10
|
|
|
|
|
42
|
my $tlib_dir = 'File::Spec'->catdir($t_dir, 'lib'); |
308
|
|
|
|
|
|
|
|
309
|
10
|
50
|
|
|
|
96
|
if (-d $tlib_dir) |
310
|
|
|
|
|
|
|
{ |
311
|
10
|
|
|
|
|
4800
|
require lib; |
312
|
10
|
|
|
|
|
5115
|
'lib'->import(Cwd::abs_path $tlib_dir); |
313
|
10
|
|
|
|
|
688
|
$found++; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
10
|
50
|
|
|
|
37
|
last LEVEL if $found; |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
|
319
|
10
|
50
|
66
|
|
|
60
|
if ($opts->{lib} and not $found) |
320
|
|
|
|
|
|
|
{ |
321
|
0
|
|
|
|
|
0
|
BAIL_OUT("Expected to find directory t/lib!"); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
# Additional exports |
326
|
|
|
|
|
|
|
# |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub does_ok ($$;$) # just a copy of Test::More::isa_ok |
329
|
|
|
|
|
|
|
{ |
330
|
2
|
|
|
2
|
1
|
3
|
my( $thing, $class, $thing_name ) = @_; |
331
|
2
|
|
|
|
|
38
|
my $tb = Test::More->builder; |
332
|
|
|
|
|
|
|
|
333
|
2
|
|
|
|
|
10
|
my $whatami; |
334
|
2
|
50
|
|
|
|
8
|
if( !defined $thing ) { |
|
|
50
|
|
|
|
|
|
335
|
0
|
|
|
|
|
0
|
$whatami = 'undef'; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
elsif( ref $thing ) { |
338
|
2
|
|
|
|
|
3
|
$whatami = 'reference'; |
339
|
|
|
|
|
|
|
|
340
|
2
|
|
|
|
|
8
|
local($@,$!); |
341
|
2
|
|
|
|
|
9
|
require Scalar::Util; |
342
|
2
|
50
|
|
|
|
8
|
if( Scalar::Util::blessed($thing) ) { |
343
|
2
|
|
|
|
|
3
|
$whatami = 'object'; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
else { |
347
|
0
|
|
|
|
|
0
|
$whatami = 'class'; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
2
|
|
|
|
|
3
|
my ($rslt, $error); |
351
|
2
|
|
|
2
|
|
12
|
try { $rslt = $thing->DOES($class) } catch { $error = $_ }; |
|
2
|
|
|
|
|
63
|
|
|
0
|
|
|
|
|
0
|
|
352
|
|
|
|
|
|
|
|
353
|
2
|
50
|
|
|
|
24
|
if ($error) { |
354
|
0
|
0
|
|
|
|
0
|
die <<WHOA unless $error =~ /^Can't (locate|call) method "DOES"/; |
355
|
|
|
|
|
|
|
WHOA! I tried to call ->DOES on your $whatami and got some weird error. |
356
|
|
|
|
|
|
|
Here's the error. |
357
|
|
|
|
|
|
|
$error |
358
|
|
|
|
|
|
|
WHOA |
359
|
|
|
|
|
|
|
} |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# Special case for isa_ok( [], "ARRAY" ) and like |
362
|
2
|
50
|
|
|
|
6
|
if( $whatami eq 'reference' ) { |
363
|
0
|
|
|
|
|
0
|
$rslt = UNIVERSAL::DOES($thing, $class); |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
|
366
|
2
|
|
|
|
|
3
|
my($diag, $name); |
367
|
2
|
50
|
|
|
|
4
|
if( defined $thing_name ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
368
|
2
|
|
|
|
|
4
|
$name = "'$thing_name' does '$class'"; |
369
|
2
|
50
|
|
|
|
10
|
$diag = defined $thing ? "'$thing_name' doesn't '$class'" : "'$thing_name' isn't defined"; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
elsif( $whatami eq 'object' ) { |
372
|
0
|
|
|
|
|
0
|
my $my_class = ref $thing; |
373
|
0
|
|
|
|
|
0
|
$thing_name = qq[An object of class '$my_class']; |
374
|
0
|
|
|
|
|
0
|
$name = "$thing_name does '$class'"; |
375
|
0
|
|
|
|
|
0
|
$diag = "The object of class '$my_class' doesn't '$class'"; |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
elsif( $whatami eq 'reference' ) { |
378
|
0
|
|
|
|
|
0
|
my $type = ref $thing; |
379
|
0
|
|
|
|
|
0
|
$thing_name = qq[A reference of type '$type']; |
380
|
0
|
|
|
|
|
0
|
$name = "$thing_name does '$class'"; |
381
|
0
|
|
|
|
|
0
|
$diag = "The reference of type '$type' doesn't '$class'"; |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
elsif( $whatami eq 'undef' ) { |
384
|
0
|
|
|
|
|
0
|
$thing_name = 'undef'; |
385
|
0
|
|
|
|
|
0
|
$name = "$thing_name does '$class'"; |
386
|
0
|
|
|
|
|
0
|
$diag = "$thing_name isn't defined"; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
elsif( $whatami eq 'class' ) { |
389
|
0
|
|
|
|
|
0
|
$thing_name = qq[The class (or class-like) '$thing']; |
390
|
0
|
|
|
|
|
0
|
$name = "$thing_name does '$class'"; |
391
|
0
|
|
|
|
|
0
|
$diag = "$thing_name doesn't '$class'"; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
else { |
394
|
0
|
|
|
|
|
0
|
die; |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
2
|
|
|
|
|
2
|
my $ok; |
398
|
2
|
50
|
|
|
|
3
|
if($rslt) { |
399
|
2
|
|
|
|
|
5
|
$ok = $tb->ok( 1, $name ); |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
else { |
402
|
0
|
|
|
|
|
0
|
$ok = $tb->ok( 0, $name ); |
403
|
0
|
|
|
|
|
0
|
$tb->diag(" $diag\n"); |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
2
|
|
|
|
|
412
|
return $ok; |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
sub object_ok |
410
|
|
|
|
|
|
|
{ |
411
|
1
|
|
|
1
|
1
|
19
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
412
|
|
|
|
|
|
|
|
413
|
1
|
|
|
|
|
2
|
my $object = shift; |
414
|
1
|
50
|
|
|
|
5
|
my $name = (@_%2) ? shift : '$object'; |
415
|
1
|
|
|
|
|
16
|
my %tests = @_; |
416
|
1
|
|
|
|
|
2
|
my $bail = !!0; |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
my $result = &subtest("$name ok", sub |
419
|
|
|
|
|
|
|
{ |
420
|
1
|
50
|
|
1
|
|
537
|
if (ref($object) eq q(CODE)) |
421
|
|
|
|
|
|
|
{ |
422
|
|
|
|
|
|
|
try { |
423
|
1
|
|
|
|
|
46
|
my $tmp = $object->(); |
424
|
1
|
50
|
|
|
|
6
|
die 'coderef did not return an object' |
425
|
|
|
|
|
|
|
unless ref($tmp); |
426
|
1
|
|
|
|
|
2
|
$object = $tmp; |
427
|
1
|
|
|
|
|
5
|
pass("instantiate $name"); |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
catch { |
430
|
0
|
|
|
|
|
0
|
fail("instantiate $name"); |
431
|
0
|
|
|
|
|
0
|
diag("instantiating $name threw an exception: $_"); |
432
|
|
|
|
|
|
|
} |
433
|
1
|
|
|
|
|
14
|
} |
434
|
|
|
|
|
|
|
|
435
|
1
|
50
|
|
|
|
264
|
ok(Scalar::Util::blessed($object), "$name is blessed") |
436
|
|
|
|
|
|
|
or return; |
437
|
|
|
|
|
|
|
|
438
|
1
|
50
|
|
|
|
210
|
if (exists($tests{isa})) |
439
|
|
|
|
|
|
|
{ |
440
|
1
|
50
|
|
|
|
6
|
my @classes = ref($tests{isa}) eq q(ARRAY) ? @{$tests{isa}} : $tests{isa}; |
|
0
|
|
|
|
|
0
|
|
441
|
1
|
|
|
|
|
5
|
isa_ok($object, $_, $name) for @classes; |
442
|
1
|
|
|
|
|
258
|
delete $tests{isa}; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
|
445
|
1
|
50
|
|
|
|
4
|
if (exists($tests{does})) |
446
|
|
|
|
|
|
|
{ |
447
|
1
|
50
|
|
|
|
7
|
my @roles = ref($tests{does}) eq q(ARRAY) ? @{$tests{does}} : $tests{does}; |
|
1
|
|
|
|
|
4
|
|
448
|
1
|
|
|
|
|
5
|
does_ok($object, $_, $name) for @roles; |
449
|
1
|
|
|
|
|
4
|
delete $tests{does}; |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
|
452
|
1
|
50
|
|
|
|
22
|
if (exists($tests{can})) |
453
|
|
|
|
|
|
|
{ |
454
|
1
|
50
|
|
|
|
7
|
my @methods = ref($tests{can}) eq q(ARRAY) ? @{$tests{can}} : $tests{can}; |
|
1
|
|
|
|
|
5
|
|
455
|
1
|
|
|
|
|
6
|
can_ok($object, @methods); |
456
|
1
|
|
|
|
|
315
|
delete $tests{can}; |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
|
459
|
1
|
50
|
|
|
|
7
|
if (exists($tests{api})) |
460
|
|
|
|
|
|
|
{ |
461
|
1
|
50
|
|
|
|
5
|
my @methods = ref($tests{api}) eq q(ARRAY) ? @{$tests{api}} : $tests{api}; |
|
1
|
|
|
|
|
5
|
|
462
|
1
|
|
|
|
|
6
|
class_api_ok(ref($object), @methods); |
463
|
1
|
|
|
|
|
317
|
delete $tests{api}; |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
|
466
|
1
|
50
|
|
|
|
4
|
if (delete($tests{clean})) |
467
|
|
|
|
|
|
|
{ |
468
|
1
|
|
|
|
|
4
|
namespaces_clean(ref($object)); |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
|
471
|
1
|
50
|
|
|
|
3
|
if (exists($tests{more})) |
472
|
|
|
|
|
|
|
{ |
473
|
1
|
|
|
|
|
3
|
my $more = delete $tests{more}; |
474
|
|
|
|
|
|
|
&subtest("more tests for $name", sub |
475
|
|
|
|
|
|
|
{ |
476
|
1
|
|
|
|
|
362
|
my $exception = exception { $object->$more }; |
|
1
|
|
|
|
|
44
|
|
477
|
1
|
|
|
|
|
688
|
is($exception, undef, "no exception thrown by additional tests"); |
478
|
1
|
|
|
|
|
217
|
done_testing; |
479
|
1
|
|
|
|
|
14
|
}); |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
1
|
|
|
|
|
459
|
$bail = !!keys %tests; |
483
|
|
|
|
|
|
|
|
484
|
1
|
|
|
|
|
3
|
done_testing; |
485
|
1
|
|
|
|
|
13
|
}); |
486
|
|
|
|
|
|
|
|
487
|
1
|
50
|
|
|
|
405
|
if ($bail) |
488
|
|
|
|
|
|
|
{ |
489
|
0
|
|
|
|
|
0
|
my $huh = join q[, ], sort keys %tests; |
490
|
0
|
|
|
|
|
0
|
BAIL_OUT("object_ok cannot understand: $huh"); |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
# return $object |
494
|
1
|
50
|
|
|
|
5
|
$result ? $object : (); |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
{ |
498
|
|
|
|
|
|
|
my $wrap = sub { |
499
|
|
|
|
|
|
|
my @alts = @_; |
500
|
|
|
|
|
|
|
my $chosen; |
501
|
|
|
|
|
|
|
return sub { |
502
|
0
|
0
|
|
0
|
|
0
|
unless ($chosen) |
503
|
|
|
|
|
|
|
{ |
504
|
0
|
|
|
|
|
0
|
ALT: for (@alts) |
505
|
|
|
|
|
|
|
{ |
506
|
0
|
0
|
0
|
|
|
0
|
ref($_) and ($chosen = $_) and last ALT; |
507
|
0
|
|
|
|
|
0
|
my ($module, $sub) = /^(.+)::(\w+)$/; |
508
|
|
|
|
|
|
|
try { |
509
|
16
|
|
|
16
|
|
93
|
no strict qw(refs); |
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
525
|
|
510
|
16
|
|
|
16
|
|
66
|
no warnings qw(exiting); |
|
16
|
|
|
|
|
20
|
|
|
16
|
|
|
|
|
7654
|
|
511
|
0
|
|
|
0
|
|
0
|
require_module($module); |
512
|
0
|
0
|
0
|
|
|
0
|
exists(&$_) |
513
|
|
|
|
|
|
|
? (($chosen = \&$_) and last ALT) |
514
|
|
|
|
|
|
|
: die("no such sub $_"); |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
catch { |
517
|
0
|
|
|
0
|
|
0
|
diag("could not load $module: $_"); |
518
|
0
|
|
|
|
|
0
|
}; |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
$chosen |
522
|
0
|
0
|
|
|
|
0
|
? goto($chosen) |
523
|
|
|
|
|
|
|
: fail("$alts[0] not available - failing test!") |
524
|
|
|
|
|
|
|
}; |
525
|
|
|
|
|
|
|
}; |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
*is_string = $wrap->( |
528
|
|
|
|
|
|
|
'Test::LongString::is_string', |
529
|
|
|
|
|
|
|
'Test::More::is', |
530
|
|
|
|
|
|
|
); |
531
|
|
|
|
|
|
|
*is_string_nows = $wrap->( |
532
|
|
|
|
|
|
|
'Test::LongString::is_string_nows', |
533
|
|
|
|
|
|
|
sub { |
534
|
|
|
|
|
|
|
my $got = shift; |
535
|
|
|
|
|
|
|
my $expected = shift; |
536
|
|
|
|
|
|
|
s/\s+//g for $got, $expected; |
537
|
|
|
|
|
|
|
unshift @_, $got, $expected; |
538
|
|
|
|
|
|
|
goto \&Test::More::is; |
539
|
|
|
|
|
|
|
}, |
540
|
|
|
|
|
|
|
); |
541
|
|
|
|
|
|
|
*like_string = $wrap->( |
542
|
|
|
|
|
|
|
'Test::LongString::like_string', |
543
|
|
|
|
|
|
|
'Test::More::like', |
544
|
|
|
|
|
|
|
); |
545
|
|
|
|
|
|
|
*unlike_string = $wrap->( |
546
|
|
|
|
|
|
|
'Test::LongString::unlike_string', |
547
|
|
|
|
|
|
|
'Test::More::unlike', |
548
|
|
|
|
|
|
|
); |
549
|
|
|
|
|
|
|
*contains_string = $wrap->( |
550
|
|
|
|
|
|
|
'Test::LongString::contains_string', |
551
|
|
|
|
|
|
|
sub { |
552
|
|
|
|
|
|
|
my $got = shift; |
553
|
|
|
|
|
|
|
my $expected = shift; |
554
|
|
|
|
|
|
|
unshift @_, $got, qr/\Q$expected\E/; |
555
|
|
|
|
|
|
|
goto \&Test::More::like; |
556
|
|
|
|
|
|
|
}, |
557
|
|
|
|
|
|
|
); |
558
|
|
|
|
|
|
|
*lacks_string = $wrap->( |
559
|
|
|
|
|
|
|
'Test::LongString::lacks_string', |
560
|
|
|
|
|
|
|
sub { |
561
|
|
|
|
|
|
|
my $got = shift; |
562
|
|
|
|
|
|
|
my $expected = shift; |
563
|
|
|
|
|
|
|
unshift @_, $got, qr/\Q$expected\E/; |
564
|
|
|
|
|
|
|
goto \&Test::More::unlike; |
565
|
|
|
|
|
|
|
}, |
566
|
|
|
|
|
|
|
); |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
sub _generate_TD |
570
|
|
|
|
|
|
|
{ |
571
|
8
|
|
|
8
|
|
9354
|
my $_td = bless(do { my $x = 1; \$x }, 'Test::Modern::_TD'); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
22
|
|
572
|
8
|
|
|
0
|
|
103
|
return sub () { $_td }; |
|
0
|
|
|
|
|
0
|
|
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
sub Test::Modern::_TD::AUTOLOAD |
576
|
|
|
|
|
|
|
{ |
577
|
2
|
|
|
2
|
|
9122
|
shift; |
578
|
2
|
|
|
|
|
17
|
my ($method) = ($Test::Modern::_TD::AUTOLOAD =~ /(\w+)\z/); |
579
|
2
|
50
|
|
|
|
7
|
return if $method eq 'DESTROY'; |
580
|
2
|
50
|
|
|
|
18
|
my $coderef = 'Test::Deep'->can($method) |
581
|
|
|
|
|
|
|
or die("Test::Deep::$method not found"); |
582
|
2
|
|
|
|
|
8
|
$coderef->(@_); |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
# Stolen from Test::CleanNamespaces; eliminated Package::Stash and |
586
|
|
|
|
|
|
|
# Sub::Name dependencies; massively cleaned up; don't use Test::Builder |
587
|
|
|
|
|
|
|
# directly; instead just call Test::More's exported functions. |
588
|
|
|
|
|
|
|
# |
589
|
|
|
|
|
|
|
{ |
590
|
|
|
|
|
|
|
my $_dirt = sub |
591
|
|
|
|
|
|
|
{ |
592
|
|
|
|
|
|
|
my $ns = shift; |
593
|
|
|
|
|
|
|
require_module($ns); |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
my %symbols = do { |
596
|
16
|
|
|
16
|
|
75
|
no strict qw(refs); |
|
16
|
|
|
|
|
19
|
|
|
16
|
|
|
|
|
2972
|
|
597
|
|
|
|
|
|
|
map { /([^:]+)$/; $1 => $_; } |
598
|
|
|
|
|
|
|
grep { eval { *$_{CODE} } } |
599
|
|
|
|
|
|
|
values %{"$ns\::"}; |
600
|
|
|
|
|
|
|
}; |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
my @imports; |
603
|
|
|
|
|
|
|
my $meta; |
604
|
|
|
|
|
|
|
if ($INC{ module_notional_filename('Moose::Util') } |
605
|
|
|
|
|
|
|
and $meta = Moose::Util::find_meta($ns)) |
606
|
|
|
|
|
|
|
{ |
607
|
|
|
|
|
|
|
my %subs = %symbols; |
608
|
|
|
|
|
|
|
delete @subs{ $meta->get_method_list }; |
609
|
|
|
|
|
|
|
@imports = keys %subs; |
610
|
|
|
|
|
|
|
} |
611
|
|
|
|
|
|
|
elsif ($INC{ module_notional_filename('Mouse::Util') } |
612
|
|
|
|
|
|
|
and $meta = Mouse::Util::class_of($ns)) |
613
|
|
|
|
|
|
|
{ |
614
|
|
|
|
|
|
|
my %subs = %symbols; |
615
|
|
|
|
|
|
|
delete @subs{ $meta->get_method_list }; |
616
|
|
|
|
|
|
|
@imports = keys %subs; |
617
|
|
|
|
|
|
|
} |
618
|
|
|
|
|
|
|
else |
619
|
|
|
|
|
|
|
{ |
620
|
|
|
|
|
|
|
require B; |
621
|
16
|
|
|
16
|
|
64
|
no strict qw(refs); |
|
16
|
|
|
|
|
27
|
|
|
16
|
|
|
|
|
10871
|
|
622
|
|
|
|
|
|
|
@imports = grep { |
623
|
|
|
|
|
|
|
my $stash = B::svref_2object(\&{"$ns\::$_"})->GV->STASH->NAME; |
624
|
|
|
|
|
|
|
$stash ne $ns |
625
|
|
|
|
|
|
|
and $stash ne 'Role::Tiny' |
626
|
|
|
|
|
|
|
and not eval { require Role::Tiny; Role::Tiny->is_role($stash) } |
627
|
|
|
|
|
|
|
} keys %symbols; |
628
|
|
|
|
|
|
|
} |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
my %imports; @imports{@imports} = map substr("$symbols{$_}", 1), @imports; |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
# But really it's better to inherit these rather than import them. :-) |
633
|
|
|
|
|
|
|
if (keys %imports) { |
634
|
|
|
|
|
|
|
delete @imports{qw(import unimport)}; |
635
|
|
|
|
|
|
|
} |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
if (keys %imports) { |
638
|
|
|
|
|
|
|
my @overloads = grep { |
639
|
|
|
|
|
|
|
/^\(/ or $imports{$_} eq 'overload::nil' |
640
|
|
|
|
|
|
|
} keys %imports; |
641
|
|
|
|
|
|
|
delete @imports{@overloads} if @overloads; |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
if (keys %imports and $] < 5.010) { |
645
|
|
|
|
|
|
|
my @constants = grep { $imports{$_} eq 'constant::__ANON__' } keys %imports; |
646
|
|
|
|
|
|
|
delete @imports{@constants} if @constants; |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
@imports = sort keys(%imports); |
650
|
|
|
|
|
|
|
my %sources; |
651
|
|
|
|
|
|
|
@sources{@imports} = map { |
652
|
|
|
|
|
|
|
B::svref_2object(\&{"$ns\::$_"})->GV->STASH->NAME; |
653
|
|
|
|
|
|
|
} @imports; |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
my %does; |
656
|
|
|
|
|
|
|
for my $func (keys %sources) { |
657
|
|
|
|
|
|
|
my $role = $sources{$func}; |
658
|
|
|
|
|
|
|
$does{$role} = !!eval { $ns->DOES($role) } |
659
|
|
|
|
|
|
|
unless exists $does{$role}; |
660
|
|
|
|
|
|
|
delete $imports{$func} |
661
|
|
|
|
|
|
|
if $does{$role}; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
sort keys(%imports); |
665
|
|
|
|
|
|
|
}; |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
my $_diag_dirt = sub |
668
|
|
|
|
|
|
|
{ |
669
|
|
|
|
|
|
|
require B; |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
my $ns = shift; |
672
|
|
|
|
|
|
|
my @imports = @_; |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
my %imports; |
675
|
|
|
|
|
|
|
@imports{@imports} = map { |
676
|
|
|
|
|
|
|
B::svref_2object(\&{"$ns\::$_"})->GV->STASH->NAME . "::$_"; |
677
|
|
|
|
|
|
|
} @imports; |
678
|
|
|
|
|
|
|
diag explain('remaining imports: ' => \%imports); |
679
|
|
|
|
|
|
|
}; |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
my $_test_or_skip = sub |
682
|
|
|
|
|
|
|
{ |
683
|
|
|
|
|
|
|
my $ns = shift; |
684
|
|
|
|
|
|
|
my $rv; |
685
|
|
|
|
|
|
|
try { |
686
|
|
|
|
|
|
|
my @imports = $ns->$_dirt; |
687
|
|
|
|
|
|
|
$rv = ok(!@imports, "${ns} contains no imported functions") |
688
|
|
|
|
|
|
|
or $ns->$_diag_dirt(@imports); |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
catch { |
691
|
|
|
|
|
|
|
SKIP: { |
692
|
|
|
|
|
|
|
skip "failed to load $ns: $_", 1; |
693
|
|
|
|
|
|
|
fail("failed to load module"); |
694
|
|
|
|
|
|
|
}; |
695
|
|
|
|
|
|
|
}; |
696
|
|
|
|
|
|
|
return $rv; |
697
|
|
|
|
|
|
|
}; |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
sub namespaces_clean |
700
|
|
|
|
|
|
|
{ |
701
|
2
|
|
|
2
|
1
|
24
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
# special case a single namespace |
704
|
2
|
100
|
|
|
|
10
|
return shift->$_test_or_skip if @_ == 1; |
705
|
|
|
|
|
|
|
|
706
|
1
|
|
|
|
|
3
|
my @namespaces = @_; |
707
|
|
|
|
|
|
|
return &subtest( |
708
|
|
|
|
|
|
|
sprintf("namespaces_clean: %s", join q(, ), @namespaces), |
709
|
|
|
|
|
|
|
sub { |
710
|
1
|
|
|
1
|
|
531
|
$_->$_test_or_skip for @namespaces; |
711
|
1
|
|
|
|
|
4
|
done_testing; |
712
|
|
|
|
|
|
|
}, |
713
|
1
|
|
|
|
|
15
|
); |
714
|
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
} |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
# Release tests... |
718
|
|
|
|
|
|
|
{ |
719
|
|
|
|
|
|
|
sub _should_extended_test () |
720
|
|
|
|
|
|
|
{ |
721
|
7
|
50
|
33
|
7
|
|
60
|
$ENV{RELEASE_TESTING} || $ENV{AUTHOR_TESTING} || $ENV{EXTENDED_TESTING}; |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
sub _wrap |
725
|
|
|
|
|
|
|
{ |
726
|
16
|
|
|
16
|
|
80
|
no strict qw(refs); |
|
16
|
|
|
|
|
17
|
|
|
16
|
|
|
|
|
16031
|
|
727
|
112
|
|
|
112
|
|
185
|
my ($module, $function, %opt) = @_; |
728
|
|
|
|
|
|
|
|
729
|
112
|
|
|
|
|
81
|
my $code; |
730
|
112
|
100
|
|
|
|
221
|
($function, $code) = each(%$function) |
731
|
|
|
|
|
|
|
if ref($function) eq q(HASH); |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
*$function = sub |
734
|
|
|
|
|
|
|
{ |
735
|
7
|
50
|
33
|
7
|
|
59
|
if ($opt{extended} and not _should_extended_test) |
736
|
|
|
|
|
|
|
{ |
737
|
7
|
|
|
|
|
24
|
SKIP: { |
738
|
7
|
|
|
|
|
8
|
skip 'Not running extended tests', 1; |
739
|
0
|
|
|
|
|
0
|
pass("skipped"); |
740
|
|
|
|
|
|
|
} |
741
|
7
|
|
|
|
|
1000
|
return 1; |
742
|
|
|
|
|
|
|
} |
743
|
|
|
|
|
|
|
|
744
|
0
|
0
|
|
|
|
0
|
if (eval "require $module") |
745
|
|
|
|
|
|
|
{ |
746
|
0
|
|
0
|
|
|
0
|
$code ||= \&{"$module\::$function"}; |
|
0
|
|
|
|
|
0
|
|
747
|
0
|
0
|
|
|
|
0
|
if ($opt{multi}) |
748
|
|
|
|
|
|
|
{ |
749
|
0
|
|
|
|
|
0
|
my @args = @_; |
750
|
|
|
|
|
|
|
@_ = ($function, sub { |
751
|
0
|
|
|
0
|
|
0
|
@_ = @args; |
752
|
0
|
|
|
|
|
0
|
goto $code; |
753
|
0
|
|
|
|
|
0
|
}); |
754
|
0
|
|
|
|
|
0
|
goto \&Test::More::subtest; |
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
else |
757
|
|
|
|
|
|
|
{ |
758
|
0
|
|
|
|
|
0
|
goto $code; |
759
|
|
|
|
|
|
|
} |
760
|
|
|
|
|
|
|
} |
761
|
|
|
|
|
|
|
|
762
|
0
|
|
|
|
|
0
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
763
|
0
|
0
|
|
|
|
0
|
SKIP: { |
764
|
0
|
|
|
|
|
0
|
skip "$module only required for release testing", 1 |
765
|
|
|
|
|
|
|
unless $ENV{RELEASE_TESTING}; |
766
|
0
|
|
|
|
|
0
|
fail("$function"); |
767
|
0
|
|
|
|
|
0
|
diag("$module not installed"); |
768
|
|
|
|
|
|
|
} |
769
|
0
|
|
|
|
|
0
|
return; |
770
|
112
|
|
|
|
|
554
|
}; |
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
my $_VAS = sub |
774
|
|
|
|
|
|
|
{ |
775
|
|
|
|
|
|
|
my ($dir, $name) = @_; |
776
|
|
|
|
|
|
|
$dir |
777
|
|
|
|
|
|
|
= defined $dir ? $dir |
778
|
|
|
|
|
|
|
: -d 'blib' ? 'blib' |
779
|
|
|
|
|
|
|
: 'lib'; |
780
|
|
|
|
|
|
|
return fail("$dir does not exist, or is not a directory") |
781
|
|
|
|
|
|
|
unless -d $dir; |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
my @files = File::Find::Rule->perl_module->in($dir); |
784
|
|
|
|
|
|
|
$name ||= "all modules in $dir have the same version number"; |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
&subtest($name => sub |
789
|
|
|
|
|
|
|
{ |
790
|
|
|
|
|
|
|
my %versions; |
791
|
|
|
|
|
|
|
for my $file (@files) |
792
|
|
|
|
|
|
|
{ |
793
|
|
|
|
|
|
|
Test::Version::version_ok($file) or next; |
794
|
|
|
|
|
|
|
my $info = Module::Metadata->new_from_file($file); |
795
|
|
|
|
|
|
|
my $ver = $info->version; |
796
|
|
|
|
|
|
|
$ver = '(undef)' unless defined $ver; |
797
|
|
|
|
|
|
|
push @{$versions{$ver}}, $file; |
798
|
|
|
|
|
|
|
} |
799
|
|
|
|
|
|
|
my $ok = keys(%versions) < 2; |
800
|
|
|
|
|
|
|
ok($ok, "single version number found"); |
801
|
|
|
|
|
|
|
if (!$ok) |
802
|
|
|
|
|
|
|
{ |
803
|
|
|
|
|
|
|
diag("Files with version $_: @{$versions{$_}}") |
804
|
|
|
|
|
|
|
for sort keys(%versions); |
805
|
|
|
|
|
|
|
} |
806
|
|
|
|
|
|
|
done_testing; |
807
|
|
|
|
|
|
|
}); |
808
|
|
|
|
|
|
|
}; |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
_wrap("Test::Pod", "pod_file_ok", extended => 1); |
811
|
|
|
|
|
|
|
_wrap("Test::Pod", "all_pod_files_ok", extended => 1, multi => 1); |
812
|
|
|
|
|
|
|
_wrap("Test::Pod::Coverage", "pod_coverage_ok", extended => 1); |
813
|
|
|
|
|
|
|
_wrap("Test::Pod::Coverage", "all_pod_coverage_ok", extended => 1, multi => 1); |
814
|
|
|
|
|
|
|
_wrap("Test::Version", "version_ok", extended => 1); |
815
|
|
|
|
|
|
|
_wrap("Test::Version", "version_all_ok", extended => 1, multi => 1); |
816
|
|
|
|
|
|
|
_wrap("Test::Version", { "version_all_same" => $_VAS }, extended => 1); |
817
|
|
|
|
|
|
|
} |
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
sub shouldnt_warn (&) |
820
|
|
|
|
|
|
|
{ |
821
|
1
|
|
|
1
|
1
|
11
|
my @warnings = do { |
822
|
1
|
|
|
|
|
4
|
local $Test::Builder::Level = $Test::Builder::Level + 3; |
823
|
1
|
|
|
|
|
6
|
&Test::Warnings::warnings(@_); |
824
|
|
|
|
|
|
|
}; |
825
|
|
|
|
|
|
|
|
826
|
1
|
|
|
|
|
1300
|
my $old = $TODO; |
827
|
1
|
|
|
|
|
2
|
$TODO = "shouldn't warn block"; |
828
|
1
|
|
|
|
|
2
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
829
|
1
|
|
|
|
|
4
|
ok(scalar(@warnings)==0, "no (unexpected) warnings"); |
830
|
1
|
|
|
|
|
284
|
diag("Saw warning: $_") for @warnings; |
831
|
1
|
|
|
|
|
84
|
$TODO = $old; |
832
|
|
|
|
|
|
|
} |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
{ |
835
|
|
|
|
|
|
|
# When passed a string of code, Benchmark::timethis() evaluates |
836
|
|
|
|
|
|
|
# it in the caller package; need to fake that. |
837
|
|
|
|
|
|
|
my $_do = sub { |
838
|
|
|
|
|
|
|
my $caller = shift; |
839
|
|
|
|
|
|
|
my $sub = shift; |
840
|
|
|
|
|
|
|
my $doer = eval qq[ package $caller; sub { ${sub}(\@_) } ]; |
841
|
|
|
|
|
|
|
$doer->(@_); |
842
|
|
|
|
|
|
|
}; |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
my $get_res = sub { |
845
|
|
|
|
|
|
|
require Benchmark; |
846
|
|
|
|
|
|
|
require Scalar::Util; |
847
|
|
|
|
|
|
|
my ($caller, $times, $sub) = @_; |
848
|
|
|
|
|
|
|
Scalar::Util::blessed($sub) && $sub->isa("Benchmark") |
849
|
|
|
|
|
|
|
? $sub |
850
|
|
|
|
|
|
|
: $caller->$_do('Benchmark::timethis', $times, $sub, "", "none"); |
851
|
|
|
|
|
|
|
}; |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
sub is_fastest |
854
|
|
|
|
|
|
|
{ |
855
|
0
|
|
|
0
|
1
|
0
|
require Benchmark; |
856
|
|
|
|
|
|
|
|
857
|
0
|
|
|
|
|
0
|
my $caller = caller; |
858
|
0
|
|
|
|
|
0
|
my ($which, $times, $marks, $desc) = @_; |
859
|
0
|
0
|
|
|
|
0
|
$desc = "$which is fastest" unless defined $desc; |
860
|
|
|
|
|
|
|
|
861
|
0
|
|
|
|
|
0
|
my @marks; |
862
|
0
|
|
|
|
|
0
|
while (my ($name, $sub) = each %$marks) |
863
|
|
|
|
|
|
|
{ |
864
|
0
|
|
|
|
|
0
|
my $res = $get_res->($caller, $times, $sub); |
865
|
0
|
|
|
|
|
0
|
my ($r, $pu, $ps, $cu, $cs, $n) = @$res; |
866
|
|
|
|
|
|
|
|
867
|
0
|
|
|
|
|
0
|
push(@marks, { |
868
|
|
|
|
|
|
|
name => $name, |
869
|
|
|
|
|
|
|
res => $res, |
870
|
|
|
|
|
|
|
n => $n, |
871
|
|
|
|
|
|
|
s => ($pu+$ps), |
872
|
|
|
|
|
|
|
}); |
873
|
|
|
|
|
|
|
} |
874
|
|
|
|
|
|
|
|
875
|
0
|
|
|
|
|
0
|
@marks = sort {$b->{n} * $a->{s} <=> $a->{n} * $b->{s}} @marks; |
|
0
|
|
|
|
|
0
|
|
876
|
|
|
|
|
|
|
|
877
|
0
|
|
|
|
|
0
|
my $ok = $marks[0]->{name} eq $which; |
878
|
|
|
|
|
|
|
|
879
|
0
|
|
|
|
|
0
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
880
|
|
|
|
|
|
|
|
881
|
0
|
|
|
|
|
0
|
ok($ok, $desc); |
882
|
0
|
0
|
|
|
|
0
|
diag("$which was not the fastest") unless $ok; |
883
|
|
|
|
|
|
|
|
884
|
0
|
0
|
0
|
|
|
0
|
if ($VERBOSE or not $ok) |
885
|
|
|
|
|
|
|
{ |
886
|
0
|
|
|
|
|
0
|
foreach my $mark (@marks) |
887
|
|
|
|
|
|
|
{ |
888
|
0
|
|
|
|
|
0
|
diag("$mark->{name} - " . Benchmark::timestr($mark->{res})); |
889
|
|
|
|
|
|
|
} |
890
|
|
|
|
|
|
|
} |
891
|
|
|
|
|
|
|
|
892
|
0
|
|
|
|
|
0
|
$ok; |
893
|
|
|
|
|
|
|
} |
894
|
|
|
|
|
|
|
} |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
1; |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
## no Test::Tabs |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
__END__ |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
=pod |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
=encoding utf-8 |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
=for stopwords todo |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
=head1 NAME |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
Test::Modern - precision testing for modern perl |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
=head1 SYNOPSIS |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
use Test::Modern; |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
# Your tests here |
917
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
done_testing; |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
=head1 DESCRIPTION |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
Test::Modern provides the best features of L<Test::More>, L<Test::Fatal>, |
923
|
|
|
|
|
|
|
L<Test::Warnings>, L<Test::API>, L<Test::LongString>, and L<Test::Deep>, |
924
|
|
|
|
|
|
|
as well as ideas from L<Test::Requires>, L<Test::DescribeMe>, |
925
|
|
|
|
|
|
|
L<Test::Moose>, and L<Test::CleanNamespaces>. |
926
|
|
|
|
|
|
|
|
927
|
|
|
|
|
|
|
Test::Modern also automatically imposes L<strict> and L<warnings> on your |
928
|
|
|
|
|
|
|
script, and loads L<IO::File>. (Much of the same stuff L<Modern::Perl> does.) |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
Although Test::Modern is a modern testing framework, it should run fine |
931
|
|
|
|
|
|
|
on pre-modern versions of Perl. It should be easy to install on Perl |
932
|
|
|
|
|
|
|
5.8.9 and above; and if you can persuade its dependencies to install |
933
|
|
|
|
|
|
|
(not necessarily easy!), should be OK on anything back to Perl 5.6.1. |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
=head2 Features from Test::More |
936
|
|
|
|
|
|
|
|
937
|
|
|
|
|
|
|
Test::Modern exports the following subs from L<Test::More>: |
938
|
|
|
|
|
|
|
|
939
|
|
|
|
|
|
|
=over |
940
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
=item C<< ok($truth, $description) >> |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
=item C<< is($got, $expected, $description) >> |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
=item C<< isnt($got, $unexpected, $description) >> |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
=item C<< like($got, $regexp, $description) >> |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
=item C<< unlike($got, $regexp, $description) >> |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
=item C<< is_deeply($got, $expected, $description) >> |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
=item C<< cmp_ok($got, $operator, $expected, $description) >> |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
=item C<< new_ok($class, \@args, $name) >> |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
=item C<< isa_ok($object|$subclass, $class, $name) >> |
958
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
=item C<< can_ok($object|$class, @methods) >> |
960
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
=item C<< pass($description) >> |
962
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
=item C<< fail($description) >> |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
=item C<< subtest($description, sub { ... }) >> |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
=item C<< diag(@messages) >> |
968
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
=item C<< note(@messages) >> |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
=item C<< explain(@messages) >> |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
=item C<< skip($why, $count) if $reason >> |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
=item C<< todo_skip($why, $count) if $reason >> |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
=item C<< $TODO >> |
978
|
|
|
|
|
|
|
|
979
|
|
|
|
|
|
|
=item C<< plan(%plan) >> |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
=item C<< done_testing >> |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
=item C<< BAIL_OUT($reason) >> |
984
|
|
|
|
|
|
|
|
985
|
|
|
|
|
|
|
=back |
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
The C<use_ok>, C<require_ok>, C<eq_array>, C<eq_hash>, and C<eq_set> functions |
988
|
|
|
|
|
|
|
are also available, but not exported by default. For C<use_ok> and |
989
|
|
|
|
|
|
|
C<require_ok> it's normally better to use the Perl built-ins C<use> and |
990
|
|
|
|
|
|
|
C<require> which will die (failing your test) if things are not OK. For |
991
|
|
|
|
|
|
|
the C<< eq_* >> functions, they can usually be replaced by C<is_deeply>. |
992
|
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
=head2 Features from Test::Fatal |
994
|
|
|
|
|
|
|
|
995
|
|
|
|
|
|
|
Test::Modern exports the following subs from L<Test::Fatal>: |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
=over |
998
|
|
|
|
|
|
|
|
999
|
|
|
|
|
|
|
=item C<< exception { BLOCK } >> |
1000
|
|
|
|
|
|
|
|
1001
|
|
|
|
|
|
|
=back |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
=head2 Features from Test::Warnings |
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
Test::Modern exports the following subs from L<Test::Warnings>: |
1006
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
=over |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
=item C<< warning { BLOCK } >> |
1010
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
=item C<< warnings { BLOCK } >> |
1012
|
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
|
=back |
1014
|
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
|
In addition, Test::Modern always enables the C<had_no_warnings> test at |
1016
|
|
|
|
|
|
|
the end of the file, ensuring that your test script generated no warnings |
1017
|
|
|
|
|
|
|
other than the expected ones which were caught by C<warnings> blocks. |
1018
|
|
|
|
|
|
|
(See also C<PERL_TEST_MODERN_ALLOW_WARNINGS> in L</"ENVIRONMENT">.) |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
Test::Modern can also export an additional function for testing warnings, |
1021
|
|
|
|
|
|
|
but does not export it by default: |
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
=over |
1024
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
=item C<< shouldnt_warn { BLOCK } >> |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
Runs a block of code that will hopefully not warn, but might. Tests that |
1028
|
|
|
|
|
|
|
it doesn't warn, but performs that test as a "todo" test, so if it fails, |
1029
|
|
|
|
|
|
|
your test suite can still pass. |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
=back |
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
=head2 Features from Test::API |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
Test::Modern exports the following subs from L<Test::API>: |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
=over |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
=item C<< public_ok($package, @functions) >> |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
=item C<< import_ok($package, export => \@functions, export_ok => \@functions) >> |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
=item C<< class_api_ok($class, @methods) >> |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
=back |
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
=head2 Features from Test::LongString |
1048
|
|
|
|
|
|
|
|
1049
|
|
|
|
|
|
|
Test::Modern exports the following subs from L<Test::LongString>: |
1050
|
|
|
|
|
|
|
|
1051
|
|
|
|
|
|
|
=over |
1052
|
|
|
|
|
|
|
|
1053
|
|
|
|
|
|
|
=item C<< is_string($got, $expected, $description) >> |
1054
|
|
|
|
|
|
|
|
1055
|
|
|
|
|
|
|
=item C<< is_string_nows($got, $expected, $description) >> |
1056
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
=item C<< like_string($got, $regexp, $description) >> |
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
=item C<< unlike_string($got, $regexp, $description) >> |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
=item C<< contains_string($haystack, $needle, $description) >> |
1062
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
=item C<< lacks_string($haystack, $needle, $description) >> |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
=back |
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
Actually Test::Modern provides these via a wrapper. If Test::LongString |
1068
|
|
|
|
|
|
|
is not installed then Test::Modern will provide a fallback |
1069
|
|
|
|
|
|
|
implementation using Test::More's C<is>, C<isnt>, C<like>, and |
1070
|
|
|
|
|
|
|
C<unlike> functions. (The diagnostics won't be as good in the case of |
1071
|
|
|
|
|
|
|
failures.) |
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
=head2 Features from Test::Deep |
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
Test::Modern exports the following subs from L<Test::Deep>: |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
=over |
1078
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
=item C<< cmp_deeply($got, $expected, $description) >> |
1080
|
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
|
=back |
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
The following are not exported by default, but can be exported upon request: |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
=over |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
=item C<< ignore() >> |
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
=item C<< methods(%hash) >> |
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
=item C<< listmethods(%hash) >> |
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
=item C<< shallow($thing) >> |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
=item C<< noclass($thing) >> |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
=item C<< useclass($thing) >> |
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
=item C<< re($regexp, $capture_data, $flags) >> |
1100
|
|
|
|
|
|
|
|
1101
|
|
|
|
|
|
|
=item C<< superhashof(\%hash) >> |
1102
|
|
|
|
|
|
|
|
1103
|
|
|
|
|
|
|
=item C<< subhashof(\%hash) >> |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
=item C<< bag(@elements) >> |
1106
|
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
|
=item C<< set(@elements) >> |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
=item C<< superbagof(@elements) >> |
1110
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
=item C<< subbagof(@elements) >> |
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
=item C<< supersetof(@elements) >> |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
=item C<< subsetof(@elements) >> |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
=item C<< all(@expecteds) >> |
1118
|
|
|
|
|
|
|
|
1119
|
|
|
|
|
|
|
=item C<< any(@expecteds) >> |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
=item C<< obj_isa($class) >> |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
=item C<< array_each($thing) >> |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
=item C<< str($string) >> |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
=item C<< num($number, $tolerance) >> |
1128
|
|
|
|
|
|
|
|
1129
|
|
|
|
|
|
|
=item C<< bool($value) >> |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
=item C<< code(\&subref) >> |
1132
|
|
|
|
|
|
|
|
1133
|
|
|
|
|
|
|
=back |
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
As an alternative to using those functions, Test::Modern exports a constant |
1136
|
|
|
|
|
|
|
C<TD> upon which you can call them as methods: |
1137
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
# like Test::Deep::bag(@elements) |
1139
|
|
|
|
|
|
|
TD->bag(@elements) |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
=head2 Features from Test::Pod and Test::Pod::Coverage |
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
B<< These features are currently considered experimental. They |
1144
|
|
|
|
|
|
|
may be removed from a future version of Test::Modern. >> |
1145
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
Test::Modern can export the following subs from L<Test::Pod> and |
1147
|
|
|
|
|
|
|
L<Test::Pod::Coverage>, though they are not exported by default: |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
=over |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
=item C<< pod_file_ok($file, $description) >> |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
=item C<< all_pod_files_ok(@dirs) >> |
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
=item C<< pod_coverage_ok($module, $params, $description) >> |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
=item C<< all_pod_coverage_ok($params, $description) >> |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
=back |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
In fact, Test::Modern wraps these tests in checks to see whether |
1162
|
|
|
|
|
|
|
Test::Pod(::Coverage) is installed, and the state of the |
1163
|
|
|
|
|
|
|
C<RELEASE_TESTING>, C<AUTHOR_TESTING>, and C<EXTENDED_TESTING> |
1164
|
|
|
|
|
|
|
environment variables. If none of those environment variables is set to |
1165
|
|
|
|
|
|
|
true, then the test is skipped altogether. If Test::Pod(::Coverage) is |
1166
|
|
|
|
|
|
|
not installed, then the test is skipped, unless C<RELEASE_TESTING> is |
1167
|
|
|
|
|
|
|
true, in which case I<< Test::Pod(::Coverage) must be installed >>. |
1168
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
This is usually a pretty sensible behaviour. You want authors to |
1170
|
|
|
|
|
|
|
be made aware of pod errors if possible. You want to make sure |
1171
|
|
|
|
|
|
|
they are tested before doing a release. End users probably don't |
1172
|
|
|
|
|
|
|
want a pod formatting error to prevent them from installing the |
1173
|
|
|
|
|
|
|
software, unless they opt into it using C<EXTENDED_TESTING>. |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
Also, Test::Modern wraps the C<< all_* >> functions to run them |
1176
|
|
|
|
|
|
|
in a subtest (because otherwise they can interfere with your test |
1177
|
|
|
|
|
|
|
plans). |
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
=head2 Features from Test::Version |
1180
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
B<< These features are currently considered experimental. They |
1182
|
|
|
|
|
|
|
may be removed from a future version of Test::Modern. >> |
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
Test::Modern can export the following subs from L<Test::Version>, |
1185
|
|
|
|
|
|
|
though they are not exported by default: |
1186
|
|
|
|
|
|
|
|
1187
|
|
|
|
|
|
|
=over |
1188
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
=item C<< version_ok($file, $description) >> |
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
=item C<< version_all_ok(@dirs) >> |
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
=back |
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
These are wrapped similarly to those described in the |
1196
|
|
|
|
|
|
|
L</"Features from Test::Pod and Test::Coverage">. |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
Test::Modern can also export another sub based on C<version_all_ok>: |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
=over |
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
=item C<< version_all_same(@dirs) >> |
1203
|
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
Acts like C<version_all_ok> but also checks that all modules have |
1205
|
|
|
|
|
|
|
the same version number. |
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
=back |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
=head2 Features inspired by Test::Moose |
1210
|
|
|
|
|
|
|
|
1211
|
|
|
|
|
|
|
Test::Modern does not use L<Test::Moose>, but does provide the |
1212
|
|
|
|
|
|
|
following function inspired by it: |
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
=over |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
=item C<< does_ok($object|$subclass, $class, $name) >> |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
Like C<isa_ok>, but calls C<< $obj->DOES >> instead of C<< $obj->isa >>. |
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
=back |
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
=head2 Features inspired by Test::CleanNamespaces |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
Test::Modern does not use L<Test::CleanNamespaces>, but does provide |
1225
|
|
|
|
|
|
|
the following function inspired by it: |
1226
|
|
|
|
|
|
|
|
1227
|
|
|
|
|
|
|
=over |
1228
|
|
|
|
|
|
|
|
1229
|
|
|
|
|
|
|
=item C<< namespaces_clean(@namespaces) >> |
1230
|
|
|
|
|
|
|
|
1231
|
|
|
|
|
|
|
Tests that namespaces don't contain any imported functions. (i.e. you |
1232
|
|
|
|
|
|
|
haven't forgotten to use L<namespace::autoclean> or L<namespace::sweep> |
1233
|
|
|
|
|
|
|
in a class). |
1234
|
|
|
|
|
|
|
|
1235
|
|
|
|
|
|
|
Unlike the version of this function supplied with L<Test::CleanNamespaces>, |
1236
|
|
|
|
|
|
|
if C<< @namespaces >> contains more than one namespace, these will be run |
1237
|
|
|
|
|
|
|
in a subtest, so the whole thing will only count as one test. |
1238
|
|
|
|
|
|
|
|
1239
|
|
|
|
|
|
|
=back |
1240
|
|
|
|
|
|
|
|
1241
|
|
|
|
|
|
|
=head2 Features inspired by Test::Benchmark |
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
Test::Modern does not use L<Test::Benchmark>, but does provide the |
1244
|
|
|
|
|
|
|
following feature inspired by it: |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
=over |
1247
|
|
|
|
|
|
|
|
1248
|
|
|
|
|
|
|
=item C<< is_fastest($implementation, $times, \%implementations, $desc) >> |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
use Test::Modern qw( is_fastest ); |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
is_fastest("speedy", -1, { |
1253
|
|
|
|
|
|
|
"speedy" => sub { ... }, |
1254
|
|
|
|
|
|
|
"slowcoach" => sub { ... }, |
1255
|
|
|
|
|
|
|
}); |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
This ensures that the named coderef runs the fastest out of a hashref |
1258
|
|
|
|
|
|
|
of alternatives. The C<< -1 >> parameter in the example is the number |
1259
|
|
|
|
|
|
|
of times to run the coderefs (see L<Benchmark> for more details, |
1260
|
|
|
|
|
|
|
including how numbers less than zero are interpreted). |
1261
|
|
|
|
|
|
|
|
1262
|
|
|
|
|
|
|
=back |
1263
|
|
|
|
|
|
|
|
1264
|
|
|
|
|
|
|
B<< Caveat: >> on fast computers, a set of coderefs that you might |
1265
|
|
|
|
|
|
|
expect to differ in speed might all run in a negligible period of |
1266
|
|
|
|
|
|
|
time, and thus be rounded to zero, in which case your test case could |
1267
|
|
|
|
|
|
|
randomly fail. Use this test with caution! |
1268
|
|
|
|
|
|
|
|
1269
|
|
|
|
|
|
|
B<< Caveat the second: >> these tests tend to be slow. Use sparingly. |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
Because of the aforementioned caveats, it is a good idea to move your |
1272
|
|
|
|
|
|
|
benchmarking tests into separate test scripts, keeping an imaginary wall |
1273
|
|
|
|
|
|
|
between them and the bulk of your test suite (which tests correctness |
1274
|
|
|
|
|
|
|
rather than speed). |
1275
|
|
|
|
|
|
|
|
1276
|
|
|
|
|
|
|
Test::Modern provides an import hint suitable for including at the top |
1277
|
|
|
|
|
|
|
of these benchmarking tests to mark them as being primarily concerned |
1278
|
|
|
|
|
|
|
with speed: |
1279
|
|
|
|
|
|
|
|
1280
|
|
|
|
|
|
|
use Test::Modern -benchmark; |
1281
|
|
|
|
|
|
|
|
1282
|
|
|
|
|
|
|
This will not only import the C<is_fastest> function, but will also |
1283
|
|
|
|
|
|
|
I<< skip the entire script >> unless one of the C<EXTENDED_TESTING> or |
1284
|
|
|
|
|
|
|
C<RELEASE_TESTING> environment variables is set. |
1285
|
|
|
|
|
|
|
|
1286
|
|
|
|
|
|
|
=head2 Features inspired by Test::Requires |
1287
|
|
|
|
|
|
|
|
1288
|
|
|
|
|
|
|
Test::Modern does not use L<Test::Requires>, but does provide the |
1289
|
|
|
|
|
|
|
following feature inspired by it: |
1290
|
|
|
|
|
|
|
|
1291
|
|
|
|
|
|
|
=over |
1292
|
|
|
|
|
|
|
|
1293
|
|
|
|
|
|
|
=item C<< use Test::Modern -requires => \%requirements >> |
1294
|
|
|
|
|
|
|
|
1295
|
|
|
|
|
|
|
This will skip the entire test script if the requirements are not met. |
1296
|
|
|
|
|
|
|
For example: |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
use Test::Modern -requires => { |
1299
|
|
|
|
|
|
|
'perl' => '5.010', |
1300
|
|
|
|
|
|
|
'Moose' => '2.11', |
1301
|
|
|
|
|
|
|
'namespace::autoclean' => undef, |
1302
|
|
|
|
|
|
|
}; |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
=back |
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
=head2 Features inspired by Test::RequiresInternet |
1307
|
|
|
|
|
|
|
|
1308
|
|
|
|
|
|
|
Similarly you can skip the test script if an Internet connection is not |
1309
|
|
|
|
|
|
|
available: |
1310
|
|
|
|
|
|
|
|
1311
|
|
|
|
|
|
|
use Test::Modern -internet; |
1312
|
|
|
|
|
|
|
|
1313
|
|
|
|
|
|
|
You can check for the ability to connect to particular hosts and ports: |
1314
|
|
|
|
|
|
|
|
1315
|
|
|
|
|
|
|
use Test::Modern -internet => [ |
1316
|
|
|
|
|
|
|
'www.example.com' => 'http', |
1317
|
|
|
|
|
|
|
'8.8.8.8' => 53, |
1318
|
|
|
|
|
|
|
]; |
1319
|
|
|
|
|
|
|
|
1320
|
|
|
|
|
|
|
Test::Modern does not use L<Test::RequiresInternet> but I've stolen much |
1321
|
|
|
|
|
|
|
of the latter's implementation. |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
=head2 Features inspired by Test::Without::Module |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
Test::Modern does not use L<Test::Without::Module>, but does provide |
1326
|
|
|
|
|
|
|
the following feature inspired by it: |
1327
|
|
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
=over |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
=item C<< use Test::Modern -without => \@modules >> |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
This will run the tests as if the module was not installed. Useful |
1333
|
|
|
|
|
|
|
for testing things in the absence of optional dependencies. For |
1334
|
|
|
|
|
|
|
example: |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
use Test::Modern -without => [ "Class::XSAccessor" ]; |
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
It cannot suppress modules from being loaded if they are required by |
1339
|
|
|
|
|
|
|
Test::Modern itself. To get a list of what modules Test::Modern |
1340
|
|
|
|
|
|
|
requires, run the following command: |
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
perl -MTest::Modern -le'print for sort keys %INC' |
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
(Note that the actual implementation is mostly stolen from |
1345
|
|
|
|
|
|
|
L<Devel::Hide> which seems to behave better than |
1346
|
|
|
|
|
|
|
L<Test::Without::Module>.) |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
=back |
1349
|
|
|
|
|
|
|
|
1350
|
|
|
|
|
|
|
=head2 Features inspired by Test::DescribeMe |
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
These export tags allow you to classify tests as "author tests", |
1353
|
|
|
|
|
|
|
"release tests", "extended tests", or "interactive tests". |
1354
|
|
|
|
|
|
|
|
1355
|
|
|
|
|
|
|
They will cause your test script to be skipped depending on |
1356
|
|
|
|
|
|
|
various environment variables. |
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
=over |
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
=item C<< use Test::Modern -author >> |
1361
|
|
|
|
|
|
|
|
1362
|
|
|
|
|
|
|
=item C<< use Test::Modern -release >> |
1363
|
|
|
|
|
|
|
|
1364
|
|
|
|
|
|
|
=item C<< use Test::Modern -extended >> |
1365
|
|
|
|
|
|
|
|
1366
|
|
|
|
|
|
|
=item C<< use Test::Modern -interactive >> |
1367
|
|
|
|
|
|
|
|
1368
|
|
|
|
|
|
|
=back |
1369
|
|
|
|
|
|
|
|
1370
|
|
|
|
|
|
|
=head2 Features inspired by Test::Lib |
1371
|
|
|
|
|
|
|
|
1372
|
|
|
|
|
|
|
B<< These features are currently considered experimental. They |
1373
|
|
|
|
|
|
|
may be removed from a future version of Test::Modern. >> |
1374
|
|
|
|
|
|
|
|
1375
|
|
|
|
|
|
|
Test::Modern tries to find a directory called C<< t/lib >> by |
1376
|
|
|
|
|
|
|
traversing up the directory tree from the caller file. If found, |
1377
|
|
|
|
|
|
|
this directory will be added to C<< @INC >>. |
1378
|
|
|
|
|
|
|
|
1379
|
|
|
|
|
|
|
L<Test::Lib> would croak if such a directory cannot be found. |
1380
|
|
|
|
|
|
|
L<Test::Modern> carries on if it can't find it. If you want something |
1381
|
|
|
|
|
|
|
more like the Test::Lib behaviour, use the C<< -lib >> import tag: |
1382
|
|
|
|
|
|
|
|
1383
|
|
|
|
|
|
|
use Test::Modern -lib; |
1384
|
|
|
|
|
|
|
|
1385
|
|
|
|
|
|
|
=head2 Brand Spanking New Features |
1386
|
|
|
|
|
|
|
|
1387
|
|
|
|
|
|
|
Test::Modern provides a shortcut which combines several features it has |
1388
|
|
|
|
|
|
|
pilfered from other testing modules: |
1389
|
|
|
|
|
|
|
|
1390
|
|
|
|
|
|
|
=over |
1391
|
|
|
|
|
|
|
|
1392
|
|
|
|
|
|
|
=item C<< object_ok($object, $name, %tests) >> |
1393
|
|
|
|
|
|
|
|
1394
|
|
|
|
|
|
|
Runs a gamut of subtests on an object: |
1395
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
object_ok( |
1397
|
|
|
|
|
|
|
$object, |
1398
|
|
|
|
|
|
|
$name, |
1399
|
|
|
|
|
|
|
isa => \@classes, |
1400
|
|
|
|
|
|
|
does => \@roles, |
1401
|
|
|
|
|
|
|
can => \@methods, |
1402
|
|
|
|
|
|
|
api => \@methods, |
1403
|
|
|
|
|
|
|
clean => $boolean, |
1404
|
|
|
|
|
|
|
more => sub { |
1405
|
|
|
|
|
|
|
my $object = shift; |
1406
|
|
|
|
|
|
|
...; |
1407
|
|
|
|
|
|
|
} |
1408
|
|
|
|
|
|
|
); |
1409
|
|
|
|
|
|
|
|
1410
|
|
|
|
|
|
|
C<< $object >> may be a blessed object, or an unblessed coderef which |
1411
|
|
|
|
|
|
|
returns a blessed object. The C<< isa >> test runs C<< isa_ok >>; the |
1412
|
|
|
|
|
|
|
C<< does >> test runs C<< does_ok >>, the C<< can >> test runs |
1413
|
|
|
|
|
|
|
C<< can_ok >>, and the C<< api >> test runs C<< class_api_ok >>. |
1414
|
|
|
|
|
|
|
C<< clean >> allows you to run C<< namespaces_clean >> on the object's |
1415
|
|
|
|
|
|
|
class. |
1416
|
|
|
|
|
|
|
|
1417
|
|
|
|
|
|
|
C<< more >> introduces a coderef for running more tests. Within this |
1418
|
|
|
|
|
|
|
sub you can use any of the standard Test::More, Test::LongString, etc |
1419
|
|
|
|
|
|
|
tests. It is automatically run in a C<< try >> block (see L<Try::Tiny>); |
1420
|
|
|
|
|
|
|
throwing an exception will cause the test to fail, but not cause the |
1421
|
|
|
|
|
|
|
script to end. |
1422
|
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
Any of the test hash keys may be omitted, in which case that test will |
1424
|
|
|
|
|
|
|
not be run. C<< $name >> may be omitted. |
1425
|
|
|
|
|
|
|
|
1426
|
|
|
|
|
|
|
If the test succeeds, it returns the object (which may be useful for |
1427
|
|
|
|
|
|
|
further tests). Otherwise, returns C<undef>. |
1428
|
|
|
|
|
|
|
|
1429
|
|
|
|
|
|
|
Practical example: |
1430
|
|
|
|
|
|
|
|
1431
|
|
|
|
|
|
|
my $bob = object_ok( |
1432
|
|
|
|
|
|
|
sub { Employee->new(name => 'Robert Jones') }, |
1433
|
|
|
|
|
|
|
'$bob', |
1434
|
|
|
|
|
|
|
isa => [qw( Employee Person Moo::Object )], |
1435
|
|
|
|
|
|
|
does => [qw( Employable )], |
1436
|
|
|
|
|
|
|
can => [qw( name employee_number tax_code )], |
1437
|
|
|
|
|
|
|
clean => 1, |
1438
|
|
|
|
|
|
|
more => sub { |
1439
|
|
|
|
|
|
|
my $object = shift; |
1440
|
|
|
|
|
|
|
is($object->name, "Robert Jones"); |
1441
|
|
|
|
|
|
|
like($object->employee_number, qr/^[0-9]+$/); |
1442
|
|
|
|
|
|
|
}, |
1443
|
|
|
|
|
|
|
); |
1444
|
|
|
|
|
|
|
|
1445
|
|
|
|
|
|
|
# make further use of $bob |
1446
|
|
|
|
|
|
|
object_ok( |
1447
|
|
|
|
|
|
|
sub { $bob->line_manager }, |
1448
|
|
|
|
|
|
|
isa => [qw( Person )], |
1449
|
|
|
|
|
|
|
); |
1450
|
|
|
|
|
|
|
|
1451
|
|
|
|
|
|
|
=back |
1452
|
|
|
|
|
|
|
|
1453
|
|
|
|
|
|
|
=head1 EXPORT |
1454
|
|
|
|
|
|
|
|
1455
|
|
|
|
|
|
|
This module uses L<Exporter::Tiny> to perform its exports. This allows |
1456
|
|
|
|
|
|
|
exported subs to be renamed, etc. |
1457
|
|
|
|
|
|
|
|
1458
|
|
|
|
|
|
|
The following export tags are supported: |
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
=over |
1461
|
|
|
|
|
|
|
|
1462
|
|
|
|
|
|
|
=item C<< -more >> |
1463
|
|
|
|
|
|
|
|
1464
|
|
|
|
|
|
|
Exports the L</"Features from Test::More">, except deprecated ones. |
1465
|
|
|
|
|
|
|
|
1466
|
|
|
|
|
|
|
=item C<< -deprecated >> |
1467
|
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
|
Exports the deprecated Test::More features. |
1469
|
|
|
|
|
|
|
|
1470
|
|
|
|
|
|
|
=item C<< -fatal >> |
1471
|
|
|
|
|
|
|
|
1472
|
|
|
|
|
|
|
Exports the L</"Features from Test::Fatal">. |
1473
|
|
|
|
|
|
|
|
1474
|
|
|
|
|
|
|
=item C<< -warnings >> |
1475
|
|
|
|
|
|
|
|
1476
|
|
|
|
|
|
|
Exports the L</"Features from Test::Warnings">. |
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
=item C<< -api >> |
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
Exports the L</"Features from Test::API">, including C<class_api_ok>. |
1481
|
|
|
|
|
|
|
|
1482
|
|
|
|
|
|
|
=item C<< -strings >> |
1483
|
|
|
|
|
|
|
|
1484
|
|
|
|
|
|
|
Exports the L</"Features from Test::LongString">. |
1485
|
|
|
|
|
|
|
|
1486
|
|
|
|
|
|
|
=item C<< -deep >> |
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
Exports L<cmp_deeply and TD|/"Features from Test::Deep">. |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
=item C<< -deeper >> |
1491
|
|
|
|
|
|
|
|
1492
|
|
|
|
|
|
|
Exports I<all> the L</"Features from Test::Deep">. |
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
=item C<< -moose >> |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
Exports the L</"Features inspired by Test::Moose">. |
1497
|
|
|
|
|
|
|
|
1498
|
|
|
|
|
|
|
=item C<< -clean >> |
1499
|
|
|
|
|
|
|
|
1500
|
|
|
|
|
|
|
Exports the L</"Features inspired by Test::CleanNamespaces">. |
1501
|
|
|
|
|
|
|
|
1502
|
|
|
|
|
|
|
=item C<< -pod >> |
1503
|
|
|
|
|
|
|
|
1504
|
|
|
|
|
|
|
Exports the L</"Features from Test::Pod and Test::Pod::Coverage">. |
1505
|
|
|
|
|
|
|
|
1506
|
|
|
|
|
|
|
=item C<< -versions >> |
1507
|
|
|
|
|
|
|
|
1508
|
|
|
|
|
|
|
Exports the L</"Features from Test::Version">. |
1509
|
|
|
|
|
|
|
|
1510
|
|
|
|
|
|
|
=item C<< -default >> |
1511
|
|
|
|
|
|
|
|
1512
|
|
|
|
|
|
|
Exports the default features -- all of the above except C<< -deprecated >>, |
1513
|
|
|
|
|
|
|
C<< -pod >>, C<< -versions >>, and C<< -deeper >>. Also exports C<object_ok>. |
1514
|
|
|
|
|
|
|
|
1515
|
|
|
|
|
|
|
=item C<< -all >> |
1516
|
|
|
|
|
|
|
|
1517
|
|
|
|
|
|
|
Exports all of the above features I<including> C<< -deprecated >>, |
1518
|
|
|
|
|
|
|
C<< -pod >>, C<< -versions >>, C<< -deeper >>, C<object_ok>, and |
1519
|
|
|
|
|
|
|
C<shouldnt_warn>. |
1520
|
|
|
|
|
|
|
|
1521
|
|
|
|
|
|
|
=item C<< -author >>, C<< -extended >>, C<< -interactive >>, and C<< -release >> |
1522
|
|
|
|
|
|
|
|
1523
|
|
|
|
|
|
|
Classify the test script. |
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
=item C<< -benchmark >> |
1526
|
|
|
|
|
|
|
|
1527
|
|
|
|
|
|
|
The test script consists mostly of benchmarking. |
1528
|
|
|
|
|
|
|
|
1529
|
|
|
|
|
|
|
=item C<< -internet >> |
1530
|
|
|
|
|
|
|
|
1531
|
|
|
|
|
|
|
The test script requires Internet access. |
1532
|
|
|
|
|
|
|
|
1533
|
|
|
|
|
|
|
=item C<< -requires >>, C<< -without >> |
1534
|
|
|
|
|
|
|
|
1535
|
|
|
|
|
|
|
Specify modules required or hidden for these test cases. |
1536
|
|
|
|
|
|
|
|
1537
|
|
|
|
|
|
|
=item C<< -lib >> |
1538
|
|
|
|
|
|
|
|
1539
|
|
|
|
|
|
|
Makes the absence of a C<< t/lib >> directory fatal. |
1540
|
|
|
|
|
|
|
|
1541
|
|
|
|
|
|
|
See L</"Features inspired by Test::Lib">. |
1542
|
|
|
|
|
|
|
|
1543
|
|
|
|
|
|
|
=item C<< -verbose >> |
1544
|
|
|
|
|
|
|
|
1545
|
|
|
|
|
|
|
Makes test output more verbose. (Currently only C<is_faster> takes notice |
1546
|
|
|
|
|
|
|
of this.) |
1547
|
|
|
|
|
|
|
|
1548
|
|
|
|
|
|
|
=back |
1549
|
|
|
|
|
|
|
|
1550
|
|
|
|
|
|
|
C<< $TODO >> is currently I<always> exported. |
1551
|
|
|
|
|
|
|
|
1552
|
|
|
|
|
|
|
=head1 ENVIRONMENT |
1553
|
|
|
|
|
|
|
|
1554
|
|
|
|
|
|
|
Test::Modern is affected by the following environment variables: |
1555
|
|
|
|
|
|
|
|
1556
|
|
|
|
|
|
|
=over |
1557
|
|
|
|
|
|
|
|
1558
|
|
|
|
|
|
|
=item C<AUTHOR_TESTING>, C<AUTOMATED_TESTING>, C<EXTENDED_TESTING>, C<RELEASE_TESTING> |
1559
|
|
|
|
|
|
|
|
1560
|
|
|
|
|
|
|
These variables affect the behaviour of Test::Modern's pod-checking and |
1561
|
|
|
|
|
|
|
version-checking. See L</"Features from Test::Pod and Test::Coverage"> |
1562
|
|
|
|
|
|
|
and L</"Features from Test::Version">. |
1563
|
|
|
|
|
|
|
|
1564
|
|
|
|
|
|
|
They also can trigger certain import tags to skip a test script. See |
1565
|
|
|
|
|
|
|
L</"Features inspired by Test::DescribeMe">, and |
1566
|
|
|
|
|
|
|
L</"Features inspired by Test::Benchmark"> |
1567
|
|
|
|
|
|
|
|
1568
|
|
|
|
|
|
|
=item C<NO_NETWORK_TESTS> |
1569
|
|
|
|
|
|
|
|
1570
|
|
|
|
|
|
|
Automatically skips any tests which indicate that they require Internet |
1571
|
|
|
|
|
|
|
access, without even checking to see if the Internet is accessible. |
1572
|
|
|
|
|
|
|
See L</"Features inspired by Test::RequiresInternet">. |
1573
|
|
|
|
|
|
|
|
1574
|
|
|
|
|
|
|
=item C<PERL_TEST_MODERN_ALLOW_WARNINGS> |
1575
|
|
|
|
|
|
|
|
1576
|
|
|
|
|
|
|
Setting this to true allows you to disable L<Test::Warnings>' end test. |
1577
|
|
|
|
|
|
|
|
1578
|
|
|
|
|
|
|
Normally the end test will cause a test script to fail if any unexpected |
1579
|
|
|
|
|
|
|
warnings are encountered during its execution. New versions of Perl, and |
1580
|
|
|
|
|
|
|
upgrades of dependencies can cause a previously good test suite to start |
1581
|
|
|
|
|
|
|
emitting warnings. This environment variable can be used as a "quick fix" |
1582
|
|
|
|
|
|
|
to get the test suite passing again. |
1583
|
|
|
|
|
|
|
|
1584
|
|
|
|
|
|
|
=back |
1585
|
|
|
|
|
|
|
|
1586
|
|
|
|
|
|
|
=head1 BUGS |
1587
|
|
|
|
|
|
|
|
1588
|
|
|
|
|
|
|
Please report any bugs to |
1589
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=Test-Modern>. |
1590
|
|
|
|
|
|
|
|
1591
|
|
|
|
|
|
|
=head1 SEE ALSO |
1592
|
|
|
|
|
|
|
|
1593
|
|
|
|
|
|
|
L<My Favourite Test::* Modules|http://blogs.perl.org/users/toby_inkster/2014/02/my-favourite-test-modules.html>, |
1594
|
|
|
|
|
|
|
L<Precision Testing for Modern Perl|http://blogs.perl.org/users/toby_inkster/2014/03/precision-testing-for-modern-perl.html>. |
1595
|
|
|
|
|
|
|
|
1596
|
|
|
|
|
|
|
L<Test::More>, |
1597
|
|
|
|
|
|
|
L<Test::Fatal>, |
1598
|
|
|
|
|
|
|
L<Test::Warnings>, |
1599
|
|
|
|
|
|
|
L<Test::API>, |
1600
|
|
|
|
|
|
|
L<Test::LongString>, |
1601
|
|
|
|
|
|
|
L<Test::Deep>, |
1602
|
|
|
|
|
|
|
L<Test::Moose>, |
1603
|
|
|
|
|
|
|
L<Test::CleanNamespaces>, |
1604
|
|
|
|
|
|
|
L<Test::Requires>, |
1605
|
|
|
|
|
|
|
L<Test::Without::Module>, |
1606
|
|
|
|
|
|
|
L<Test::RequiresInternet>, |
1607
|
|
|
|
|
|
|
L<Test::DescribeMe>, |
1608
|
|
|
|
|
|
|
L<Test::Lib>, |
1609
|
|
|
|
|
|
|
L<Test::Pod>, |
1610
|
|
|
|
|
|
|
L<Test::Pod::Coverage>, |
1611
|
|
|
|
|
|
|
L<Test::Version>. |
1612
|
|
|
|
|
|
|
|
1613
|
|
|
|
|
|
|
L<Test::Most> is a similar idea, but provides a slightly different |
1614
|
|
|
|
|
|
|
combination of features. |
1615
|
|
|
|
|
|
|
|
1616
|
|
|
|
|
|
|
=head1 AUTHOR |
1617
|
|
|
|
|
|
|
|
1618
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
1619
|
|
|
|
|
|
|
|
1620
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
1621
|
|
|
|
|
|
|
|
1622
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Toby Inkster. |
1623
|
|
|
|
|
|
|
|
1624
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
1625
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
1626
|
|
|
|
|
|
|
|
1627
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
1628
|
|
|
|
|
|
|
|
1629
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
1630
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
1631
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
1632
|
|
|
|
|
|
|
|