Add CPANPLUS 0.78
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / t / 04_CPANPLUS-Module.t
CommitLineData
6aaee015 1### make sure we can find our conf.pl file
2BEGIN {
3 use FindBin;
4 require "$FindBin::Bin/inc/conf.pl";
5}
6
7use strict;
8
9use CPANPLUS::Configure;
10use CPANPLUS::Backend;
11use CPANPLUS::Module::Fake;
12use CPANPLUS::Module::Author::Fake;
13use CPANPLUS::Internals::Constants;
14
15use Test::More 'no_plan';
16use Data::Dumper;
17use File::Path ();
18
19### silence errors, unless you tell us not to ###
20local $CPANPLUS::Error::ERROR_FH = output_handle() unless @ARGV;
21
22my $Conf = gimme_conf();
23my $CB = CPANPLUS::Backend->new( $Conf );
24
25### start with fresh sources ###
26ok( $CB->reload_indices( update_source => 0 ), "Rebuilding trees" );
27
28my $AuthName = 'EUNOXS';
29my $Auth = $CB->author_tree( $AuthName );
30my $ModName = TEST_CONF_MODULE;
31my $Mod = $CB->module_tree( $ModName );
32my $CoreName = TEST_CONF_PREREQ;
33my $CoreMod = $CB->module_tree( $CoreName );
34
35isa_ok( $Auth, 'CPANPLUS::Module::Author' );
36isa_ok( $Mod, 'CPANPLUS::Module' );
37isa_ok( $CoreMod, 'CPANPLUS::Module' );
38
39### author accessors ###
40is( $Auth->author, 'ExtUtils::MakeMaker No XS Code',
41 "Author name: " . $Auth->author );
42is( $Auth->cpanid, $AuthName, "Author CPANID: " . $Auth->cpanid );
43is( $Auth->email, DEFAULT_EMAIL,"Author email: " . $Auth->email );
44isa_ok( $Auth->parent, 'CPANPLUS::Backend' );
45
46### module accessors ###
47{ my %map = (
48 ### method ### result
49 module => $ModName,
50 name => $ModName,
51 comment => undef,
52 package => 'Foo-Bar-0.01.tar.gz',
53 path => 'authors/id/E/EU/EUNOXS',
54 version => '0.01',
55 dslip => 'cdpO ',
56 description => 'CPANPLUS Test Package',
57 mtime => '',
58 author => $Auth,
59 );
60
61 my @acc = $Mod->accessors;
62 ok( scalar(@acc), "Retrieved module accessors" );
63
64 ### remove private accessors
65 is_deeply( [ sort keys %map ], [ sort grep { $_ !~ /^_/ } @acc ],
66 " About to test all accessors" );
67
68 ### check all the accessors
69 while( my($meth,$res) = each %map ) {
70 is( $Mod->$meth, $res, " Mod->$meth: " . ($res || '<empty>') );
71 }
72
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,
77 "Module eq Author" );
78}
79
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");
88}
89
90### clone & status tests
91{ my $clone = $Mod->clone;
92 ok( $clone, "Module cloned" );
93 isa_ok( $clone, 'CPANPLUS::Module' );
94
95 for my $acc ( $Mod->accessors ) {
96 is( $clone->$acc, $Mod->$acc,
97 " Clone->$acc matches Mod->$acc " );
98 }
99
100 ### XXX whitebox test
101 ok( !$clone->_status, "Status object empty on start" );
102
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' );
108}
109
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" );
114}
115
116{ ### fetch tests ###
117 ### enable signature checks for checksums ###
118 my $old = $Conf->get_conf('signature');
119 $Conf->set_conf(signature => 1);
120
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" );
125
126 $Conf->set_conf( signature => $old );
127}
128
129{ ### extract tests ###
130 my $dir = $Mod->extract( force => 1 );
131 ok( $dir, "Module extracted" );
132 ok( -d $dir, " Dir exsits" );
133}
134
135
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" );
141}
142
143{ ### checksums tests ###
144 SKIP: {
145 skip(q[You chose not to enable checksum verification], 5)
146 unless $Conf->get_conf('md5');
147
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" );
154
155 ### XXX test checksum_value if there's digest::md5 + config wants it
156 ok( $Mod->status->checksum_ok,
157 " Checksum is ok" );
158 }
159}
160
161
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" );
167}
168
169{ ### check signature tests ###
170 SKIP: {
171 skip(q[You chose not to enable signature checks], 1)
172 unless $Conf->get_conf('signature');
173
174 ok( $Mod->check_signature,
175 "Signature check OK" );
176 }
177}
178
179{ ### details() test ###
180 my $href = {
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,
188 'Language Used' =>
189 'Perl-only, no compiler needed, should be platform independent',
190 'Interface Style' =>
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',
195 };
196
197 my $res = $Mod->details;
198
199 ### delete they key of which we don't know the value ###
200 delete $res->{'Version Installed'};
201
202 is_deeply( $res, $href, "Details OK" );
203}
204
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;
210
211 ok( scalar(@list), "Found modules contained in this one" );
212 is_deeply( \@list, [$CoreMod],
213 " Found all modules expected" );
214}
215
216{ ### testing distributions() ###
217 my @mdists = $Mod->distributions;
218 is( scalar @mdists, 1, "Distributions found via module" );
219
220 my @adists = $Auth->distributions;
221 is( scalar @adists, 3, "Distributions found via author" );
222}
223
224{ ### test status->flush ###
225 ok( $Mod->status->mk_flush,
226 "Status flushed" );
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" );
234}
235
236{ ### testing bundles ###
237 my $bundle = $CB->module_tree('Bundle::Foo::Bar');
238 isa_ok( $bundle, 'CPANPLUS::Module' );
239
240 ok( $bundle->is_bundle, " It's a Bundle:: module" );
241 ok( $bundle->fetch, " Fetched the bundle" );
242 ok( $bundle->extract, " Extracted the bundle" );
243
244 my @objs = $bundle->bundle_modules;
245 is( scalar(@objs), 5, " Found all prerequisites" );
246
247 for( @objs ) {
248 isa_ok( $_, 'CPANPLUS::Module',
249 " Prereq " . $_->module );
250 ok( defined $bundle->status->prereqs->{$_->module},
251 " Prereq was registered" );
252 }
253}
254
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" );
260
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");
265 }
266
267 ok( !$CoreMod->install, " Package not installed" );
268 like( CPANPLUS::Error->stack_as_string, qr/core Perl/,
269 " Error properly logged" );
270}
271
272### test third-party modules
273SKIP: {
274 skip "Module::ThirdParty not installed", 10
275 unless eval { require Module::ThirdParty; 1 };
276
277 ok( !$Mod->is_third_party,
278 "Not a 3rd party module: ". $Mod->name );
279
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" );
284
285 my $info = $fake->third_party_information;
286 ok( $info, "Got 3rd party package information" );
287 isa_ok( $info, 'HASH' );
288
289 for my $item ( qw[name url author author_url] ) {
290 ok( length($info->{$item}),
291 " $item field is filled" );
292 }
293}
294
295### testing EU::Installed methods in Dist::MM tests ###
296
297# Local variables:
298# c-indentation-style: bsd
299# c-basic-offset: 4
300# indent-tabs-mode: nil
301# End:
302# vim: expandtab shiftwidth=4: