1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
10 use CPANPLUS::Internals::Constants;
12 use Test::More 'no_plan';
14 use File::Basename qw[dirname];
16 my $conf = gimme_conf();
17 my $cb = CPANPLUS::Backend->new( $conf );
20 # $conf->set_conf( verbose => 1 );
22 isa_ok($cb, "CPANPLUS::Internals" );
24 my $mt = $cb->_module_tree;
25 my $at = $cb->_author_tree;
26 my $modname = TEST_CONF_MODULE;
28 for my $name (qw[auth mod dslip] ) {
29 my $file = File::Spec->catfile(
30 $conf->get_conf('base'),
31 $conf->_get_source($name)
33 ok( (-e $file && -f _ && -s _), "$file exists" );
36 ok( scalar keys %$at, "Authortree loaded successfully" );
37 ok( scalar keys %$mt, "Moduletree loaded successfully" );
40 { my $auth = $at->{'EUNOXS'};
41 my $mod = $mt->{$modname};
43 isa_ok( $auth, 'CPANPLUS::Module::Author' );
44 isa_ok( $mod, 'CPANPLUS::Module' );
47 ### check custom sources
50 ### first, find a file to serve as a source
51 my $mod = $mt->{$modname};
52 my $package = File::Spec->rel2abs(
61 ok( $package, "Found file for custom source" );
62 ok( -e $package, " File '$package' exists" );
65 my $uri = $cb->_host_to_uri(
68 path => File::Spec->catfile( dirname($package) )
71 my $expected_file = $cb->__custom_module_source_index_file( uri => $uri );
73 ok( $expected_file, "Sources should be written to '$uri'" );
75 skip( "Index file size too long (>260 chars). Can't write to disk", 28 )
76 if length $expected_file > 260 and ON_WIN32;
81 my $src_file = $cb->_add_custom_module_source( uri => $uri );
82 ok( $src_file, "Sources written to '$src_file'" );
83 ok( -e $src_file, " File exists" );
85 ### and write the file
87 { my $meth = '__write_custom_module_index';
91 path => dirname( $package ),
95 ok( $rv, " Sources written" );
96 is( $rv, $src_file, " Written to expected file" );
97 ok( -e $src_file, " Source file exists" );
98 ok( -s $src_file, " File has non-zero size" );
101 ### let's see if we can find our custom files
103 { my $meth = '__list_custom_module_sources';
104 can_ok( $cb, $meth );
106 my %files = $cb->$meth;
107 ok( scalar(keys(%files)),
108 " Got list of sources" );
110 ### on VMS, we can't predict the case unfortunately
111 ### so grep for it instead;
113 my $src_re = quotemeta($src_file);
117 ok( $found, " Found proper entry for $src_file" );
120 ### now we can have it be loaded in
122 { my $meth = '__create_custom_module_entries';
123 can_ok( $cb, $meth );
125 ### now add our own sources
126 ok( $cb->$meth, "Sources file loaded" );
128 my $add_name = TEST_CONF_INST_MODULE;
129 my $add = $mt->{$add_name};
130 ok( $add, " Found added module" );
132 ok( $add->status->_fetch_from,
133 " Full download path set" );
134 is( $add->author->cpanid, CUSTOM_AUTHOR_ID,
135 " Attributed to custom author" );
137 ### since we replaced an existing module, there should be
138 ### a message on the stack
139 like( CPANPLUS::Error->stack_as_string, qr/overwrite module tree/i,
140 " Addition message recorded" );
143 ### test updating custom sources
145 { my $meth = '__update_custom_module_sources';
146 can_ok( $cb, $meth );
148 ### mark what time it is now, sleep 1 second for better measuring
154 ok( $ok, "Custom sources updated" );
155 cmp_ok( [stat $src_file]->[9], '>=', $now,
156 " Timestamp on sourcefile updated" );
159 ### now update it individually
161 { my $meth = '__update_custom_module_source';
162 can_ok( $cb, $meth );
164 ### mark what time it is now, sleep 1 second for better measuring
168 my $ok = $cb->$meth( remote => $uri );
170 ok( $ok, "Custom source for '$uri' updated" );
171 cmp_ok( [stat $src_file]->[9], '>=', $now,
172 " Timestamp on sourcefile updated" );
175 ### now update using the higher level API, see if it's part of the update
177 { CPANPLUS::Error->flush;
179 ### mark what time it is now, sleep 1 second for better measuring
183 my $ok = $cb->_build_trees(
188 ok( $ok, "All sources updated" );
189 cmp_ok( [stat $src_file]->[9], '>=', $now,
190 " Timestamp on sourcefile updated" );
192 like( CPANPLUS::Error->stack_as_string, qr/Updating sources from/,
193 " Update recorded in the log" );
196 ### now remove the index file;
198 { my $meth = '_remove_custom_module_source';
199 can_ok( $cb, $meth );
201 my $file = $cb->$meth( uri => $uri );
202 ok( $file, "Index file removed" );
203 ok( ! -e $file, " File '$file' no longer on disk" );
208 # c-indentation-style: bsd
210 # indent-tabs-mode: nil
212 # vim: expandtab shiftwidth=4: