Update CPANPLUS to 0.83_10
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / t / 03_CPANPLUS-Internals-Source.t
CommitLineData
6aaee015 1### make sure we can find our conf.pl file
2BEGIN {
3 use FindBin;
4 require "$FindBin::Bin/inc/conf.pl";
5}
6
7use strict;
8
9use CPANPLUS::Backend;
5bc5f6dc 10use CPANPLUS::Internals::Constants;
6aaee015 11
12use Test::More 'no_plan';
13use Data::Dumper;
5bc5f6dc 14use File::Basename qw[dirname];
6aaee015 15
16my $conf = gimme_conf();
5bc5f6dc 17my $cb = CPANPLUS::Backend->new( $conf );
18
19### XXX temp
20# $conf->set_conf( verbose => 1 );
6aaee015 21
6aaee015 22isa_ok($cb, "CPANPLUS::Internals" );
23
24my $mt = $cb->_module_tree;
25my $at = $cb->_author_tree;
26my $modname = TEST_CONF_MODULE;
27
28for my $name (qw[auth mod dslip] ) {
29 my $file = File::Spec->catfile(
30 $conf->get_conf('base'),
31 $conf->_get_source($name)
32 );
33 ok( (-e $file && -f _ && -s _), "$file exists" );
34}
35
5bc5f6dc 36ok( scalar keys %$at, "Authortree loaded successfully" );
37ok( scalar keys %$mt, "Moduletree loaded successfully" );
38
39### test lookups
40{ my $auth = $at->{'EUNOXS'};
41 my $mod = $mt->{$modname};
42
43 isa_ok( $auth, 'CPANPLUS::Module::Author' );
44 isa_ok( $mod, 'CPANPLUS::Module' );
45}
46
47### check custom sources
48### XXX whitebox test
0fe18d46 49SKIP: {
50 ### first, find a file to serve as a source
5bc5f6dc 51 my $mod = $mt->{$modname};
52 my $package = File::Spec->rel2abs(
53 File::Spec->catfile(
54 $FindBin::Bin,
55 TEST_CONF_CPAN_DIR,
56 $mod->path,
57 $mod->package,
58 )
59 );
60
61 ok( $package, "Found file for custom source" );
62 ok( -e $package, " File '$package' exists" );
63
64 ### remote uri
65 my $uri = $cb->_host_to_uri(
66 scheme => 'file',
67 host => '',
68 path => File::Spec->catfile( dirname($package) )
69 );
70
0fe18d46 71 my $expected_file = $cb->__custom_module_source_index_file( uri => $uri );
72
73 ok( $expected_file, "Sources should be written to '$uri'" );
74
75 skip( "Index file size too long (>260 chars). Can't write to disk", 28 )
76 if length $expected_file > 260 and ON_WIN32;
77
78
79 ### local file
80 ### 2 tests
5bc5f6dc 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" );
84
0fe18d46 85 ### and write the file
86 ### 5 tests
5bc5f6dc 87 { my $meth = '__write_custom_module_index';
88 can_ok( $cb, $meth );
89
90 my $rv = $cb->$meth(
91 path => dirname( $package ),
92 to => $src_file
93 );
94
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" );
99 }
100
101 ### let's see if we can find our custom files
0fe18d46 102 ### 3 tests
5bc5f6dc 103 { my $meth = '__list_custom_module_sources';
104 can_ok( $cb, $meth );
105
106 my %files = $cb->$meth;
107 ok( scalar(keys(%files)),
108 " Got list of sources" );
5879cbe1 109
110 ### on VMS, we can't predict the case unfortunately
111 ### so grep for it instead;
112 my $found = map {
113 my $src_re = quotemeta($src_file);
114 $_ =~ /$src_re/i;
115 } keys %files;
116
117 ok( $found, " Found proper entry for $src_file" );
5bc5f6dc 118 }
119
120 ### now we can have it be loaded in
0fe18d46 121 ### 6 tests
5bc5f6dc 122 { my $meth = '__create_custom_module_entries';
123 can_ok( $cb, $meth );
6aaee015 124
5bc5f6dc 125 ### now add our own sources
126 ok( $cb->$meth, "Sources file loaded" );
6aaee015 127
5bc5f6dc 128 my $add_name = TEST_CONF_INST_MODULE;
129 my $add = $mt->{$add_name};
130 ok( $add, " Found added module" );
131
132 ok( $add->status->_fetch_from,
133 " Full download path set" );
134 is( $add->author->cpanid, CUSTOM_AUTHOR_ID,
135 " Attributed to custom author" );
136
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" );
141 }
142
143 ### test updating custom sources
0fe18d46 144 ### 3 tests
5bc5f6dc 145 { my $meth = '__update_custom_module_sources';
146 can_ok( $cb, $meth );
147
148 ### mark what time it is now, sleep 1 second for better measuring
149 my $now = time;
150 sleep 1;
151
152 my $ok = $cb->$meth;
153
154 ok( $ok, "Custom sources updated" );
155 cmp_ok( [stat $src_file]->[9], '>=', $now,
156 " Timestamp on sourcefile updated" );
157 }
158
159 ### now update it individually
0fe18d46 160 ### 3 tests
5bc5f6dc 161 { my $meth = '__update_custom_module_source';
162 can_ok( $cb, $meth );
163
164 ### mark what time it is now, sleep 1 second for better measuring
165 my $now = time;
166 sleep 1;
167
168 my $ok = $cb->$meth( remote => $uri );
169
170 ok( $ok, "Custom source for '$uri' updated" );
171 cmp_ok( [stat $src_file]->[9], '>=', $now,
172 " Timestamp on sourcefile updated" );
173 }
174
175 ### now update using the higher level API, see if it's part of the update
0fe18d46 176 ### 3 tests
5bc5f6dc 177 { CPANPLUS::Error->flush;
178
179 ### mark what time it is now, sleep 1 second for better measuring
180 my $now = time;
181 sleep 1;
182
183 my $ok = $cb->_build_trees(
184 uptodate => 0,
185 use_stored => 0,
186 );
187
188 ok( $ok, "All sources updated" );
189 cmp_ok( [stat $src_file]->[9], '>=', $now,
190 " Timestamp on sourcefile updated" );
191
192 like( CPANPLUS::Error->stack_as_string, qr/Updating sources from/,
193 " Update recorded in the log" );
194 }
195
196 ### now remove the index file;
0fe18d46 197 ### 3 tests
5bc5f6dc 198 { my $meth = '_remove_custom_module_source';
199 can_ok( $cb, $meth );
200
201 my $file = $cb->$meth( uri => $uri );
202 ok( $file, "Index file removed" );
203 ok( ! -e $file, " File '$file' no longer on disk" );
204 }
205}
6aaee015 206
207# Local variables:
208# c-indentation-style: bsd
209# c-basic-offset: 4
210# indent-tabs-mode: nil
211# End:
212# vim: expandtab shiftwidth=4: