Update CPANPLUS to 0.83_02
[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
49{ ### first, find a file to serve as a source
50 my $mod = $mt->{$modname};
51 my $package = File::Spec->rel2abs(
52 File::Spec->catfile(
53 $FindBin::Bin,
54 TEST_CONF_CPAN_DIR,
55 $mod->path,
56 $mod->package,
57 )
58 );
59
60 ok( $package, "Found file for custom source" );
61 ok( -e $package, " File '$package' exists" );
62
63 ### remote uri
64 my $uri = $cb->_host_to_uri(
65 scheme => 'file',
66 host => '',
67 path => File::Spec->catfile( dirname($package) )
68 );
69
70 ### local file
71 my $src_file = $cb->_add_custom_module_source( uri => $uri );
72 ok( $src_file, "Sources written to '$src_file'" );
73 ok( -e $src_file, " File exists" );
74
75 ### and write the file
76 { my $meth = '__write_custom_module_index';
77 can_ok( $cb, $meth );
78
79 my $rv = $cb->$meth(
80 path => dirname( $package ),
81 to => $src_file
82 );
83
84 ok( $rv, " Sources written" );
85 is( $rv, $src_file, " Written to expected file" );
86 ok( -e $src_file, " Source file exists" );
87 ok( -s $src_file, " File has non-zero size" );
88 }
89
90 ### let's see if we can find our custom files
91 { my $meth = '__list_custom_module_sources';
92 can_ok( $cb, $meth );
93
94 my %files = $cb->$meth;
95 ok( scalar(keys(%files)),
96 " Got list of sources" );
97 ok( $files{ $src_file }," Found proper entry" );
98 }
99
100 ### now we can have it be loaded in
101 { my $meth = '__create_custom_module_entries';
102 can_ok( $cb, $meth );
6aaee015 103
5bc5f6dc 104 ### now add our own sources
105 ok( $cb->$meth, "Sources file loaded" );
6aaee015 106
5bc5f6dc 107 my $add_name = TEST_CONF_INST_MODULE;
108 my $add = $mt->{$add_name};
109 ok( $add, " Found added module" );
110
111 ok( $add->status->_fetch_from,
112 " Full download path set" );
113 is( $add->author->cpanid, CUSTOM_AUTHOR_ID,
114 " Attributed to custom author" );
115
116 ### since we replaced an existing module, there should be
117 ### a message on the stack
118 like( CPANPLUS::Error->stack_as_string, qr/overwrite module tree/i,
119 " Addition message recorded" );
120 }
121
122 ### test updating custom sources
123 { my $meth = '__update_custom_module_sources';
124 can_ok( $cb, $meth );
125
126 ### mark what time it is now, sleep 1 second for better measuring
127 my $now = time;
128 sleep 1;
129
130 my $ok = $cb->$meth;
131
132 ok( $ok, "Custom sources updated" );
133 cmp_ok( [stat $src_file]->[9], '>=', $now,
134 " Timestamp on sourcefile updated" );
135 }
136
137 ### now update it individually
138 { my $meth = '__update_custom_module_source';
139 can_ok( $cb, $meth );
140
141 ### mark what time it is now, sleep 1 second for better measuring
142 my $now = time;
143 sleep 1;
144
145 my $ok = $cb->$meth( remote => $uri );
146
147 ok( $ok, "Custom source for '$uri' updated" );
148 cmp_ok( [stat $src_file]->[9], '>=', $now,
149 " Timestamp on sourcefile updated" );
150 }
151
152 ### now update using the higher level API, see if it's part of the update
153 { CPANPLUS::Error->flush;
154
155 ### mark what time it is now, sleep 1 second for better measuring
156 my $now = time;
157 sleep 1;
158
159 my $ok = $cb->_build_trees(
160 uptodate => 0,
161 use_stored => 0,
162 );
163
164 ok( $ok, "All sources updated" );
165 cmp_ok( [stat $src_file]->[9], '>=', $now,
166 " Timestamp on sourcefile updated" );
167
168 like( CPANPLUS::Error->stack_as_string, qr/Updating sources from/,
169 " Update recorded in the log" );
170 }
171
172 ### now remove the index file;
173 { my $meth = '_remove_custom_module_source';
174 can_ok( $cb, $meth );
175
176 my $file = $cb->$meth( uri => $uri );
177 ok( $file, "Index file removed" );
178 ok( ! -e $file, " File '$file' no longer on disk" );
179 }
180}
6aaee015 181
182# Local variables:
183# c-indentation-style: bsd
184# c-basic-offset: 4
185# indent-tabs-mode: nil
186# End:
187# vim: expandtab shiftwidth=4: