line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package My::Module::Test; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
7374
|
use strict; |
|
4
|
|
|
|
|
31
|
|
|
4
|
|
|
|
|
114
|
|
4
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
132
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2531
|
use Astro::SIMBAD::Client; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
203
|
|
7
|
4
|
|
|
4
|
|
2649
|
use Test::More 0.96; # Because of subtest() |
|
4
|
|
|
|
|
271318
|
|
|
4
|
|
|
|
|
33
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
1053
|
use Exporter (); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
194
|
|
10
|
|
|
|
|
|
|
our @ISA = qw{ Exporter }; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @CARP_NOT = ( qw{ Astro::SIMBAD::Client } ); |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
20
|
use constant ARRAY_REF => ref []; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
389
|
|
15
|
4
|
|
|
4
|
|
26
|
use constant HASH_REF => ref {}; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
339
|
|
16
|
4
|
|
|
4
|
|
26
|
use constant REGEXP_REF => ref qr{}; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
9243
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
19
|
|
|
|
|
|
|
access |
20
|
|
|
|
|
|
|
call |
21
|
|
|
|
|
|
|
call_a |
22
|
|
|
|
|
|
|
canned |
23
|
|
|
|
|
|
|
clear |
24
|
|
|
|
|
|
|
count |
25
|
|
|
|
|
|
|
deref |
26
|
|
|
|
|
|
|
deref_curr |
27
|
|
|
|
|
|
|
diag |
28
|
|
|
|
|
|
|
dumper |
29
|
|
|
|
|
|
|
echo |
30
|
|
|
|
|
|
|
end |
31
|
|
|
|
|
|
|
find |
32
|
|
|
|
|
|
|
have_scheme |
33
|
|
|
|
|
|
|
hidden |
34
|
|
|
|
|
|
|
load_data |
35
|
|
|
|
|
|
|
load_module |
36
|
|
|
|
|
|
|
load_module_or_skip_all |
37
|
|
|
|
|
|
|
module_loaded |
38
|
|
|
|
|
|
|
note |
39
|
|
|
|
|
|
|
plan |
40
|
|
|
|
|
|
|
returned_value |
41
|
|
|
|
|
|
|
silent |
42
|
|
|
|
|
|
|
subtest |
43
|
|
|
|
|
|
|
test |
44
|
|
|
|
|
|
|
test_false |
45
|
|
|
|
|
|
|
$TODO |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
our @EXPORT = @EXPORT_OK; ## no critic (ProhibitAutomaticExportation) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $canned; # Canned data to test against. |
50
|
|
|
|
|
|
|
my $got; # Result of method call. |
51
|
|
|
|
|
|
|
my %loaded; # Record of the results of attempting to load modules. |
52
|
|
|
|
|
|
|
my $obj; # The object to be tested. |
53
|
|
|
|
|
|
|
my $ref; # Reference to result of method call, if it is a reference. |
54
|
|
|
|
|
|
|
my $skip; # True to skip tests. |
55
|
|
|
|
|
|
|
my $silent; # True to silence exceptions if $skip is true. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub access { |
58
|
5
|
50
|
|
5
|
1
|
346
|
eval { |
59
|
5
|
|
|
|
|
32
|
require LWP::UserAgent; |
60
|
5
|
|
|
|
|
21
|
1; |
61
|
|
|
|
|
|
|
} or plan skip_all => 'Can not load LWP::UserAgent'; |
62
|
5
|
|
|
|
|
48
|
my $resp = LWP::UserAgent->new( |
63
|
|
|
|
|
|
|
)->get( Astro::SIMBAD::Client->__build_url( 'simbad/' ) ); |
64
|
5
|
50
|
|
|
|
898634
|
$resp->is_success |
65
|
0
|
|
|
|
|
0
|
or plan skip_all => "@{[$resp->status_line]}"; |
66
|
5
|
|
|
|
|
215
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub call { |
70
|
17
|
|
|
17
|
1
|
118
|
my ( $method, @args ) = @_; |
71
|
17
|
|
66
|
|
|
80
|
$obj ||= Astro::SIMBAD::Client->new(); |
72
|
|
|
|
|
|
|
eval { |
73
|
17
|
|
|
|
|
100
|
$got = $obj->$method( @args ); |
74
|
16
|
|
|
|
|
130
|
1; |
75
|
17
|
100
|
|
|
|
27
|
} or do { |
76
|
1
|
|
|
|
|
7
|
_method_failure( $method, @args ); |
77
|
1
|
|
|
|
|
2
|
$got = $@; |
78
|
|
|
|
|
|
|
}; |
79
|
17
|
100
|
|
|
|
67
|
$ref = ref $got ? $got : undef; |
80
|
17
|
|
|
|
|
73
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub call_a { |
84
|
1
|
|
|
1
|
1
|
2010
|
my ( $method, @args ) = @_; |
85
|
1
|
|
33
|
|
|
5
|
$obj ||= Astro::SIMBAD::Client->new(); |
86
|
|
|
|
|
|
|
eval { |
87
|
1
|
|
|
|
|
5
|
$got = [ $obj->$method( @args ) ]; |
88
|
1
|
|
|
|
|
6
|
1; |
89
|
1
|
50
|
|
|
|
2
|
} or do { |
90
|
0
|
|
|
|
|
0
|
_method_failure( $method. @args ); |
91
|
0
|
|
|
|
|
0
|
$got = $@; |
92
|
|
|
|
|
|
|
}; |
93
|
1
|
50
|
|
|
|
6
|
$ref = ref $got ? $got : undef; |
94
|
1
|
|
|
|
|
5
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub canned { |
98
|
42
|
|
|
42
|
1
|
109
|
my ( @args ) = @_; |
99
|
42
|
|
|
|
|
98
|
my $want = $canned; |
100
|
42
|
|
|
|
|
85
|
foreach my $key (@args) { |
101
|
84
|
|
|
|
|
126
|
my $ref = ref $want; |
102
|
84
|
50
|
|
|
|
169
|
if ( ARRAY_REF eq $ref ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
$want = $want->[$key]; |
104
|
|
|
|
|
|
|
} elsif ( HASH_REF eq $ref ) { |
105
|
84
|
|
|
|
|
166
|
$want = $want->{$key}; |
106
|
|
|
|
|
|
|
} elsif ($ref) { |
107
|
0
|
|
|
|
|
0
|
die "Loaded data contains unexpected $ref reference for key $key\n"; |
108
|
|
|
|
|
|
|
} else { |
109
|
0
|
|
|
|
|
0
|
die "Loaded data does not contain key @args\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
42
|
|
|
|
|
179
|
return $want; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub clear { |
116
|
6
|
|
|
6
|
1
|
30
|
$got = $ref = undef; # clear |
117
|
6
|
|
|
|
|
38
|
$skip = undef; # noskip |
118
|
6
|
|
|
|
|
10
|
$silent = undef; # Not silent. |
119
|
6
|
|
|
|
|
13
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub count { |
123
|
6
|
50
|
|
6
|
1
|
44
|
if ( ARRAY_REF eq ref $got ) { |
124
|
6
|
|
|
|
|
15
|
$got = @{ $got }; |
|
6
|
|
|
|
|
29
|
|
125
|
|
|
|
|
|
|
} else { |
126
|
0
|
|
|
|
|
0
|
$got = undef; |
127
|
|
|
|
|
|
|
}; |
128
|
6
|
|
|
|
|
14
|
return; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub deref { |
132
|
43
|
|
|
43
|
1
|
2684
|
$got = $ref; |
133
|
43
|
|
|
|
|
176
|
goto &deref_curr; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub deref_curr { |
137
|
43
|
|
|
43
|
1
|
122
|
my ( @args ) = @_; |
138
|
43
|
|
|
|
|
88
|
foreach my $key (@args) { |
139
|
85
|
|
|
|
|
140
|
my $type = ref $got; |
140
|
85
|
100
|
|
|
|
217
|
if ( ARRAY_REF eq $type ) { |
|
|
50
|
|
|
|
|
|
141
|
43
|
|
|
|
|
97
|
$got = $got->[$key]; |
142
|
|
|
|
|
|
|
} elsif ($type eq HASH_REF) { |
143
|
42
|
|
|
|
|
106
|
$got = $got->{$key}; |
144
|
|
|
|
|
|
|
} else { |
145
|
0
|
|
|
|
|
0
|
$got = undef; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
43
|
|
|
|
|
91
|
return; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub dumper { |
152
|
0
|
|
|
0
|
1
|
0
|
require Data::Dumper; |
153
|
0
|
|
|
|
|
0
|
diag Data::Dumper::Dumper( $got ); |
154
|
0
|
|
|
|
|
0
|
return; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub echo { |
158
|
7
|
|
|
7
|
1
|
56
|
my @args = @_; |
159
|
7
|
|
|
|
|
20
|
foreach ( @args ) { |
160
|
7
|
|
|
|
|
35
|
note $_; |
161
|
|
|
|
|
|
|
} |
162
|
7
|
|
|
|
|
3937
|
return; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub end { |
166
|
2
|
|
|
2
|
1
|
3757
|
done_testing; |
167
|
2
|
|
|
|
|
1318
|
return; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub find { |
171
|
0
|
|
|
0
|
1
|
0
|
my ( @args ) = @_; |
172
|
0
|
|
|
|
|
0
|
my $target = pop @args; |
173
|
0
|
0
|
|
|
|
0
|
if ( ARRAY_REF eq ref $got ) { |
174
|
0
|
|
|
|
|
0
|
foreach my $item ( @{ $got } ) { |
|
0
|
|
|
|
|
0
|
|
175
|
0
|
|
|
|
|
0
|
my $test = $item; |
176
|
0
|
|
|
|
|
0
|
foreach my $key ( @args ) { |
177
|
0
|
|
|
|
|
0
|
my $type = ref $test; |
178
|
0
|
0
|
|
|
|
0
|
if ( ARRAY_REF eq $type ) { |
|
|
0
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
$test = $test->[$key]; |
180
|
|
|
|
|
|
|
} elsif ( HASH_REF eq $type ) { |
181
|
0
|
|
|
|
|
0
|
$test = $test->{$key}; |
182
|
|
|
|
|
|
|
} else { |
183
|
0
|
|
|
|
|
0
|
$test = undef; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
(defined $test && $test eq $target) |
187
|
0
|
0
|
0
|
|
|
0
|
and do {$got = $item; last;}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
0
|
return; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub have_scheme { |
194
|
4
|
|
|
4
|
0
|
9246
|
my ( $protocol ) = @_; |
195
|
4
|
|
|
|
|
11
|
local $@ = undef; |
196
|
4
|
|
|
|
|
9
|
return eval { |
197
|
4
|
|
|
|
|
500
|
require "LWP/Protocol/$protocol.pm"; |
198
|
2
|
|
|
|
|
9
|
1; |
199
|
|
|
|
|
|
|
}; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub hidden { |
203
|
0
|
|
|
0
|
1
|
0
|
my ( $module ) = @_; |
204
|
0
|
0
|
|
|
|
0
|
my $code = Test::Without::Module->can( 'get_forbidden_list' ) |
205
|
|
|
|
|
|
|
or return 0; |
206
|
0
|
|
0
|
|
|
0
|
return exists $code->()->{$module} || 0; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub load_data { |
210
|
1
|
|
|
1
|
1
|
8
|
my ( $arg ) = @_; |
211
|
1
|
50
|
|
|
|
3
|
if ( defined $arg ) { |
212
|
1
|
|
|
|
|
6
|
local @INC = ( @INC, '.' ); |
213
|
1
|
|
|
|
|
447
|
$canned = do $arg; |
214
|
|
|
|
|
|
|
} else { |
215
|
0
|
|
|
|
|
0
|
$canned = undef; |
216
|
|
|
|
|
|
|
} |
217
|
1
|
|
|
|
|
28
|
return; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub load_module { |
221
|
3
|
|
|
3
|
1
|
19
|
my @args = @_; |
222
|
3
|
50
|
|
|
|
43
|
my $prob = @args > 1 ? |
|
|
100
|
|
|
|
|
|
223
|
|
|
|
|
|
|
("Can not load any of " . join (', ', @args)) : |
224
|
|
|
|
|
|
|
@args ? "Can not load @args" : ''; |
225
|
3
|
|
|
|
|
17
|
foreach ( @args ) { |
226
|
4
|
50
|
|
|
|
19
|
if ( exists $loaded{$_} ) { |
227
|
0
|
0
|
|
|
|
0
|
$loaded{$_} and do { |
228
|
0
|
|
|
|
|
0
|
$prob = undef; |
229
|
0
|
|
|
|
|
0
|
last; |
230
|
|
|
|
|
|
|
}; |
231
|
|
|
|
|
|
|
} else { |
232
|
4
|
|
|
|
|
15
|
$loaded{$_} = undef; |
233
|
4
|
50
|
|
|
|
630
|
eval "require $_; 1" and do { |
234
|
0
|
|
|
|
|
0
|
$prob = undef; |
235
|
0
|
|
|
|
|
0
|
$loaded{$_} = 1; |
236
|
0
|
|
|
|
|
0
|
last; |
237
|
|
|
|
|
|
|
}; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
3
|
50
|
33
|
|
|
37
|
defined $prob |
241
|
|
|
|
|
|
|
and not $skip |
242
|
|
|
|
|
|
|
and $skip = $prob; |
243
|
3
|
|
|
|
|
12
|
return; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub load_module_or_skip_all { |
247
|
2
|
|
|
2
|
0
|
26
|
my @args = @_; |
248
|
2
|
|
|
|
|
14
|
load_module( @args ); |
249
|
2
|
50
|
|
|
|
19
|
$skip |
250
|
|
|
|
|
|
|
and plan skip_all => $skip; |
251
|
0
|
|
|
|
|
0
|
return; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub module_loaded { ## no critic (RequireArgUnpacking) |
255
|
0
|
|
|
0
|
1
|
0
|
my ( @args ) = @_; |
256
|
0
|
0
|
|
|
|
0
|
$loaded{shift @args} or return; |
257
|
0
|
|
|
|
|
0
|
my $verb = shift @args; |
258
|
0
|
0
|
|
|
|
0
|
my $code = __PACKAGE__->can( $verb ) |
259
|
|
|
|
|
|
|
or die "Unknown command $verb"; |
260
|
0
|
|
|
|
|
0
|
@_ = @args; |
261
|
0
|
|
|
|
|
0
|
goto &$code; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub returned_value { |
265
|
0
|
|
|
0
|
1
|
0
|
return $got; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub silent { |
269
|
0
|
|
|
0
|
1
|
0
|
my ( $arg ) = @_; |
270
|
0
|
0
|
|
|
|
0
|
defined $arg |
271
|
|
|
|
|
|
|
or $arg = ! $silent; |
272
|
0
|
|
|
|
|
0
|
$silent = $arg; |
273
|
0
|
|
|
|
|
0
|
return; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub test { ## no critic (RequireArgUnpacking) |
277
|
50
|
|
|
50
|
1
|
129
|
$_[2] = 1; |
278
|
50
|
|
|
|
|
174
|
goto &_test; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub test_false { ## no critic (RequireArgUnpacking) |
282
|
0
|
|
|
0
|
0
|
0
|
$_[2] = 0; |
283
|
0
|
|
|
|
|
0
|
goto &_test; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub _test { ## no critic (RequireArgUnpacking) |
287
|
50
|
|
|
50
|
|
155
|
my ( $want, $title, $type ) = @_; |
288
|
50
|
50
|
|
|
|
140
|
$got = 'undef' unless defined $got; |
289
|
50
|
|
|
|
|
100
|
foreach ($want, $got) { |
290
|
100
|
100
|
|
|
|
255
|
ref $_ and next; |
291
|
99
|
|
|
|
|
392
|
chomp $_; |
292
|
99
|
50
|
33
|
|
|
924
|
m/(.+?)\s+$/ and _numberp ($1 . '') and $_ = $1; |
293
|
|
|
|
|
|
|
} |
294
|
50
|
50
|
66
|
|
|
233
|
if ( $skip ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
295
|
|
|
|
|
|
|
SKIP: { |
296
|
0
|
|
|
|
|
0
|
skip $skip, 1; |
|
0
|
|
|
|
|
0
|
|
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
} elsif ( REGEXP_REF eq ref $want ) { |
299
|
1
|
|
|
|
|
31
|
@_ = ( $got, $want, $title ); |
300
|
1
|
50
|
|
|
|
17
|
goto $type ? \&like : \&unlike; |
301
|
|
|
|
|
|
|
} elsif (_numberp ($want) && _numberp ($got)) { |
302
|
43
|
50
|
|
|
|
194
|
@_ = ( $got, ( $type ? '==' : '!=' ), $want, $title ); |
303
|
43
|
|
|
|
|
201
|
goto &cmp_ok; |
304
|
|
|
|
|
|
|
} else { |
305
|
6
|
|
|
|
|
23
|
@_ = ( $got, $want, $title ); |
306
|
6
|
50
|
|
|
|
39
|
goto $type ? \&is : \&isnt; |
307
|
|
|
|
|
|
|
} |
308
|
0
|
|
|
|
|
0
|
return; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
################################################################## |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub _method_failure { |
314
|
1
|
|
|
1
|
|
4
|
my ( $method, @args ) = @_; |
315
|
1
|
50
|
33
|
|
|
5
|
$skip |
316
|
|
|
|
|
|
|
and $silent |
317
|
|
|
|
|
|
|
and return; |
318
|
1
|
50
|
|
|
|
6
|
my $msg = $skip ? ' ($skip set)' : ''; |
319
|
1
|
|
|
|
|
3
|
@args = map { _quote() } @args; |
|
2
|
|
|
|
|
6
|
|
320
|
1
|
|
|
|
|
15
|
local $" = ', '; |
321
|
1
|
|
|
|
|
11
|
diag "$method( @args ) failed$msg: $@"; |
322
|
1
|
|
|
|
|
447
|
return; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub _numberp { |
326
|
94
|
|
|
94
|
|
758
|
return ($_[0] =~ m/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub _quote { |
330
|
2
|
50
|
|
2
|
|
4
|
defined $_ |
331
|
|
|
|
|
|
|
or return 'undef'; |
332
|
2
|
50
|
|
|
|
5
|
_numberp( $_ ) |
333
|
|
|
|
|
|
|
and return $_; |
334
|
2
|
|
|
|
|
10
|
s/ ( ['\\] ) /\\$1/smx; |
335
|
2
|
|
|
|
|
11
|
return "'$_'"; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
1; |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
__END__ |