line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Test; |
2
|
1
|
|
|
1
|
|
176696
|
use Module::Load; |
|
1
|
|
|
|
|
1466
|
|
|
1
|
|
|
|
|
8
|
|
3
|
1
|
|
|
1
|
|
1267
|
use Test::More 'no_plan'; |
|
1
|
|
|
|
|
23322
|
|
|
1
|
|
|
|
|
14
|
|
4
|
1
|
|
|
1
|
|
360
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
180
|
use vars qw[$VERSION]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
236
|
|
7
|
|
|
|
|
|
|
$VERSION = 0.03; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $href = { |
10
|
|
|
|
|
|
|
CODE => { type => 'subroutine', |
11
|
|
|
|
|
|
|
post => '()', |
12
|
|
|
|
|
|
|
tests => [ |
13
|
|
|
|
|
|
|
'passed expected parameters', |
14
|
|
|
|
|
|
|
'catches faulty input', |
15
|
|
|
|
|
|
|
'works as expected with no input', |
16
|
|
|
|
|
|
|
'return value OK', |
17
|
|
|
|
|
|
|
] |
18
|
|
|
|
|
|
|
}, |
19
|
|
|
|
|
|
|
SCALAR => { type => 'global scalar', |
20
|
|
|
|
|
|
|
pre => '$', |
21
|
|
|
|
|
|
|
tests => [ |
22
|
|
|
|
|
|
|
'available', |
23
|
|
|
|
|
|
|
'initialized properly', |
24
|
|
|
|
|
|
|
'content OK', |
25
|
|
|
|
|
|
|
] |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
HASH => { type => 'global hash', |
28
|
|
|
|
|
|
|
pre => '%', |
29
|
|
|
|
|
|
|
tests => [ |
30
|
|
|
|
|
|
|
'available', |
31
|
|
|
|
|
|
|
'initialized properly', |
32
|
|
|
|
|
|
|
'contains all expected key/value pairs', |
33
|
|
|
|
|
|
|
] |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
ARRAY => { type => 'global array', |
36
|
|
|
|
|
|
|
pre => '@', |
37
|
|
|
|
|
|
|
tests => [ |
38
|
|
|
|
|
|
|
'available', |
39
|
|
|
|
|
|
|
'initialized properly', |
40
|
|
|
|
|
|
|
'contains all expected elements', |
41
|
|
|
|
|
|
|
] |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
IO => { type => 'global IO/Filehandle', |
44
|
|
|
|
|
|
|
tests => [ |
45
|
|
|
|
|
|
|
'available', |
46
|
|
|
|
|
|
|
'initialized properly', |
47
|
|
|
|
|
|
|
] |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
FORMAT => { type => 'format', |
50
|
|
|
|
|
|
|
tests => [ |
51
|
|
|
|
|
|
|
'available', |
52
|
|
|
|
|
|
|
'prints ok', |
53
|
|
|
|
|
|
|
] |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
Regexp => { type => 'regex', |
56
|
|
|
|
|
|
|
tests => [ |
57
|
|
|
|
|
|
|
'available', |
58
|
|
|
|
|
|
|
'initialized properly', |
59
|
|
|
|
|
|
|
] |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub import { |
64
|
1
|
|
|
1
|
|
8
|
my $class = shift; |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
|
|
|
5
|
unless(@_) { |
67
|
0
|
|
|
|
|
0
|
warn qq[Useless call to Acme::Test::import!\n] . |
68
|
|
|
|
|
|
|
qq[Usage:\tuse Acme::Test qw|Your::Package|\n]; |
69
|
0
|
|
|
|
|
0
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
588
|
|
73
|
1
|
|
|
|
|
3
|
for my $mod ( @_ ) { |
74
|
1
|
|
|
|
|
5
|
load $mod; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
90
|
my $str = join '/', split '::', $mod; |
77
|
1
|
|
|
|
|
167
|
my @pkgs = map { s|/|::|g; s/\.pm$//i; $_ } grep /^$str/, keys %INC; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
4
|
|
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
5
|
for my $pkg (@pkgs) { |
80
|
1
|
|
|
|
|
6
|
diag("Testing $pkg"); |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
175
|
my $stash = $pkg . '::'; |
83
|
1
|
|
|
|
|
20
|
for my $name (sort keys %$stash ) { |
84
|
|
|
|
|
|
|
|
85
|
33
|
|
|
|
|
89
|
for my $type (keys %$href) { |
86
|
|
|
|
|
|
|
|
87
|
231
|
|
|
|
|
10723
|
my $x = *{"$stash->{$name}"}{$type}; |
|
231
|
|
|
|
|
875
|
|
88
|
231
|
100
|
|
|
|
2279
|
next unless defined $x; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
### so apparently some entries in the scalar slot |
91
|
|
|
|
|
|
|
### are set regardless, but are references to undef |
92
|
|
|
|
|
|
|
### let's just skip these... |
93
|
63
|
100
|
100
|
|
|
1309
|
next if ref $x eq "SCALAR" and not defined $$x; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
### some hash entries might be other stashes again |
96
|
|
|
|
|
|
|
### let's just skip these as well... |
97
|
31
|
50
|
33
|
|
|
75
|
next if ref $x eq "HASH" and $name =~ /::$/; |
98
|
|
|
|
|
|
|
|
99
|
31
|
50
|
|
|
|
63
|
my $priv = $name =~/^_/ ? 1 : 0; |
100
|
31
|
50
|
|
|
|
51
|
my $status = $priv ? '[Private]' : '[Public]'; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#next if $priv && $NO_PRIVATE; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
### add sigils and the like ### |
105
|
31
|
|
|
|
|
46
|
my $short = $name; |
106
|
31
|
|
|
|
|
49
|
my $full = "${pkg}::$name"; |
107
|
31
|
|
|
|
|
42
|
for my $alias ($short, $full) { |
108
|
62
|
100
|
|
|
|
2946
|
$alias = $href->{$type}->{pre} . $alias |
109
|
|
|
|
|
|
|
if $href->{$type}->{pre}; |
110
|
62
|
100
|
|
|
|
191
|
$alias .= $href->{$type}->{post} if $href->{$type}->{post}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
31
|
|
|
|
|
123
|
diag("$status Testing $href->{$type}->{type} $full"); |
114
|
|
|
|
|
|
|
|
115
|
31
|
|
|
|
|
3648
|
for my $test ( @{$href->{$type}->{tests}} ) { |
|
31
|
|
|
|
|
84
|
|
116
|
123
|
|
|
|
|
34728
|
ok( 1, " $short $test" ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=pod |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 NAME |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Acme::Test |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SYNOPSIS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
use Acme::Test qw[Your::Module Your::Other::Module]; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
All the latest software craze is about regression tests and XP |
138
|
|
|
|
|
|
|
programming -- Write a test, make sure it fails. Then write the |
139
|
|
|
|
|
|
|
functionality and make sure the test now passes, etc. |
140
|
|
|
|
|
|
|
Although these are good ideas, who really has time for this? |
141
|
|
|
|
|
|
|
Fixing faililng tests is a lot of work, and one can only be happy |
142
|
|
|
|
|
|
|
with a test suite that has no fails. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Enter C -- automate test-suite generation with guaranteed |
145
|
|
|
|
|
|
|
passing tests for your modules! |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 USE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Simply write |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
use Acme::Test 'Your::Module'; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
at the top of your test scrip, and everything else goes automatically. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
C will not only 'test' your subroutines, but also any |
156
|
|
|
|
|
|
|
global variables and even IO and format handles! It will also make a |
157
|
|
|
|
|
|
|
distinction between public and private subroutines/variables. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 EXAMPLE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Imagine your test.pl script would look something like this: |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
use lib '../devel/file-basename/lib'; |
164
|
|
|
|
|
|
|
use Acme::Test 'File::Basename'; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Then the resulting test output would look pretty much like this: |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Testing File::Basename |
169
|
|
|
|
|
|
|
# [Public] Testing global array @File::Basename::EXPORT |
170
|
|
|
|
|
|
|
ok 1 - @EXPORT available |
171
|
|
|
|
|
|
|
ok 2 - @EXPORT initialized properly |
172
|
|
|
|
|
|
|
ok 3 - @EXPORT contains all expected elements |
173
|
|
|
|
|
|
|
# [Public] Testing global scalar $File::Basename::Fileparse_fstype |
174
|
|
|
|
|
|
|
ok 4 - $Fileparse_fstype available |
175
|
|
|
|
|
|
|
ok 5 - $Fileparse_fstype initialized properly |
176
|
|
|
|
|
|
|
ok 6 - $Fileparse_fstype content OK |
177
|
|
|
|
|
|
|
# [Public] Testing global scalar $File::Basename::Fileparse_igncase |
178
|
|
|
|
|
|
|
ok 7 - $Fileparse_igncase available |
179
|
|
|
|
|
|
|
ok 8 - $Fileparse_igncase initialized properly |
180
|
|
|
|
|
|
|
ok 9 - $Fileparse_igncase content OK |
181
|
|
|
|
|
|
|
# [Public] Testing global array @File::Basename::ISA |
182
|
|
|
|
|
|
|
ok 10 - @ISA available |
183
|
|
|
|
|
|
|
ok 11 - @ISA initialized properly |
184
|
|
|
|
|
|
|
ok 12 - @ISA contains all expected elements |
185
|
|
|
|
|
|
|
# [Public] Testing global scalar $File::Basename::VERSION |
186
|
|
|
|
|
|
|
ok 13 - $VERSION available |
187
|
|
|
|
|
|
|
ok 14 - $VERSION initialized properly |
188
|
|
|
|
|
|
|
ok 15 - $VERSION content OK |
189
|
|
|
|
|
|
|
# [Public] Testing subroutine File::Basename::basename() |
190
|
|
|
|
|
|
|
ok 16 - basename() passed expected parameters |
191
|
|
|
|
|
|
|
ok 17 - basename() catches faulty input |
192
|
|
|
|
|
|
|
ok 18 - basename() works as expected with no input |
193
|
|
|
|
|
|
|
ok 19 - basename() return value OK |
194
|
|
|
|
|
|
|
# [Public] Testing subroutine File::Basename::dirname() |
195
|
|
|
|
|
|
|
ok 20 - dirname() passed expected parameters |
196
|
|
|
|
|
|
|
ok 21 - dirname() catches faulty input |
197
|
|
|
|
|
|
|
ok 22 - dirname() works as expected with no input |
198
|
|
|
|
|
|
|
ok 23 - dirname() return value OK |
199
|
|
|
|
|
|
|
# [Public] Testing subroutine File::Basename::fileparse() |
200
|
|
|
|
|
|
|
ok 24 - fileparse() passed expected parameters |
201
|
|
|
|
|
|
|
ok 25 - fileparse() catches faulty input |
202
|
|
|
|
|
|
|
ok 26 - fileparse() works as expected with no input |
203
|
|
|
|
|
|
|
ok 27 - fileparse() return value OK |
204
|
|
|
|
|
|
|
# [Public] Testing subroutine File::Basename::fileparse_set_fstype() |
205
|
|
|
|
|
|
|
ok 28 - fileparse_set_fstype() passed expected parameters |
206
|
|
|
|
|
|
|
ok 29 - fileparse_set_fstype() catches faulty input |
207
|
|
|
|
|
|
|
ok 30 - fileparse_set_fstype() works as expected with no input |
208
|
|
|
|
|
|
|
ok 31 - fileparse_set_fstype() return value OK |
209
|
|
|
|
|
|
|
1..31 |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 BUGS |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
In code this funky, I'm sure there are some ;) |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 AUTHOR |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This module by |
218
|
|
|
|
|
|
|
Jos Boumans Ekane@cpan.orgE. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 COPYRIGHT |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
This module is |
224
|
|
|
|
|
|
|
copyright (c) 2002 Jos Boumans Ekane@cpan.orgE. |
225
|
|
|
|
|
|
|
All rights reserved. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This library is free software; |
228
|
|
|
|
|
|
|
you may redistribute and/or modify it under the same |
229
|
|
|
|
|
|
|
terms as Perl itself. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |