1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
11 load $ENV{CPANPLUS_SOURCE_ENGINE} if $ENV{CPANPLUS_SOURCE_ENGINE}; 1
13 : (skip_all => "SQLite engine not available");
16 use CPANPLUS::Backend;
17 use CPANPLUS::Internals::Constants;
20 use File::Basename qw[dirname];
22 my $conf = gimme_conf();
23 my $cb = CPANPLUS::Backend->new( $conf );
26 # $conf->set_conf( verbose => 1 );
28 isa_ok($cb, "CPANPLUS::Internals" );
30 my $modname = TEST_CONF_MODULE;
33 { my $mt = $cb->_module_tree;
34 my $at = $cb->_author_tree;
36 ### source files should be copied from the 'server' now
37 for my $name (qw[auth mod dslip] ) {
38 my $file = File::Spec->catfile(
39 $conf->get_conf('base'),
40 $conf->_get_source($name)
42 ok( (-e $file && -f _ && -s _), "$file exists" );
45 ok( $at, "Authortree loaded successfully" );
46 ok( scalar keys %$at, " Authortree has items in it" );
47 ok( $mt, "Moduletree loaded successfully" );
48 ok( scalar keys %$mt, " Moduletree has items in it" );
50 my $auth = $at->{'EUNOXS'};
51 my $mod = $mt->{$modname};
53 isa_ok( $auth, 'CPANPLUS::Module::Author' );
54 isa_ok( $mod, 'CPANPLUS::Module' );
59 skip "Save state tests for custom engine $ENV{CPANPLUS_SOURCE_ENGINE}", 7
60 if $ENV{CPANPLUS_SOURCE_ENGINE};
62 ok( 1, "Testing save state functionality" );
65 ### check we dont have a status set yet
66 { my $mod = $cb->_module_tree->{$modname};
67 ok( !$mod->_status, " No status set yet in module object" );
68 ok( $mod->status, " Status now set" );
71 ### now save this to disk
72 { CPANPLUS::Error->flush;
74 my $rv = $cb->save_state;
75 ok( $rv, " State information saved" );
77 like( CPANPLUS::Error->stack_as_string, qr/Writing compiled source/,
78 " Diagnostics confirmed" );
81 ### now we rebuild the trees from disk and
82 ### check if the module object has a status saved with it
83 { CPANPLUS::Error->flush;
84 ok( $cb->_build_trees( uptodate => 1, use_stored => 1),
85 " Trees are rebuilt" );
87 like( CPANPLUS::Error->stack_as_string, qr/Retrieving/,
88 " Diagnostics confirmed" );
91 my $mod = $cb->_module_tree->{$modname};
92 ok( $mod->status, " Status now set in module object" );
96 ### check custom sources
99 ### first, find a file to serve as a source
100 my $mod = $cb->_module_tree->{$modname};
101 my $package = File::Spec->rel2abs(
110 ok( $package, "Found file for custom source" );
111 ok( -e $package, " File '$package' exists" );
114 my $uri = $cb->_host_to_uri(
117 path => File::Spec->catfile( dirname($package) )
120 my $expected_file = $cb->__custom_module_source_index_file( uri => $uri );
122 ok( $expected_file, "Sources should be written to '$uri'" );
124 skip( "Index file size too long (>260 chars). Can't write to disk", 28 )
125 if length $expected_file > 260 and ON_WIN32;
130 my $src_file = $cb->_add_custom_module_source( uri => $uri );
131 ok( $src_file, "Sources written to '$src_file'" );
132 ok( -e $src_file, " File exists" );
134 ### and write the file
136 { my $meth = '__write_custom_module_index';
137 can_ok( $cb, $meth );
140 path => dirname( $package ),
144 ok( $rv, " Sources written" );
145 is( $rv, $src_file, " Written to expected file" );
146 ok( -e $src_file, " Source file exists" );
147 ok( -s $src_file, " File has non-zero size" );
150 ### let's see if we can find our custom files
152 { my $meth = '__list_custom_module_sources';
153 can_ok( $cb, $meth );
155 my %files = $cb->$meth;
156 ok( scalar(keys(%files)),
157 " Got list of sources" );
159 ### on VMS, we can't predict the case unfortunately
160 ### so grep for it instead;
162 my $src_re = quotemeta($src_file);
166 ok( $found, " Found proper entry for $src_file" );
169 ### now we can have it be loaded in
171 { my $meth = '__create_custom_module_entries';
172 can_ok( $cb, $meth );
174 ### now add our own sources
175 ok( $cb->$meth, "Sources file loaded" );
177 my $add_name = TEST_CONF_INST_MODULE;
178 my $add = $cb->_module_tree->{$add_name};
179 ok( $add, " Found added module" );
181 ok( $add->status->_fetch_from,
182 " Full download path set" );
183 is( $add->author->cpanid, CUSTOM_AUTHOR_ID,
184 " Attributed to custom author" );
186 ### since we replaced an existing module, there should be
187 ### a message on the stack
188 like( CPANPLUS::Error->stack_as_string, qr/overwrite module tree/i,
189 " Addition message recorded" );
192 ### test updating custom sources
194 { my $meth = '__update_custom_module_sources';
195 can_ok( $cb, $meth );
197 ### mark what time it is now, sleep 1 second for better measuring
203 ok( $ok, "Custom sources updated" );
204 cmp_ok( [stat $src_file]->[9], '>=', $now,
205 " Timestamp on sourcefile updated" );
208 ### now update it individually
210 { my $meth = '__update_custom_module_source';
211 can_ok( $cb, $meth );
213 ### mark what time it is now, sleep 1 second for better measuring
217 my $ok = $cb->$meth( remote => $uri );
219 ok( $ok, "Custom source for '$uri' updated" );
220 cmp_ok( [stat $src_file]->[9], '>=', $now,
221 " Timestamp on sourcefile updated" );
224 ### now update using the higher level API, see if it's part of the update
226 { CPANPLUS::Error->flush;
228 ### mark what time it is now, sleep 1 second for better measuring
232 my $ok = $cb->_build_trees(
237 ok( $ok, "All sources updated" );
238 cmp_ok( [stat $src_file]->[9], '>=', $now,
239 " Timestamp on sourcefile updated" );
241 like( CPANPLUS::Error->stack_as_string, qr/Updating sources from/,
242 " Update recorded in the log" );
245 ### now remove the index file;
247 { my $meth = '_remove_custom_module_source';
248 can_ok( $cb, $meth );
250 my $file = $cb->$meth( uri => $uri );
251 ok( $file, "Index file removed" );
252 ok( ! -e $file, " File '$file' no longer on disk" );
257 # c-indentation-style: bsd
259 # indent-tabs-mode: nil
261 # vim: expandtab shiftwidth=4: