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 | use Test::More 'no_plan'; |
9 | use File::Basename 'dirname'; |
10 | |
11 | use Data::Dumper; |
12 | use CPANPLUS::Error; |
13 | use CPANPLUS::Internals::Constants; |
14 | |
15 | my $conf = gimme_conf(); |
16 | |
6aaee015 |
17 | my $Class = 'CPANPLUS::Backend'; |
18 | ### D::C has troubles with the 'use_ok' -- it finds the wrong paths. |
19 | ### for now, do a 'use' instead |
20 | #use_ok( $Class ) or diag "$Class not found"; |
21 | use CPANPLUS::Backend; |
22 | |
23 | my $cb = $Class->new( $conf ); |
24 | isa_ok( $cb, $Class ); |
25 | |
26 | my $mt = $cb->module_tree; |
27 | my $at = $cb->author_tree; |
28 | ok( scalar keys %$mt, "Module tree has entries" ); |
29 | ok( scalar keys %$at, "Author tree has entries" ); |
30 | |
31 | ### module_tree tests ### |
32 | my $Name = TEST_CONF_MODULE; |
33 | my $mod = $cb->module_tree($Name); |
34 | |
35 | ### XXX SOURCEFILES FIX |
36 | { my @mods = $cb->module_tree($Name,$Name); |
37 | my $none = $cb->module_tree( TEST_CONF_INVALID_MODULE ); |
38 | |
39 | ok( IS_MODOBJ->(mod => $mod), "Module object found" ); |
40 | is( scalar(@mods), 2, " Module list found" ); |
41 | ok( IS_MODOBJ->(mod => $mods[0]), " ISA module object" ); |
42 | ok( !IS_MODOBJ->(mod => $none), " Bogus module detected"); |
43 | } |
44 | |
45 | ### author_tree tests ### |
46 | { my @auths = $cb->author_tree( $mod->author->cpanid, |
47 | $mod->author->cpanid ); |
48 | my $none = $cb->author_tree( 'fnurk' ); |
49 | |
50 | ok( IS_AUTHOBJ->(auth => $mod->author), "Author object found" ); |
51 | is( scalar(@auths), 2, " Author list found" ); |
52 | ok( IS_AUTHOBJ->( author => $auths[0] )," ISA author object" ); |
53 | is( $mod->author, $auths[0], " Objects are identical" ); |
54 | ok( !IS_AUTHOBJ->( author => $none ), " Bogus author detected" ); |
55 | } |
56 | |
57 | my $conf_obj = $cb->configure_object; |
58 | ok( IS_CONFOBJ->(conf => $conf_obj), "Configure object found" ); |
59 | |
60 | |
61 | ### parse_module tests ### |
62 | { my @map = ( # author package version |
63 | $Name => [ $mod->author->cpanid, $mod->package_name, $mod->version ], |
64 | $mod => [ $mod->author->cpanid, $mod->package_name, $mod->version ], |
65 | 'Foo-Bar-EU-NOXS' |
66 | => [ $mod->author->cpanid, $mod->package_name, $mod->version ], |
67 | 'Foo-Bar-EU-NOXS-0.01' |
68 | => [ $mod->author->cpanid, $mod->package_name, '0.01' ], |
69 | 'EUNOXS/Foo-Bar-EU-NOXS' |
70 | => [ 'EUNOXS', $mod->package_name, $mod->version ], |
71 | 'EUNOXS/Foo-Bar-EU-NOXS-0.01' |
72 | => [ 'EUNOXS', $mod->package_name, '0.01' ], |
73 | 'Foo-Bar-EU-NOXS-0.09' |
74 | => [ $mod->author->cpanid, $mod->package_name, '0.09' ], |
75 | 'MBXS/Foo-Bar-EU-NOXS-0.01' |
76 | => [ 'MBXS', $mod->package_name, '0.01' ], |
77 | 'EUNOXS/Foo-Bar-EU-NOXS-0.09' |
78 | => [ 'EUNOXS', $mod->package_name, '0.09' ], |
79 | 'EUNOXS/Foo-Bar-EU-NOXS-0.09.zip' |
80 | => [ 'EUNOXS', $mod->package_name, '0.09' ], |
81 | 'FROO/Flub-Flob-1.1.zip' |
82 | => [ 'FROO', 'Flub-Flob', '1.1' ], |
83 | 'G/GO/GOYALI/SMS_API_3_01.tar.gz' |
84 | => [ 'GOYALI', 'SMS_API', '3_01' ], |
85 | 'E/EY/EYCK/Net/Lite/Net-Lite-FTP-0.091' |
86 | => [ 'EYCK', 'Net-Lite-FTP', '0.091' ], |
87 | 'EYCK/Net/Lite/Net-Lite-FTP-0.091' |
88 | => [ 'EYCK', 'Net-Lite-FTP', '0.091' ], |
89 | 'M/MA/MAXDB/DBD-MaxDB-7.5.00.24a' |
90 | => [ 'MAXDB', 'DBD-MaxDB', '7.5.00.24a' ], |
91 | 'EUNOXS/perl5.005_03.tar.gz' |
92 | => [ 'EUNOXS', 'perl', '5.005_03' ], |
93 | 'FROO/Flub-Flob-v1.1.0.tbz' |
94 | => [ 'FROO', 'Flub-Flob', 'v1.1.0' ], |
95 | 'FROO/Flub-Flob-1.1_2.tbz' |
96 | => [ 'FROO', 'Flub-Flob', '1.1_2' ], |
97 | 'LDS/CGI.pm-3.27.tar.gz' |
98 | => [ 'LDS', 'CGI', '3.27' ], |
99 | 'FROO/Text-Tabs+Wrap-2006.1117.tar.gz' |
100 | => [ 'FROO', 'Text-Tabs+Wrap', '2006.1117' ], |
101 | 'JETTERO/Crypt-PBC-0.7.20.0-0.4.9', |
102 | => [ 'JETTERO', 'Crypt-PBC', '0.7.20.0-0.4.9' ], |
103 | |
104 | ); |
105 | |
106 | while ( my($guess, $attr) = splice @map, 0, 2 ) { |
107 | my( $author, $pkg, $version ) = @$attr; |
108 | |
109 | ok( $guess, "Attempting to parse $guess" ); |
110 | |
111 | my $obj = $cb->parse_module( module => $guess ); |
112 | |
113 | ok( $obj, " Result returned" ); |
114 | ok( IS_MODOBJ->( mod => $obj ), |
115 | " parse_module success by '$guess'" ); |
116 | |
117 | is( $obj->version, $version, |
118 | " Proper version found: $version" ); |
119 | is( $obj->package_version, $version, |
120 | " Found in package_version as well" ); |
121 | is( $obj->package_name, $pkg, |
122 | " Proper package found: $pkg" ); |
123 | unlike( $obj->package_name, qr/\d/, |
124 | " No digits in package name" ); |
125 | like( $obj->author->cpanid, "/$author/i", |
126 | " Proper author found: $author"); |
127 | like( $obj->path, "/$author/i", |
128 | " Proper path found: " . $obj->path ); |
129 | } |
130 | |
131 | |
132 | ### test for things that look like real modules, but aren't ### |
983ffab6 |
133 | { my @map = ( |
6aaee015 |
134 | [ $Name . $$ => [ |
135 | [qr/does not contain an author/,"Missing author part detected"], |
136 | [qr/Cannot find .+? in the module tree/,"Unable to find module"] |
137 | ] ], |
138 | [ {}, => [ |
139 | [ qr/module string from reference/,"Unable to parse ref"] |
140 | ] ], |
141 | ); |
142 | |
143 | for my $entry ( @map ) { |
144 | my($mod,$aref) = @$entry; |
145 | |
146 | my $none = $cb->parse_module( module => $mod ); |
147 | ok( !IS_MODOBJ->(mod => $none), |
148 | "Non-existant module detected" ); |
149 | ok( !IS_FAKE_MODOBJ->(mod => $none), |
150 | "Non-existant fake module detected" ); |
151 | |
152 | my $str = CPANPLUS::Error->stack_as_string; |
153 | for my $pair (@$aref) { |
154 | my($re,$diag) = @$pair; |
155 | like( $str, $re," $diag" ); |
156 | } |
157 | } |
158 | } |
159 | |
160 | ### test parsing of arbitrary URI |
161 | for my $guess ( qw[ http://foo/bar.gz |
162 | http://a/b/c/d/e/f/g/h/i/j |
163 | flub://floo ] |
164 | ) { |
165 | my $obj = $cb->parse_module( module => $guess ); |
5bc5f6dc |
166 | ok( IS_FAKE_MODOBJ->(mod => $obj), |
167 | "parse_module success by '$guess'" ); |
6aaee015 |
168 | is( $obj->status->_fetch_from, $guess, |
5bc5f6dc |
169 | " Fetch from set ok" ); |
6aaee015 |
170 | } |
171 | } |
172 | |
173 | ### RV tests ### |
174 | { my $method = 'readme'; |
175 | my %args = ( modules => [$Name] ); |
176 | |
177 | my $rv = $cb->$method( %args ); |
178 | ok( IS_RVOBJ->( $rv ), "Got an RV object" ); |
179 | ok( $rv->ok, " Overall OK" ); |
180 | cmp_ok( $rv, '==', 1, " Overload OK" ); |
181 | is( $rv->function, $method, " Function stored OK" ); |
182 | is_deeply( $rv->args, \%args, " Arguments stored OK" ); |
183 | is( $rv->rv->{$Name}, $mod->readme, " RV as expected" ); |
184 | } |
185 | |
186 | ### reload_indices tests ### |
187 | { |
188 | my $file = File::Spec->catfile( $conf->get_conf('base'), |
189 | $conf->_get_source('mod'), |
190 | ); |
191 | |
192 | ok( $cb->reload_indices( update_source => 0 ), "Rebuilding trees" ); |
193 | my $age = -M $file; |
194 | |
195 | ### make sure we are 'newer' on faster machines with a sleep.. |
196 | ### apparently Win32's FAT isn't granual enough on intervals |
197 | ### < 2 seconds, so it may give the same answer before and after |
198 | ### the sleep, causing the test to fail. so sleep atleast 2 seconds. |
199 | sleep 2; |
200 | ok( $cb->reload_indices( update_source => 1 ), |
201 | "Rebuilding and refetching trees" ); |
202 | cmp_ok( $age, '>', -M $file, " Source file '$file' updated" ); |
203 | } |
204 | |
205 | ### flush tests ### |
206 | { |
207 | for my $cache( qw[methods hosts modules lib all] ) { |
208 | ok( $cb->flush($cache), "Cache $cache flushed ok" ); |
209 | } |
210 | } |
211 | |
212 | ### installed tests ### |
5bc5f6dc |
213 | { ok( scalar($cb->installed), "Found list of installed modules" ); |
6aaee015 |
214 | } |
215 | |
216 | ### autobudle tests ### |
217 | { |
218 | my $where = $cb->autobundle; |
219 | ok( $where, "Autobundle written" ); |
220 | ok( -s $where, " File has size" ); |
221 | } |
222 | |
223 | ### local_mirror tests ### |
224 | { ### turn off md5 checks for the 'fake' packages we have |
225 | my $old_md5 = $conf->get_conf('md5'); |
226 | $conf->set_conf( md5 => 0 ); |
227 | |
228 | ### otherwise 'status->fetch' might be undef! ### |
229 | my $rv = $cb->local_mirror( path => 'dummy-localmirror' ); |
230 | ok( $rv, "Local mirror created" ); |
231 | |
232 | for my $mod ( values %{ $cb->module_tree } ) { |
233 | my $name = $mod->module; |
234 | |
235 | my $cksum = File::Spec->catfile( |
236 | dirname($mod->status->fetch), |
237 | CHECKSUMS ); |
238 | ok( -e $mod->status->fetch, " Module '$name' fetched" ); |
239 | ok( -s _, " Module '$name' has size" ); |
240 | ok( -e $cksum, " Checksum fetched for '$name'" ); |
241 | ok( -s _, " Checksum for '$name' has size" ); |
242 | } |
243 | |
244 | $conf->set_conf( md5 => $old_md5 ); |
245 | } |
246 | |
247 | ### check ENV variable |
248 | { ### process id |
249 | { my $name = 'PERL5_CPANPLUS_IS_RUNNING'; |
250 | ok( $ENV{$name}, "Env var '$name' set" ); |
251 | is( $ENV{$name}, $$, " Set to current process id" ); |
252 | } |
253 | |
254 | ### Version |
255 | { my $name = 'PERL5_CPANPLUS_IS_VERSION'; |
256 | ok( $ENV{$name}, "Env var '$name' set" ); |
257 | |
258 | ### version.pm formats ->VERSION output... *sigh* |
259 | is( $ENV{$name}, $Class->VERSION, |
260 | " Set to current process version" ); |
261 | } |
262 | |
263 | } |
264 | |
265 | __END__ |
266 | |
267 | # Local variables: |
268 | # c-indentation-style: bsd |
269 | # c-basic-offset: 4 |
270 | # indent-tabs-mode: nil |
271 | # End: |
272 | # vim: expandtab shiftwidth=4: |
273 | |