Re: [perl #46011] [RESOLVED] overload "0+" doesn't handle integer results
[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
6aaee015 19my $Conf = gimme_conf();
20my $CB = CPANPLUS::Backend->new( $Conf );
21
22### start with fresh sources ###
23ok( $CB->reload_indices( update_source => 0 ), "Rebuilding trees" );
24
25my $AuthName = 'EUNOXS';
26my $Auth = $CB->author_tree( $AuthName );
27my $ModName = TEST_CONF_MODULE;
28my $Mod = $CB->module_tree( $ModName );
29my $CoreName = TEST_CONF_PREREQ;
30my $CoreMod = $CB->module_tree( $CoreName );
31
32isa_ok( $Auth, 'CPANPLUS::Module::Author' );
33isa_ok( $Mod, 'CPANPLUS::Module' );
34isa_ok( $CoreMod, 'CPANPLUS::Module' );
35
36### author accessors ###
37is( $Auth->author, 'ExtUtils::MakeMaker No XS Code',
38 "Author name: " . $Auth->author );
39is( $Auth->cpanid, $AuthName, "Author CPANID: " . $Auth->cpanid );
40is( $Auth->email, DEFAULT_EMAIL,"Author email: " . $Auth->email );
41isa_ok( $Auth->parent, 'CPANPLUS::Backend' );
42
43### module accessors ###
44{ my %map = (
45 ### method ### result
46 module => $ModName,
47 name => $ModName,
48 comment => undef,
49 package => 'Foo-Bar-0.01.tar.gz',
50 path => 'authors/id/E/EU/EUNOXS',
51 version => '0.01',
52 dslip => 'cdpO ',
53 description => 'CPANPLUS Test Package',
54 mtime => '',
55 author => $Auth,
56 );
57
58 my @acc = $Mod->accessors;
59 ok( scalar(@acc), "Retrieved module accessors" );
60
61 ### remove private accessors
62 is_deeply( [ sort keys %map ], [ sort grep { $_ !~ /^_/ } @acc ],
63 " About to test all accessors" );
64
65 ### check all the accessors
66 while( my($meth,$res) = each %map ) {
67 is( $Mod->$meth, $res, " Mod->$meth: " . ($res || '<empty>') );
68 }
69
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,
74 "Module eq Author" );
75}
76
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");
85}
86
87### clone & status tests
88{ my $clone = $Mod->clone;
89 ok( $clone, "Module cloned" );
90 isa_ok( $clone, 'CPANPLUS::Module' );
91
92 for my $acc ( $Mod->accessors ) {
93 is( $clone->$acc, $Mod->$acc,
94 " Clone->$acc matches Mod->$acc " );
95 }
96
97 ### XXX whitebox test
98 ok( !$clone->_status, "Status object empty on start" );
99
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' );
105}
106
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" );
111}
112
113{ ### fetch tests ###
114 ### enable signature checks for checksums ###
115 my $old = $Conf->get_conf('signature');
116 $Conf->set_conf(signature => 1);
117
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" );
122
123 $Conf->set_conf( signature => $old );
124}
125
126{ ### extract tests ###
127 my $dir = $Mod->extract( force => 1 );
128 ok( $dir, "Module extracted" );
129 ok( -d $dir, " Dir exsits" );
130}
131
132
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" );
138}
139
140{ ### checksums tests ###
141 SKIP: {
142 skip(q[You chose not to enable checksum verification], 5)
143 unless $Conf->get_conf('md5');
144
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" );
151
152 ### XXX test checksum_value if there's digest::md5 + config wants it
153 ok( $Mod->status->checksum_ok,
154 " Checksum is ok" );
155 }
156}
157
158
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" );
164}
165
166{ ### check signature tests ###
167 SKIP: {
168 skip(q[You chose not to enable signature checks], 1)
169 unless $Conf->get_conf('signature');
170
171 ok( $Mod->check_signature,
172 "Signature check OK" );
173 }
174}
175
176{ ### details() test ###
177 my $href = {
178 'Support Level' => 'Developer',
179 'Package' => $Mod->package,
180 'Description' => $Mod->description,
181 'Development Stage' =>
182 'under construction but pre-alpha (not yet released)',
183 'Author' => sprintf("%s (%s)", $Auth->author, $Auth->email),
184 'Version on CPAN' => $Mod->version,
185 'Language Used' =>
186 'Perl-only, no compiler needed, should be platform independent',
187 'Interface Style' =>
188 'Object oriented using blessed references and/or inheritance',
189 'Public License' => 'Unknown',
190 ### XXX we can't really know what you have installed ###
191 #'Version Installed' => '0.06',
192 };
193
194 my $res = $Mod->details;
195
196 ### delete they key of which we don't know the value ###
197 delete $res->{'Version Installed'};
198
199 is_deeply( $res, $href, "Details OK" );
200}
201
202{ ### contians() test ###
203 ### XXX ->contains works based on package name. in our sourcefiles
204 ### we use 4x the same package name for different modules. So use
205 ### the only unique package name here, which is the one for the core mod
206 my @list = $CoreMod->contains;
207
208 ok( scalar(@list), "Found modules contained in this one" );
209 is_deeply( \@list, [$CoreMod],
210 " Found all modules expected" );
211}
212
213{ ### testing distributions() ###
214 my @mdists = $Mod->distributions;
215 is( scalar @mdists, 1, "Distributions found via module" );
216
217 my @adists = $Auth->distributions;
218 is( scalar @adists, 3, "Distributions found via author" );
219}
220
221{ ### test status->flush ###
222 ok( $Mod->status->mk_flush,
223 "Status flushed" );
224 ok(!$Mod->status->fetch," Fetch status empty" );
225 ok(!$Mod->status->extract,
226 " Extract status empty" );
227 ok(!$Mod->status->checksums,
228 " Checksums status empty" );
229 ok(!$Mod->status->readme,
230 " Readme status empty" );
231}
232
233{ ### testing bundles ###
234 my $bundle = $CB->module_tree('Bundle::Foo::Bar');
235 isa_ok( $bundle, 'CPANPLUS::Module' );
236
237 ok( $bundle->is_bundle, " It's a Bundle:: module" );
238 ok( $bundle->fetch, " Fetched the bundle" );
239 ok( $bundle->extract, " Extracted the bundle" );
240
241 my @objs = $bundle->bundle_modules;
242 is( scalar(@objs), 5, " Found all prerequisites" );
243
244 for( @objs ) {
245 isa_ok( $_, 'CPANPLUS::Module',
246 " Prereq " . $_->module );
247 ok( defined $bundle->status->prereqs->{$_->module},
248 " Prereq was registered" );
249 }
250}
251
252### test module from perl core ###
253{ isa_ok( $CoreMod, 'CPANPLUS::Module',
254 "Core module " . $CoreName );
255 ok( $CoreMod->package_is_perl_core,
256 " Package found in perl core" );
257
258 ### check if it's core with 5.6.1
259 { local $] = '5.006001';
260 ok( $CoreMod->module_is_supplied_with_perl_core,
261 " Module also found in perl core");
262 }
263
264 ok( !$CoreMod->install, " Package not installed" );
265 like( CPANPLUS::Error->stack_as_string, qr/core Perl/,
266 " Error properly logged" );
267}
268
269### test third-party modules
270SKIP: {
271 skip "Module::ThirdParty not installed", 10
272 unless eval { require Module::ThirdParty; 1 };
273
274 ok( !$Mod->is_third_party,
275 "Not a 3rd party module: ". $Mod->name );
276
277 my $fake = $CB->parse_module( module => 'LOCAL/SVN-Core-1.0' );
278 ok( $fake, "Created module object for ". $fake->name );
279 ok( $fake->is_third_party,
280 " It is a 3rd party module" );
281
282 my $info = $fake->third_party_information;
283 ok( $info, "Got 3rd party package information" );
284 isa_ok( $info, 'HASH' );
285
286 for my $item ( qw[name url author author_url] ) {
287 ok( length($info->{$item}),
288 " $item field is filled" );
289 }
290}
291
292### testing EU::Installed methods in Dist::MM tests ###
293
294# Local variables:
295# c-indentation-style: bsd
296# c-basic-offset: 4
297# indent-tabs-mode: nil
298# End:
299# vim: expandtab shiftwidth=4: