This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: 5.10.0 test hangs on non internet access
[perl5.git] / lib / CPANPLUS / Dist / Build / t / 02_CPANPLUS-Dist-Build.t
CommitLineData
9b4bd854
JB
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;
8use CPANPLUS::Configure;
9use CPANPLUS::Backend;
10use CPANPLUS::Internals::Constants;
11use CPANPLUS::Module::Fake;
12use CPANPLUS::Module::Author::Fake;
13
14use Config;
15use Test::More 'no_plan';
031ea58b 16use File::Basename qw[basename];
9b4bd854
JB
17use Data::Dumper;
18use Config;
19use IPC::Cmd 'can_run';
20
21$SIG{__WARN__} = sub {warn @_ unless @_ && $_[0] =~ /redefined|isn't numeric/};
22
23# Load these two modules in advance, even though they would be
24# auto-loaded, because we want to override some of their subs.
25use ExtUtils::Packlist;
26use ExtUtils::Installed;
27
28my $Class = 'CPANPLUS::Dist::Build';
29my $Utils = 'CPANPLUS::Internals::Utils';
30my $Have_CC = can_run($Config{'cc'} )? 1 : 0;
31
32
33my $Lib = File::Spec->rel2abs(File::Spec->catdir( qw[dummy-perl] ));
34my $Src = File::Spec->rel2abs(File::Spec->catdir( qw[src] ));
35
36my $Verbose = @ARGV ? 1 : 0;
37my $CB = CPANPLUS::Backend->new;
38my $Conf = $CB->configure_object;
39
40
41### create a fake object, so we don't use the actual module tree
6c7ff726
JB
42### make sure to add dslip data, so CPANPLUS doesn't try to find
43### it in another module in the package, for which it needs the
44### module tree
9b4bd854
JB
45my $Mod = CPANPLUS::Module::Fake->new(
46 module => 'Foo::Bar',
47 path => 'src',
48 author => CPANPLUS::Module::Author::Fake->new,
49 package => 'Foo-Bar-0.01.tar.gz',
6c7ff726 50 dslip => 'RdpO?',
9b4bd854
JB
51 );
52
53$Conf->set_conf( base => 'dummy-cpanplus' );
54$Conf->set_conf( dist_type => '' );
55$Conf->set_conf( verbose => $Verbose );
56$Conf->set_conf( signature => 0 );
57### running tests will mess with the test output so skip 'm
58$Conf->set_conf( skiptest => 1 );
59
031ea58b
JB
60### dmq tells us that we should run with /nologo
61### if using nmake, as it's very noise otherwise.
62### XXX copied from CPANPLUS' test include file!
63{ my $make = $Conf->get_program('make');
64 if( $make and basename($make) =~ /^nmake/i and
65 $make !~ m|/nologo|
66 ) {
67 $make .= ' /nologo';
68 $Conf->set_program( make => $make );
69 }
70}
71
72
9b4bd854
JB
73 # path, cc needed?
74my %Map = ( noxs => 0,
75 xs => 1
76 );
77
78
79### Disable certain possible settings, so we dont accidentally
80### touch anything outside our sandbox
81{
82 ### set buildflags to install in our dummy perl dir
83 $Conf->set_conf( buildflags => "install_base=$Lib" );
84
85 ### don't start sending test reports now... ###
86 $CB->_callbacks->send_test_report( sub { 0 } );
87 $Conf->set_conf( cpantest => 0 );
88
89 ### we dont need sudo -- we're installing in our own sandbox now
90 $Conf->set_program( sudo => undef );
91}
92
93use_ok( $Class );
94
95ok( $Class->format_available, "Format is available" );
96
97
98while( my($path,$need_cc) = each %Map ) {
99
100 my $mod = $Mod->clone;
101 ok( $mod, "Module object created for '$path'" );
102
103 ### set the fetch location -- it's local
104 { my $where = File::Spec->rel2abs(
105 File::Spec->catdir( $Src, $path, $mod->package )
106 );
107
108 $mod->status->fetch( $where );
109
110 ok( -e $where, " Tarball '$where' exists" );
111 }
112
113 ok( $mod->prepare, " Preparing module" );
114
115 ok( $mod->status->dist_cpan,
116 " Dist registered as status" );
117
118 isa_ok( $mod->status->dist_cpan, $Class );
119
120 ok( $mod->status->dist_cpan->status->prepared,
121 " Prepared status registered" );
122 is( $mod->status->dist_cpan->status->distdir, $mod->status->extract,
123 " Distdir status registered properly" );
124
125
126 is( $mod->status->installer_type, INSTALLER_BUILD,
127 " Proper installer type found" );
128
129
130 ### we might not have a C compiler
131 SKIP: {
132 skip("The CC compiler listed in Config.pm is not available " .
133 "-- skipping compile tests", 5) if $need_cc && !$Have_CC;
134 skip("Module::Build is not compiled with C support ".
135 "-- skipping compile tests", 5)
136 unless Module::Build->_mb_feature('C_support');
137
138 ok( $mod->create( ), "Creating module" );
139 ok( $mod->status->dist_cpan->status->created,
140 " Created status registered" );
141
142 ### install tests
143 SKIP: {
144 skip("Install tests require Module::Build 0.2606 or higher", 2)
145 unless $Module::Build::VERSION >= '0.2606';
146
147 ### flush the lib cache
148 ### otherwise, cpanplus thinks the module's already installed
149 ### since the blib is already in @INC
150 $CB->_flush( list => [qw|lib|] );
151
152 ### force the install, make sure the Dist::Build->install()
153 ### sub gets called
154 ok( $mod->install( force => 1 ),
155 "Installing module" );
156 ok( $mod->status->installed,
157 " Status says module installed" );
158 }
159
160 SKIP: {
161 my $minversion = 0.2609;
162 skip(qq[Uninstalling requires at least Module::Build $minversion], 1)
163 unless eval { Module::Build->VERSION($minversion); 1 };
164
165 # The installation directory actually needs to be in @INC
166 # in order to test uninstallation
167 'lib'->import( File::Spec->catdir($Lib, 'lib', 'perl5') );
168
169 # EU::Installed and CP+::M are only capable of searching
170 # for modules in the core directories. We need to fake
171 # them out with our own subs here.
172 my $packlist = find_module($mod->name . '::.packlist');
173 ok $packlist, "Found packlist";
174
175 my $p = ExtUtils::Packlist->new($packlist);
176 ok keys(%$p) > 0, "Packlist contains entries";
177
178 local *CPANPLUS::Module::installed_version = sub {1};
179 local *CPANPLUS::Module::packlist = sub { [$p] };
180 local *ExtUtils::Installed::files = sub { keys %$p };
181
182 ok( $mod->uninstall,"Uninstalling module" );
183 }
184 }
185
186 ### throw away all the extracted stuff
187 $Utils->_rmdir( dir => $Conf->get_conf('base') );
188}
189
190### test ENV setting while running Build.PL code
191{ ### use print() not die() -- we're redirecting STDERR in tests!
192 my $env = 'ENV_CPANPLUS_IS_EXECUTING';
193 my $clone = $Mod->clone;
194
195 ok( $clone, 'Testing ENV settings $dist->prepare' );
196
197 $clone->status->fetch( File::Spec->catfile($Src, 'noxs', $clone->package) );
198 ok( $clone->extract, ' Files extracted' );
199
200 ### write our own Build.PL file
201 my $build_pl = BUILD_PL->( $clone->status->extract );
202 { my $fh = OPEN_FILE->( $build_pl, '>' );
203 print $fh "die qq[ENV=\$ENV{$env}\n];";
204 close $fh;
205 }
206 ok( -e $build_pl, " File exists" );
207
208 ### clear errors
209 CPANPLUS::Error->flush;
210
211 ### since we're die'ing in the Build.PL, do a local *STDERR,
212 ### so we dont spam the result through the test -- this is expected
213 ### behaviour after all.
078adea4
JB
214 ### also quell the warning for print() on unopened fh...
215 my $rv = do {
216 local $^W;
217 local *STDERR;
218 $clone->prepare( force => 1 )
219 };
9b4bd854
JB
220 ok( !$rv, ' $mod->prepare failed' );
221
222 my $re = quotemeta( $build_pl );
223 like( CPANPLUS::Error->stack_as_string, qr/ENV=$re/,
224 " \$ENV $env set correctly during execution");
225
226 ### and the ENV var should no longer be set now
227 ok( !$ENV{$env}, " ENV var now unset" );
228}
229
230
231sub find_module {
232 my $module = shift;
233
078adea4
JB
234 ### Don't add the .pm yet, in case it's a packlist or something
235 ### like ExtUtils::xsubpp.
9b4bd854
JB
236 my $file = File::Spec->catfile( split m/::/, $module );
237 my $candidate;
238 foreach (@INC) {
239 if (-e ($candidate = File::Spec->catdir($_, $file))
240 or
241 -e ($candidate = File::Spec->catdir($_, "$file.pm"))
242 or
243 -e ($candidate = File::Spec->catdir($_, 'auto', $file))
244 or
245 -e ($candidate = File::Spec->catdir($_, 'auto', "$file.pm"))) {
246 return $candidate;
247 }
248 }
249 return;
250}
251
252
253# Local variables:
254# c-indentation-style: bsd
255# c-basic-offset: 4
256# indent-tabs-mode: nil
257# End:
258# vim: expandtab shiftwidth=4: