1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
9 use CPANPLUS::Configure;
10 use CPANPLUS::Backend;
11 use CPANPLUS::Module::Fake;
12 use CPANPLUS::Module::Author::Fake;
13 use CPANPLUS::Internals::Constants;
15 use Test::More 'no_plan';
19 my $Conf = gimme_conf();
20 my $CB = CPANPLUS::Backend->new( $Conf );
22 ### start with fresh sources ###
23 ok( $CB->reload_indices( update_source => 0 ), "Rebuilding trees" );
25 my $AuthName = TEST_CONF_AUTHOR;
26 my $Auth = $CB->author_tree( $AuthName );
27 my $ModName = TEST_CONF_MODULE;
28 my $Mod = $CB->module_tree( $ModName );
29 my $CoreName = TEST_CONF_PREREQ;
30 my $CoreMod = $CB->module_tree( $CoreName );
32 isa_ok( $Auth, 'CPANPLUS::Module::Author' );
33 isa_ok( $Mod, 'CPANPLUS::Module' );
34 isa_ok( $CoreMod, 'CPANPLUS::Module' );
36 ### author accessors ###
37 is( $Auth->author, 'ExtUtils::MakeMaker No XS Code',
38 "Author name: " . $Auth->author );
39 is( $Auth->cpanid, $AuthName, "Author CPANID: " . $Auth->cpanid );
40 is( $Auth->email, DEFAULT_EMAIL,"Author email: " . $Auth->email );
41 isa_ok( $Auth->parent, 'CPANPLUS::Backend' );
43 ### module accessors ###
49 package => 'Foo-Bar-0.01.tar.gz',
50 path => 'authors/id/EUNOXS',
53 description => 'CPANPLUS Test Package',
58 my @acc = $Mod->accessors;
59 ok( scalar(@acc), "Retrieved module accessors" );
61 ### remove private accessors
62 is_deeply( [ sort keys %map ], [ sort grep { $_ !~ /^_/ } @acc ],
63 " About to test all accessors" );
65 ### check all the accessors
66 while( my($meth,$res) = each %map ) {
67 is( $Mod->$meth, $res, " Mod->$meth: " . ($res || '<empty>') );
70 ### check accessor objects ###
71 isa_ok( $Mod->parent, 'CPANPLUS::Backend' );
72 isa_ok( $Mod->author, 'CPANPLUS::Module::Author' );
73 is( $Mod->author->author, $Auth->author,
77 ### convenience methods ###
78 { ok( 1, "Convenience functions" );
79 is( $Mod->package_name, 'Foo-Bar', " Package name");
80 is( $Mod->package_version, '0.01', " Package version");
81 is( $Mod->package_extension, 'tar.gz', " Package extension");
82 ok( !$Mod->package_is_perl_core, " Package not core");
83 ok( !$Mod->module_is_supplied_with_perl_core, " Module not core" );
84 ok( !$Mod->is_bundle, " Package not bundle");
87 ### clone & status tests
88 { my $clone = $Mod->clone;
89 ok( $clone, "Module cloned" );
90 isa_ok( $clone, 'CPANPLUS::Module' );
92 for my $acc ( $Mod->accessors ) {
93 is( $clone->$acc, $Mod->$acc,
94 " Clone->$acc matches Mod->$acc " );
98 ok( !$clone->_status, "Status object empty on start" );
100 my $status = $clone->status;
101 ok( $status, " Status object defined after query" );
102 is( $status, $clone->_status,
103 " Object stored as expected" );
104 isa_ok( $status, 'Object::Accessor' );
107 { ### extract + error test ###
108 ok( !$Mod->extract(), "Cannot extract unfetched file" );
109 like( CPANPLUS::Error->stack_as_string, qr/You have not fetched/,
110 " Error properly logged" );
113 { ### fetch tests ###
114 ### enable signature checks for checksums ###
115 my $old = $Conf->get_conf('signature');
116 $Conf->set_conf(signature => 1);
118 my $where = $Mod->fetch( force => 1 );
119 ok( $where, "Module fetched" );
120 ok( -f $where, " Module is a file" );
121 ok( -s $where, " Module has size" );
123 $Conf->set_conf( signature => $old );
126 { ### extract tests ###
127 my $dir = $Mod->extract( force => 1 );
128 ok( $dir, "Module extracted" );
129 ok( -d $dir, " Dir exsits" );
133 { ### readme tests ###
134 my $readme = $Mod->readme;
135 ok( length $readme, "Readme found" );
136 is( $readme, $Mod->status->readme,
137 " Readme stored in module object" );
140 { ### checksums tests ###
142 skip(q[You chose not to enable checksum verification], 5)
143 unless $Conf->get_conf('md5');
145 my $cksum_file = $Mod->checksums( force => 1 );
146 ok( $cksum_file, "Checksum file found" );
147 is( $cksum_file, $Mod->status->checksums,
148 " File stored in module object" );
149 ok( -e $cksum_file, " File exists" );
150 ok( -s $cksum_file, " File has size" );
152 ### XXX test checksum_value if there's digest::md5 + config wants it
153 ok( $Mod->status->checksum_ok,
159 { ### installer type tests ###
160 my $installer = $Mod->get_installer_type;
161 ok( $installer, "Installer found" );
162 is( $installer, INSTALLER_MM,
163 " Proper installer found" );
166 { ### check signature tests ###
168 skip(q[You chose not to enable signature checks], 1)
169 unless $Conf->get_conf('signature');
171 ok( $Mod->check_signature,
172 "Signature check OK" );
177 { my $dslip = $Mod->dslip;
178 ok( $dslip, "Got dslip information from $ModName ($dslip)" );
180 ### now find it for a submodule
181 { my $submod = $CB->module_tree( TEST_CONF_MODULE_SUB );
182 ok( $submod, " Found submodule " . $submod->name );
183 ok( $submod->dslip, " Got dslip info (".$submod->dslip.")" );
184 is( $submod->dslip, $dslip,
185 " It's identical to $ModName" );
189 { ### details() test ###
191 'Support Level' => 'Developer',
192 'Package' => $Mod->package,
193 'Description' => $Mod->description,
194 'Development Stage' =>
195 'under construction but pre-alpha (not yet released)',
196 'Author' => sprintf("%s (%s)", $Auth->author, $Auth->email),
197 'Version on CPAN' => $Mod->version,
199 'Perl-only, no compiler needed, should be platform independent',
201 'Object oriented using blessed references and/or inheritance',
202 'Public License' => 'Unknown',
203 ### XXX we can't really know what you have installed ###
204 #'Version Installed' => '0.06',
207 my $res = $Mod->details;
209 ### delete they key of which we don't know the value ###
210 delete $res->{'Version Installed'};
212 is_deeply( $res, $href, "Details OK" );
215 { ### contians() test ###
216 ### XXX ->contains works based on package name. in our sourcefiles
217 ### we use 4x the same package name for different modules. So use
218 ### the only unique package name here, which is the one for the core mod
219 my @list = $CoreMod->contains;
221 ok( scalar(@list), "Found modules contained in this one" );
222 is_deeply( \@list, [$CoreMod],
223 " Found all modules expected" );
226 { ### testing distributions() ###
227 my @mdists = $Mod->distributions;
228 is( scalar @mdists, 1, "Distributions found via module" );
230 my @adists = $Auth->distributions;
231 is( scalar @adists, 3, "Distributions found via author" );
234 { ### test status->flush ###
235 ok( $Mod->status->mk_flush,
237 ok(!$Mod->status->fetch," Fetch status empty" );
238 ok(!$Mod->status->extract,
239 " Extract status empty" );
240 ok(!$Mod->status->checksums,
241 " Checksums status empty" );
242 ok(!$Mod->status->readme,
243 " Readme status empty" );
246 { ### testing bundles ###
247 my $bundle = $CB->module_tree('Bundle::Foo::Bar');
248 isa_ok( $bundle, 'CPANPLUS::Module' );
250 ok( $bundle->is_bundle, " It's a Bundle:: module" );
251 ok( $bundle->fetch, " Fetched the bundle" );
252 ok( $bundle->extract, " Extracted the bundle" );
254 my @objs = $bundle->bundle_modules;
255 is( scalar(@objs), 5, " Found all prerequisites" );
258 isa_ok( $_, 'CPANPLUS::Module',
259 " Prereq " . $_->module );
260 ok( defined $bundle->status->prereqs->{$_->module},
261 " Prereq was registered" );
265 ### test module from perl core ###
266 { isa_ok( $CoreMod, 'CPANPLUS::Module',
267 "Core module " . $CoreName );
268 ok( $CoreMod->package_is_perl_core,
269 " Package found in perl core" );
271 ### check if it's core with 5.6.1
272 { local $] = '5.006001';
273 ok( $CoreMod->module_is_supplied_with_perl_core,
274 " Module also found in perl core");
277 ok( !$CoreMod->install, " Package not installed" );
278 like( CPANPLUS::Error->stack_as_string, qr/core Perl/,
279 " Error properly logged" );
282 ### test third-party modules
284 skip "Module::ThirdParty not installed", 10
285 unless eval { require Module::ThirdParty; 1 };
287 ok( !$Mod->is_third_party,
288 "Not a 3rd party module: ". $Mod->name );
290 my $fake = $CB->parse_module( module => 'LOCAL/SVN-Core-1.0' );
291 ok( $fake, "Created module object for ". $fake->name );
292 ok( $fake->is_third_party,
293 " It is a 3rd party module" );
295 my $info = $fake->third_party_information;
296 ok( $info, "Got 3rd party package information" );
297 isa_ok( $info, 'HASH' );
299 for my $item ( qw[name url author author_url] ) {
300 ok( length($info->{$item}),
301 " $item field is filled" );
305 ### testing EU::Installed methods in Dist::MM tests ###
308 # c-indentation-style: bsd
310 # indent-tabs-mode: nil
312 # vim: expandtab shiftwidth=4: