Commit | Line | Data |
6aaee015 |
1 | ### make sure we can find our conf.pl file |
2 | BEGIN { |
3 | use FindBin; |
4 | require "$FindBin::Bin/inc/conf.pl"; |
5 | } |
6 | |
7 | use strict; |
8 | |
9 | use CPANPLUS::Configure; |
10 | use CPANPLUS::Backend; |
11 | use CPANPLUS::Module::Fake; |
12 | use CPANPLUS::Module::Author::Fake; |
13 | use CPANPLUS::Internals::Constants; |
14 | |
15 | use Test::More 'no_plan'; |
16 | use Data::Dumper; |
17 | use File::Path (); |
18 | |
6aaee015 |
19 | my $Conf = gimme_conf(); |
20 | my $CB = CPANPLUS::Backend->new( $Conf ); |
21 | |
22 | ### start with fresh sources ### |
23 | ok( $CB->reload_indices( update_source => 0 ), "Rebuilding trees" ); |
24 | |
5879cbe1 |
25 | my $AuthName = TEST_CONF_AUTHOR; |
6aaee015 |
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 ); |
31 | |
32 | isa_ok( $Auth, 'CPANPLUS::Module::Author' ); |
33 | isa_ok( $Mod, 'CPANPLUS::Module' ); |
34 | isa_ok( $CoreMod, 'CPANPLUS::Module' ); |
35 | |
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' ); |
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', |
5bc5f6dc |
50 | path => 'authors/id/EUNOXS', |
6aaee015 |
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" ); |
5bc5f6dc |
79 | is( $Mod->package_name, 'Foo-Bar', " Package name"); |
6aaee015 |
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 | |
5879cbe1 |
176 | ### dslip & related |
177 | { my $dslip = $Mod->dslip; |
178 | ok( $dslip, "Got dslip information from $ModName ($dslip)" ); |
179 | |
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" ); |
186 | } |
187 | } |
188 | |
6aaee015 |
189 | { ### details() test ### |
190 | my $href = { |
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, |
198 | 'Language Used' => |
199 | 'Perl-only, no compiler needed, should be platform independent', |
200 | 'Interface Style' => |
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', |
205 | }; |
206 | |
207 | my $res = $Mod->details; |
208 | |
209 | ### delete they key of which we don't know the value ### |
210 | delete $res->{'Version Installed'}; |
211 | |
212 | is_deeply( $res, $href, "Details OK" ); |
213 | } |
214 | |
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; |
220 | |
221 | ok( scalar(@list), "Found modules contained in this one" ); |
222 | is_deeply( \@list, [$CoreMod], |
223 | " Found all modules expected" ); |
224 | } |
225 | |
226 | { ### testing distributions() ### |
227 | my @mdists = $Mod->distributions; |
228 | is( scalar @mdists, 1, "Distributions found via module" ); |
229 | |
230 | my @adists = $Auth->distributions; |
231 | is( scalar @adists, 3, "Distributions found via author" ); |
232 | } |
233 | |
234 | { ### test status->flush ### |
235 | ok( $Mod->status->mk_flush, |
236 | "Status flushed" ); |
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" ); |
244 | } |
245 | |
246 | { ### testing bundles ### |
247 | my $bundle = $CB->module_tree('Bundle::Foo::Bar'); |
248 | isa_ok( $bundle, 'CPANPLUS::Module' ); |
249 | |
250 | ok( $bundle->is_bundle, " It's a Bundle:: module" ); |
251 | ok( $bundle->fetch, " Fetched the bundle" ); |
252 | ok( $bundle->extract, " Extracted the bundle" ); |
253 | |
254 | my @objs = $bundle->bundle_modules; |
255 | is( scalar(@objs), 5, " Found all prerequisites" ); |
256 | |
257 | for( @objs ) { |
258 | isa_ok( $_, 'CPANPLUS::Module', |
259 | " Prereq " . $_->module ); |
260 | ok( defined $bundle->status->prereqs->{$_->module}, |
261 | " Prereq was registered" ); |
262 | } |
263 | } |
264 | |
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" ); |
270 | |
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"); |
275 | } |
276 | |
277 | ok( !$CoreMod->install, " Package not installed" ); |
278 | like( CPANPLUS::Error->stack_as_string, qr/core Perl/, |
279 | " Error properly logged" ); |
280 | } |
281 | |
282 | ### test third-party modules |
283 | SKIP: { |
284 | skip "Module::ThirdParty not installed", 10 |
285 | unless eval { require Module::ThirdParty; 1 }; |
286 | |
287 | ok( !$Mod->is_third_party, |
288 | "Not a 3rd party module: ". $Mod->name ); |
289 | |
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" ); |
294 | |
295 | my $info = $fake->third_party_information; |
296 | ok( $info, "Got 3rd party package information" ); |
297 | isa_ok( $info, 'HASH' ); |
298 | |
299 | for my $item ( qw[name url author author_url] ) { |
300 | ok( length($info->{$item}), |
301 | " $item field is filled" ); |
302 | } |
303 | } |
304 | |
305 | ### testing EU::Installed methods in Dist::MM tests ### |
306 | |
307 | # Local variables: |
308 | # c-indentation-style: bsd |
309 | # c-basic-offset: 4 |
310 | # indent-tabs-mode: nil |
311 | # End: |
312 | # vim: expandtab shiftwidth=4: |