1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
### make sure we can find our conf.pl file
BEGIN {
use FindBin;
require "$FindBin::Bin/inc/conf.pl";
}
use strict;
use Module::Load;
use Test::More eval {
load $ENV{CPANPLUS_SOURCE_ENGINE} if $ENV{CPANPLUS_SOURCE_ENGINE}; 1
} ? 'no_plan'
: (skip_all => "SQLite engine not available");
use CPANPLUS::Error;
use CPANPLUS::Backend;
use CPANPLUS::Internals::Constants;
use Data::Dumper;
use File::Basename qw[dirname];
my $conf = gimme_conf();
$conf->set_conf( enable_custom_sources => 1 );
my $cb = CPANPLUS::Backend->new( $conf );
### XXX temp
# $conf->set_conf( verbose => 1 );
isa_ok($cb, "CPANPLUS::Internals" );
my $modname = TEST_CONF_MODULE;
### test lookups
{ my $mt = $cb->_module_tree;
my $at = $cb->_author_tree;
### source files should be copied from the 'server' now
for my $name (qw[auth mod] ) {
my $file = File::Spec->catfile(
$conf->get_conf('base'),
$conf->_get_source($name)
);
ok( (-e $file && -f _ && -s _), "$file exists" );
}
ok( $at, "Authortree loaded successfully" );
ok( scalar keys %$at, " Authortree has items in it" );
ok( $mt, "Moduletree loaded successfully" );
ok( scalar keys %$mt, " Moduletree has items in it" );
my $auth = $at->{'EUNOXS'};
my $mod = $mt->{$modname};
isa_ok( $auth, 'CPANPLUS::Module::Author' );
isa_ok( $mod, 'CPANPLUS::Module' );
}
### save state tests
SKIP: {
skip "Save state tests for custom engine $ENV{CPANPLUS_SOURCE_ENGINE}", 7
if $ENV{CPANPLUS_SOURCE_ENGINE};
ok( 1, "Testing save state functionality" );
### check we dont have a status set yet
{ my $mod = $cb->_module_tree->{$modname};
ok( !$mod->_status, " No status set yet in module object" );
ok( $mod->status, " Status now set" );
}
### now save this to disk
{ CPANPLUS::Error->flush;
my $rv = $cb->save_state;
ok( $rv, " State information saved" );
like( CPANPLUS::Error->stack_as_string, qr/Writing compiled source/,
" Diagnostics confirmed" );
}
### now we rebuild the trees from disk and
### check if the module object has a status saved with it
{ CPANPLUS::Error->flush;
ok( $cb->_build_trees( uptodate => 1, use_stored => 1),
" Trees are rebuilt" );
like( CPANPLUS::Error->stack_as_string, qr/Retrieving/,
" Diagnostics confirmed" );
my $mod = $cb->_module_tree->{$modname};
ok( $mod->status, " Status now set in module object" );
}
}
### check custom sources
### XXX whitebox test
SKIP: {
### first, find a file to serve as a source
my $mod = $cb->_module_tree->{$modname};
my $package = File::Spec->rel2abs(
File::Spec->catfile(
$FindBin::Bin,
TEST_CONF_CPAN_DIR,
$mod->path,
$mod->package,
)
);
ok( $package, "Found file for custom source" );
ok( -e $package, " File '$package' exists" );
### remote uri
my $uri = $cb->_host_to_uri(
scheme => 'file',
host => '',
path => File::Spec->catfile( dirname($package) )
);
my $expected_file = $cb->__custom_module_source_index_file( uri => $uri );
ok( $expected_file, "Sources should be written to '$uri'" );
skip( "Index file size too long (>260 chars). Can't write to disk", 28 )
if length $expected_file > 260 and ON_WIN32;
skip( "MINIX file system has a 60 char limit on filenames", 28 )
if length $expected_file > 60 and ON_MINIX;
### local file
### 2 tests
my $src_file = $cb->_add_custom_module_source( uri => $uri );
ok( $src_file, "Sources written to '$src_file'" );
ok( -e $src_file, " File exists" );
### and write the file
### 5 tests
{ my $meth = '__write_custom_module_index';
can_ok( $cb, $meth );
my $rv = $cb->$meth(
path => dirname( $package ),
to => $src_file
);
ok( $rv, " Sources written" );
is( $rv, $src_file, " Written to expected file" );
ok( -e $src_file, " Source file exists" );
ok( -s $src_file, " File has non-zero size" );
}
### let's see if we can find our custom files
### 3 tests
{ my $meth = '__list_custom_module_sources';
can_ok( $cb, $meth );
my %files = $cb->$meth;
ok( scalar(keys(%files)),
" Got list of sources" );
### on VMS, we can't predict the case unfortunately
### so grep for it instead;
my $found = map {
my $src_re = quotemeta($src_file);
$_ =~ /$src_re/i;
} keys %files;
ok( $found, " Found proper entry for $src_file" );
}
### now we can have it be loaded in
### 6 tests
{ my $meth = '__create_custom_module_entries';
can_ok( $cb, $meth );
### now add our own sources
ok( $cb->$meth, "Sources file loaded" );
my $add_name = TEST_CONF_INST_MODULE;
my $add = $cb->_module_tree->{$add_name};
ok( $add, " Found added module" );
ok( $add->status->_fetch_from,
" Full download path set" );
is( $add->author->cpanid, CUSTOM_AUTHOR_ID,
" Attributed to custom author" );
### since we replaced an existing module, there should be
### a message on the stack
like( CPANPLUS::Error->stack_as_string, qr/overwrite module tree/i,
" Addition message recorded" );
}
### test updating custom sources
### 3 tests
{ my $meth = '__update_custom_module_sources';
can_ok( $cb, $meth );
### mark what time it is now, sleep 1 second for better measuring
my $now = time;
sleep 1;
my $ok = $cb->$meth;
ok( $ok, "Custom sources updated" );
cmp_ok( [stat $src_file]->[9], '>=', $now,
" Timestamp on sourcefile updated" );
}
### now update it individually
### 3 tests
{ my $meth = '__update_custom_module_source';
can_ok( $cb, $meth );
### mark what time it is now, sleep 1 second for better measuring
my $now = time;
sleep 1;
my $ok = $cb->$meth( remote => $uri );
ok( $ok, "Custom source for '$uri' updated" );
cmp_ok( [stat $src_file]->[9], '>=', $now,
" Timestamp on sourcefile updated" );
}
### now update using the higher level API, see if it's part of the update
### 3 tests
{ CPANPLUS::Error->flush;
### mark what time it is now, sleep 1 second for better measuring
my $now = time;
sleep 1;
my $ok = $cb->_build_trees(
uptodate => 0,
use_stored => 0,
);
ok( $ok, "All sources updated" );
cmp_ok( [stat $src_file]->[9], '>=', $now,
" Timestamp on sourcefile updated" );
like( CPANPLUS::Error->stack_as_string, qr/Updating sources from/,
" Update recorded in the log" );
}
### now remove the index file;
### 3 tests
{ my $meth = '_remove_custom_module_source';
can_ok( $cb, $meth );
my $file = $cb->$meth( uri => $uri );
ok( $file, "Index file removed" );
ok( ! -e $file, " File '$file' no longer on disk" );
}
}
# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:
|