1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
### make sure we can find our conf.pl file
BEGIN {
use FindBin;
require "$FindBin::Bin/inc/conf.pl";
}
use strict;
use Test::More 'no_plan';
use File::Basename 'dirname';
use Data::Dumper;
use CPANPLUS::Error;
use CPANPLUS::Internals::Constants;
my $conf = gimme_conf();
my $Class = 'CPANPLUS::Backend';
### D::C has troubles with the 'use_ok' -- it finds the wrong paths.
### for now, do a 'use' instead
#use_ok( $Class ) or diag "$Class not found";
use CPANPLUS::Backend;
my $cb = $Class->new( $conf );
isa_ok( $cb, $Class );
my $mt = $cb->module_tree;
my $at = $cb->author_tree;
ok( scalar keys %$mt, "Module tree has entries" );
ok( scalar keys %$at, "Author tree has entries" );
### module_tree tests ###
my $Name = TEST_CONF_MODULE;
my $mod = $cb->module_tree($Name);
### XXX SOURCEFILES FIX
{ my @mods = $cb->module_tree($Name,$Name);
my $none = $cb->module_tree( TEST_CONF_INVALID_MODULE );
ok( IS_MODOBJ->(mod => $mod), "Module object found" );
is( scalar(@mods), 2, " Module list found" );
ok( IS_MODOBJ->(mod => $mods[0]), " ISA module object" );
ok( !IS_MODOBJ->(mod => $none), " Bogus module detected");
}
### author_tree tests ###
{ my @auths = $cb->author_tree( $mod->author->cpanid,
$mod->author->cpanid );
my $none = $cb->author_tree( 'fnurk' );
ok( IS_AUTHOBJ->(auth => $mod->author), "Author object found" );
is( scalar(@auths), 2, " Author list found" );
ok( IS_AUTHOBJ->( author => $auths[0] )," ISA author object" );
is( $mod->author, $auths[0], " Objects are identical" );
ok( !IS_AUTHOBJ->( author => $none ), " Bogus author detected" );
}
my $conf_obj = $cb->configure_object;
ok( IS_CONFOBJ->(conf => $conf_obj), "Configure object found" );
### parse_module tests ###
{ my @map = (
$Name => [
$mod->author->cpanid, # author
$mod->package_name, # package name
$mod->version, # version
],
$mod => [
$mod->author->cpanid,
$mod->package_name,
$mod->version,
],
'Foo-Bar-EU-NOXS' => [
$mod->author->cpanid,
$mod->package_name,
$mod->version,
],
'Foo-Bar-EU-NOXS-0.01' => [
$mod->author->cpanid,
$mod->package_name,
'0.01',
],
'EUNOXS/Foo-Bar-EU-NOXS' => [
'EUNOXS',
$mod->package_name,
$mod->version,
],
'EUNOXS/Foo-Bar-EU-NOXS-0.01' => [
'EUNOXS',
$mod->package_name,
'0.01',
],
### existing module, no extension given
### this used to create a modobj with no package extension
'EUNOXS/Foo-Bar-0.02' => [
'EUNOXS',
'Foo-Bar',
'0.02',
],
'Foo-Bar-EU-NOXS-0.09' => [
$mod->author->cpanid,
$mod->package_name,
'0.09',
],
'MBXS/Foo-Bar-EU-NOXS-0.01' => [
'MBXS',
$mod->package_name,
'0.01',
],
'EUNOXS/Foo-Bar-EU-NOXS-0.09' => [
'EUNOXS',
$mod->package_name,
'0.09',
],
'EUNOXS/Foo-Bar-EU-NOXS-0.09.zip' => [
'EUNOXS',
$mod->package_name,
'0.09',
],
'FROO/Flub-Flob-1.1.zip' => [
'FROO',
'Flub-Flob',
'1.1',
],
'G/GO/GOYALI/SMS_API_3_01.tar.gz' => [
'GOYALI',
'SMS_API',
'3_01',
],
'E/EY/EYCK/Net/Lite/Net-Lite-FTP-0.091' => [
'EYCK',
'Net-Lite-FTP',
'0.091',
],
'EYCK/Net/Lite/Net-Lite-FTP-0.091' => [
'EYCK',
'Net-Lite-FTP',
'0.091',
],
'M/MA/MAXDB/DBD-MaxDB-7.5.0.24a' => [
'MAXDB',
'DBD-MaxDB',
'7.5.0.24a',
],
'EUNOXS/perl5.005_03.tar.gz' => [
'EUNOXS',
'perl',
'5.005_03',
],
'FROO/Flub-Flub-v1.1.0.tbz' => [
'FROO',
'Flub-Flub',
'v1.1.0',
],
'FROO/Flub-Flub-1.1_2.tbz' => [
'FROO',
'Flub-Flub',
'1.1_2',
],
'LDS/CGI.pm-3.27.tar.gz' => [
'LDS',
'CGI',
'3.27',
],
'FROO/Text-Tabs+Wrap-2006.1117.tar.gz' => [
'FROO',
'Text-Tabs+Wrap',
'2006.1117',
],
'JETTERO/Crypt-PBC-0.7.20.0-0.4.9' => [
'JETTERO',
'Crypt-PBC',
'0.7.20.0-0.4.9' ,
],
'GRICHTER/HTML-Embperl-1.2.1.tar.gz' => [
'GRICHTER',
'HTML-Embperl',
'1.2.1',
],
'KANE/File-Fetch-0.15_03' => [
'KANE',
'File-Fetch',
'0.15_03',
],
'AUSCHUTZ/IO-Stty-.02.tar.gz' => [
'AUSCHUTZ',
'IO-Stty',
'.02',
],
);
while ( my($guess, $attr) = splice @map, 0, 2 ) {
my( $author, $pkg_name, $version ) = @$attr;
ok( $guess, "Attempting to parse $guess" );
my $obj = $cb->parse_module( module => $guess );
ok( $obj, " Result returned" );
ok( IS_MODOBJ->( mod => $obj ),
" parse_module success by '$guess'" );
is( $obj->version, $version,
" Proper version found: $version" );
is( $obj->package_version, $version,
" Found in package_version as well" );
is( $obj->package_name, $pkg_name,
" Proper package_name found: $pkg_name" );
unlike( $obj->package_name, qr/\d/,
" No digits in package name" );
{ my $ext = $obj->package_extension;
ok( $ext, " Has extension as well: $ext" );
}
like( $obj->author->cpanid, "/$author/i",
" Proper author found: $author");
like( $obj->path, "/$author/i",
" Proper path found: " . $obj->path );
}
### test for things that look like real modules, but aren't ###
{ my @map = (
[ $Name . $$ => [
[qr/does not contain an author/,"Missing author part detected"],
[qr/Cannot find .+? in the module tree/,"Unable to find module"]
] ],
[ {}, => [
[ qr/module string from reference/,"Unable to parse ref"]
] ],
);
for my $entry ( @map ) {
my($mod,$aref) = @$entry;
my $none = $cb->parse_module( module => $mod );
ok( !IS_MODOBJ->(mod => $none),
"Non-existant module detected" );
ok( !IS_FAKE_MODOBJ->(mod => $none),
"Non-existant fake module detected" );
my $str = CPANPLUS::Error->stack_as_string;
for my $pair (@$aref) {
my($re,$diag) = @$pair;
like( $str, $re," $diag" );
}
}
}
### test parsing of arbitrary URI
for my $guess ( qw[ http://foo/bar.gz
http://a/b/c/d/e/f/g/h/i/j
flub://floo ]
) {
my $obj = $cb->parse_module( module => $guess );
ok( IS_FAKE_MODOBJ->(mod => $obj),
"parse_module success by '$guess'" );
is( $obj->status->_fetch_from, $guess,
" Fetch from set ok" );
}
}
### RV tests ###
{ my $method = 'readme';
my %args = ( modules => [$Name] );
my $rv = $cb->$method( %args );
ok( IS_RVOBJ->( $rv ), "Got an RV object" );
ok( $rv->ok, " Overall OK" );
cmp_ok( $rv, '==', 1, " Overload OK" );
is( $rv->function, $method, " Function stored OK" );
is_deeply( $rv->args, \%args, " Arguments stored OK" );
is( $rv->rv->{$Name}, $mod->readme, " RV as expected" );
}
### reload_indices tests ###
{
my $file = File::Spec->catfile( $conf->get_conf('base'),
$conf->_get_source('mod'),
);
ok( $cb->reload_indices( update_source => 0 ), "Rebuilding trees" );
my $age = -M $file;
### make sure we are 'newer' on faster machines with a sleep..
### apparently Win32's FAT isn't granual enough on intervals
### < 2 seconds, so it may give the same answer before and after
### the sleep, causing the test to fail. so sleep atleast 2 seconds.
sleep 2;
ok( $cb->reload_indices( update_source => 1 ),
"Rebuilding and refetching trees" );
cmp_ok( $age, '>', -M $file, " Source file '$file' updated" );
}
### flush tests ###
{
for my $cache( qw[methods hosts modules lib all] ) {
ok( $cb->flush($cache), "Cache $cache flushed ok" );
}
}
### installed tests ###
{ ok( scalar($cb->installed), "Found list of installed modules" );
}
### autobudle tests ###
{
my $where = $cb->autobundle;
ok( $where, "Autobundle written" );
ok( -s $where, " File has size" );
}
### local_mirror tests ###
{ ### turn off md5 checks for the 'fake' packages we have
my $old_md5 = $conf->get_conf('md5');
$conf->set_conf( md5 => 0 );
### otherwise 'status->fetch' might be undef! ###
my $rv = $cb->local_mirror( path => 'dummy-localmirror' );
ok( $rv, "Local mirror created" );
for my $mod ( values %{ $cb->module_tree } ) {
my $name = $mod->module;
my $cksum = File::Spec->catfile(
dirname($mod->status->fetch),
CHECKSUMS );
ok( -e $mod->status->fetch, " Module '$name' fetched" );
ok( -s _, " Module '$name' has size" );
ok( -e $cksum, " Checksum fetched for '$name'" );
ok( -s _, " Checksum for '$name' has size" );
}
$conf->set_conf( md5 => $old_md5 );
}
### check ENV variable
{ ### process id
{ my $name = 'PERL5_CPANPLUS_IS_RUNNING';
ok( $ENV{$name}, "Env var '$name' set" );
is( $ENV{$name}, $$, " Set to current process id" );
}
### Version
{ my $name = 'PERL5_CPANPLUS_IS_VERSION';
ok( $ENV{$name}, "Env var '$name' set" );
### version.pm formats ->VERSION output... *sigh*
is( $ENV{$name}, $Class->VERSION,
" Set to current process version" );
}
}
__END__
# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:
|