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 ### silence errors, unless you tell us not to ###
20 local $CPANPLUS::Error::ERROR_FH = output_handle() unless @ARGV;
22 my $Conf = gimme_conf();
23 my $CB = CPANPLUS::Backend->new( $Conf );
25 ### start with fresh sources ###
26 ok( $CB->reload_indices( update_source => 0 ), "Rebuilding trees" );
28 my $AuthName = 'EUNOXS';
29 my $Auth = $CB->author_tree( $AuthName );
30 my $ModName = TEST_CONF_MODULE;
31 my $Mod = $CB->module_tree( $ModName );
32 my $CoreName = TEST_CONF_PREREQ;
33 my $CoreMod = $CB->module_tree( $CoreName );
35 isa_ok( $Auth, 'CPANPLUS::Module::Author' );
36 isa_ok( $Mod, 'CPANPLUS::Module' );
37 isa_ok( $CoreMod, 'CPANPLUS::Module' );
39 ### author accessors ###
40 is( $Auth->author, 'ExtUtils::MakeMaker No XS Code',
41 "Author name: " . $Auth->author );
42 is( $Auth->cpanid, $AuthName, "Author CPANID: " . $Auth->cpanid );
43 is( $Auth->email, DEFAULT_EMAIL,"Author email: " . $Auth->email );
44 isa_ok( $Auth->parent, 'CPANPLUS::Backend' );
46 ### module accessors ###
52 package => 'Foo-Bar-0.01.tar.gz',
53 path => 'authors/id/E/EU/EUNOXS',
56 description => 'CPANPLUS Test Package',
61 my @acc = $Mod->accessors;
62 ok( scalar(@acc), "Retrieved module accessors" );
64 ### remove private accessors
65 is_deeply( [ sort keys %map ], [ sort grep { $_ !~ /^_/ } @acc ],
66 " About to test all accessors" );
68 ### check all the accessors
69 while( my($meth,$res) = each %map ) {
70 is( $Mod->$meth, $res, " Mod->$meth: " . ($res || '<empty>') );
73 ### check accessor objects ###
74 isa_ok( $Mod->parent, 'CPANPLUS::Backend' );
75 isa_ok( $Mod->author, 'CPANPLUS::Module::Author' );
76 is( $Mod->author->author, $Auth->author,
80 ### convenience methods ###
81 { ok( 1, "Convenience functions" );
82 is( $Mod->package_name, 'Foo-Bar', " Package name");
83 is( $Mod->package_version, '0.01', " Package version");
84 is( $Mod->package_extension, 'tar.gz', " Package extension");
85 ok( !$Mod->package_is_perl_core, " Package not core");
86 ok( !$Mod->module_is_supplied_with_perl_core, " Module not core" );
87 ok( !$Mod->is_bundle, " Package not bundle");
90 ### clone & status tests
91 { my $clone = $Mod->clone;
92 ok( $clone, "Module cloned" );
93 isa_ok( $clone, 'CPANPLUS::Module' );
95 for my $acc ( $Mod->accessors ) {
96 is( $clone->$acc, $Mod->$acc,
97 " Clone->$acc matches Mod->$acc " );
100 ### XXX whitebox test
101 ok( !$clone->_status, "Status object empty on start" );
103 my $status = $clone->status;
104 ok( $status, " Status object defined after query" );
105 is( $status, $clone->_status,
106 " Object stored as expected" );
107 isa_ok( $status, 'Object::Accessor' );
110 { ### extract + error test ###
111 ok( !$Mod->extract(), "Cannot extract unfetched file" );
112 like( CPANPLUS::Error->stack_as_string, qr/You have not fetched/,
113 " Error properly logged" );
116 { ### fetch tests ###
117 ### enable signature checks for checksums ###
118 my $old = $Conf->get_conf('signature');
119 $Conf->set_conf(signature => 1);
121 my $where = $Mod->fetch( force => 1 );
122 ok( $where, "Module fetched" );
123 ok( -f $where, " Module is a file" );
124 ok( -s $where, " Module has size" );
126 $Conf->set_conf( signature => $old );
129 { ### extract tests ###
130 my $dir = $Mod->extract( force => 1 );
131 ok( $dir, "Module extracted" );
132 ok( -d $dir, " Dir exsits" );
136 { ### readme tests ###
137 my $readme = $Mod->readme;
138 ok( length $readme, "Readme found" );
139 is( $readme, $Mod->status->readme,
140 " Readme stored in module object" );
143 { ### checksums tests ###
145 skip(q[You chose not to enable checksum verification], 5)
146 unless $Conf->get_conf('md5');
148 my $cksum_file = $Mod->checksums( force => 1 );
149 ok( $cksum_file, "Checksum file found" );
150 is( $cksum_file, $Mod->status->checksums,
151 " File stored in module object" );
152 ok( -e $cksum_file, " File exists" );
153 ok( -s $cksum_file, " File has size" );
155 ### XXX test checksum_value if there's digest::md5 + config wants it
156 ok( $Mod->status->checksum_ok,
162 { ### installer type tests ###
163 my $installer = $Mod->get_installer_type;
164 ok( $installer, "Installer found" );
165 is( $installer, INSTALLER_MM,
166 " Proper installer found" );
169 { ### check signature tests ###
171 skip(q[You chose not to enable signature checks], 1)
172 unless $Conf->get_conf('signature');
174 ok( $Mod->check_signature,
175 "Signature check OK" );
179 { ### details() test ###
181 'Support Level' => 'Developer',
182 'Package' => $Mod->package,
183 'Description' => $Mod->description,
184 'Development Stage' =>
185 'under construction but pre-alpha (not yet released)',
186 'Author' => sprintf("%s (%s)", $Auth->author, $Auth->email),
187 'Version on CPAN' => $Mod->version,
189 'Perl-only, no compiler needed, should be platform independent',
191 'Object oriented using blessed references and/or inheritance',
192 'Public License' => 'Unknown',
193 ### XXX we can't really know what you have installed ###
194 #'Version Installed' => '0.06',
197 my $res = $Mod->details;
199 ### delete they key of which we don't know the value ###
200 delete $res->{'Version Installed'};
202 is_deeply( $res, $href, "Details OK" );
205 { ### contians() test ###
206 ### XXX ->contains works based on package name. in our sourcefiles
207 ### we use 4x the same package name for different modules. So use
208 ### the only unique package name here, which is the one for the core mod
209 my @list = $CoreMod->contains;
211 ok( scalar(@list), "Found modules contained in this one" );
212 is_deeply( \@list, [$CoreMod],
213 " Found all modules expected" );
216 { ### testing distributions() ###
217 my @mdists = $Mod->distributions;
218 is( scalar @mdists, 1, "Distributions found via module" );
220 my @adists = $Auth->distributions;
221 is( scalar @adists, 3, "Distributions found via author" );
224 { ### test status->flush ###
225 ok( $Mod->status->mk_flush,
227 ok(!$Mod->status->fetch," Fetch status empty" );
228 ok(!$Mod->status->extract,
229 " Extract status empty" );
230 ok(!$Mod->status->checksums,
231 " Checksums status empty" );
232 ok(!$Mod->status->readme,
233 " Readme status empty" );
236 { ### testing bundles ###
237 my $bundle = $CB->module_tree('Bundle::Foo::Bar');
238 isa_ok( $bundle, 'CPANPLUS::Module' );
240 ok( $bundle->is_bundle, " It's a Bundle:: module" );
241 ok( $bundle->fetch, " Fetched the bundle" );
242 ok( $bundle->extract, " Extracted the bundle" );
244 my @objs = $bundle->bundle_modules;
245 is( scalar(@objs), 5, " Found all prerequisites" );
248 isa_ok( $_, 'CPANPLUS::Module',
249 " Prereq " . $_->module );
250 ok( defined $bundle->status->prereqs->{$_->module},
251 " Prereq was registered" );
255 ### test module from perl core ###
256 { isa_ok( $CoreMod, 'CPANPLUS::Module',
257 "Core module " . $CoreName );
258 ok( $CoreMod->package_is_perl_core,
259 " Package found in perl core" );
261 ### check if it's core with 5.6.1
262 { local $] = '5.006001';
263 ok( $CoreMod->module_is_supplied_with_perl_core,
264 " Module also found in perl core");
267 ok( !$CoreMod->install, " Package not installed" );
268 like( CPANPLUS::Error->stack_as_string, qr/core Perl/,
269 " Error properly logged" );
272 ### test third-party modules
274 skip "Module::ThirdParty not installed", 10
275 unless eval { require Module::ThirdParty; 1 };
277 ok( !$Mod->is_third_party,
278 "Not a 3rd party module: ". $Mod->name );
280 my $fake = $CB->parse_module( module => 'LOCAL/SVN-Core-1.0' );
281 ok( $fake, "Created module object for ". $fake->name );
282 ok( $fake->is_third_party,
283 " It is a 3rd party module" );
285 my $info = $fake->third_party_information;
286 ok( $info, "Got 3rd party package information" );
287 isa_ok( $info, 'HASH' );
289 for my $item ( qw[name url author author_url] ) {
290 ok( length($info->{$item}),
291 " $item field is filled" );
295 ### testing EU::Installed methods in Dist::MM tests ###
298 # c-indentation-style: bsd
300 # indent-tabs-mode: nil
302 # vim: expandtab shiftwidth=4: