1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
9 use CPANPLUS::Configure;
10 use CPANPLUS::Backend;
12 use CPANPLUS::Dist::MM;
13 use CPANPLUS::Internals::Constants;
15 use Test::More 'no_plan';
19 use File::Basename ();
22 my $conf = gimme_conf();
23 my $cb = CPANPLUS::Backend->new( $conf );
24 my $noperms = ($< and not $conf->get_program('sudo')) &&
25 ($conf->get_conf('makemakerflags') or
26 not -w $Config{installsitelib} );
28 my $Verbose = @ARGV ? 1 : 0;
30 #$IPC::Cmd::DEBUG = $Verbose;
32 ### Make sure we get the _EUMM_NOXS_ version
33 my $ModName = TEST_CONF_MODULE;
35 ### This is the module name that gets /installed/
36 my $InstName = TEST_CONF_INST_MODULE;
38 ### don't start sending test reports now... ###
39 $cb->_callbacks->send_test_report( sub { 0 } );
40 $conf->set_conf( cpantest => 0 );
42 ### Redirect errors to file ###
43 *STDERR = output_handle() unless $Verbose;
45 ### dont uncomment this, it screws up where STDOUT goes and makes
46 ### test::harness create test counter mismatches
47 #*STDOUT = output_handle() unless @ARGV;
48 ### for the same test-output counter mismatch, we disable verbose
50 $conf->set_conf( verbose => $Verbose );
51 $conf->set_conf( allow_build_interactivity => 0 );
53 ### start with fresh sources ###
54 ok( $cb->reload_indices( update_source => 0 ),
57 ### we might need this Some Day when we're going to install into
58 ### our own sandbox dir.. but for now, no dice due to EU::I bug
59 # $conf->set_program( sudo => '' );
60 # $conf->set_conf( makemakerflags => TEST_INSTALL_EU_MM_FLAGS );
62 ### set alternate install dir ###
63 ### XXX rather pointless, since we can't uninstall them, due to a bug
64 ### in EU::Installed (6871). And therefor we can't test uninstall() or any of
65 ### the EU::Installed functions. So, let's just install into sitelib... =/
66 #my $prefix = File::Spec->rel2abs( File::Spec->catdir(cwd(),'dummy-perl') );
67 #my $rv = $cb->configure_object->set_conf( makemakerflags => "PREFIX=$prefix" );
68 #ok( $rv, "Alternate install path set" );
70 my $Mod = $cb->module_tree( $ModName );
71 my $InstMod = $cb->module_tree( $InstName );
72 ok( $Mod, "Loaded object for: " . $Mod->name );
73 ok( $Mod, "Loaded object for: " . $InstMod->name );
75 ### format_available tests ###
76 { ok( CPANPLUS::Dist::MM->format_available,
77 "Format is available" );
81 local *CPANPLUS::Dist::MM::can_load = sub { 0 };
82 ok(!CPANPLUS::Dist::MM->format_available,
83 " Making format unavailable" );
86 ### test if the error got logged ok ###
87 like( CPANPLUS::Error->stack_as_string,
88 qr/You do not have .+?'CPANPLUS::Dist::MM' not available/s,
89 " Format failure logged" );
91 ### flush the stack ###
92 CPANPLUS::Error->flush;
95 ok( $Mod->fetch, "Fetching module to ".$Mod->status->fetch );
96 ok( $Mod->extract, "Extracting module to ".$Mod->status->extract );
98 ok( $Mod->test, "Testing module" );
100 ok( $Mod->status->dist_cpan->status->test,
101 " Test success registered as status" );
102 ok( $Mod->status->dist_cpan->status->prepared,
103 " Prepared status registered" );
104 ok( $Mod->status->dist_cpan->status->created,
105 " Created status registered" );
106 is( $Mod->status->dist_cpan->status->distdir, $Mod->status->extract,
107 " Distdir status registered properly" );
109 ### test the convenience methods
110 ok( $Mod->prepare, "Preparing module" );
111 ok( $Mod->create, "Creating module" );
113 ok( $Mod->dist, "Building distribution" );
114 ok( $Mod->status->dist_cpan, " Dist registered as status" );
115 isa_ok( $Mod->status->dist_cpan, "CPANPLUS::Dist::MM" );
117 ### flush the lib cache
118 ### otherwise, cpanplus thinks the module's already installed
119 ### since the blib is already in @INC
120 $cb->_flush( list => [qw|lib|] );
124 skip(q[No install tests under core perl], 10) if $ENV{PERL_CORE};
126 skip(q[Probably no permissions to install, skipping], 10)
129 ### XXX new EU::I should be forthcoming pending this patch from Steffen
130 ### Mueller on p5p: http://www.xray.mpe.mpg.de/mailing-lists/ \
131 ### perl5-porters/2007-01/msg00895.html
132 ### This should become EU::I 1.42.. if so, we should upgrade this bit of
133 ### code and remove the diag, since we can then install in our dummy dir..
134 diag("\nSorry, installing into your real perl dir, rather than our test");
135 diag("area since ExtUtils::Installed does not probe for .packlists in " );
136 diag('other dirs than those in %Config. See bug #6871 on rt.cpan.org ' );
139 diag(q[Note: 'sudo' might ask for your password to do the install test])
140 if $conf->get_program('sudo');
142 ok( $Mod->install( force =>1 ),
143 "Installing module" );
144 ok( $Mod->status->installed," Module installed according to status" );
147 SKIP: { ### EU::Installed tests ###
149 skip("makemakerflags set -- probably EU::Installed tests will fail", 8)
150 if $conf->get_conf('makemakerflags');
152 skip( "Old perl on cygwin detected " .
153 "-- tests will fail due to known bugs", 8
156 ### might need it Later when EU::I is fixed..
157 #local @INC = ( TEST_INSTALL_DIR_LIB, @INC );
160 my @missing = $InstMod->validate;
162 is_deeply( \@missing, [],
163 "No missing files" );
167 my @files = $InstMod->files;
169 ### number of files may vary from OS to OS
170 ok( scalar(@files), "All files accounted for" );
171 ok( grep( /$File/, @files),
172 " Found the module" );
174 ### XXX does this work on all OSs?
175 #ok( grep( /man/, @files ),
176 # " Found the manpage" );
180 my ($obj) = $InstMod->packlist;
181 isa_ok( $obj, "ExtUtils::Packlist" );
185 my @dirs = $InstMod->directory_tree;
186 ok( scalar(@dirs), "Directory tree obtained" );
189 for my $dir (@dirs) {
190 ok( -d $dir, " Directory exists" );
192 my $file = File::Spec->catfile( $dir, $File );
193 $found = $file if -e $file;
196 ok( -e $found, " Module found" );
200 skip("Probably no permissions to uninstall", 1)
203 ok( $InstMod->uninstall,"Uninstalling module" );
208 ### test exceptions in Dist::MM->create ###
209 { ok( $Mod->status->mk_flush, "Old status info flushed" );
210 my $dist = CPANPLUS::Dist->new( module => $Mod,
211 format => INSTALLER_MM );
213 ok( $dist, "New dist object made" );
214 ok(!$dist->prepare, " Dist->prepare failed" );
215 like( CPANPLUS::Error->stack_as_string, qr/No dir found to operate on/,
218 ### manually set the extract dir,
219 $Mod->status->extract($0);
221 ok(!$dist->create, " Dist->create failed" );
222 like( CPANPLUS::Error->stack_as_string, qr/not successfully prepared/s,
225 ### pretend we've been prepared ###
226 $dist->status->prepared(1);
228 ok(!$dist->create, " Dist->create failed" );
229 like( CPANPLUS::Error->stack_as_string, qr/Could not chdir/s,
233 ### writemakefile.pl tests ###
234 { ### remove old status info
235 ok( $Mod->status->mk_flush, "Old status info flushed" );
236 ok( $Mod->fetch, "Module fetched again" );
237 ok( $Mod->extract, "Module extracted again" );
239 ### cheat and add fake prereqs ###
240 my $prereq = TEST_CONF_PREREQ;
242 $Mod->status->prereqs( { $prereq => 0 } );
244 my $makefile_pl = MAKEFILE_PL->( $Mod->status->extract );
245 my $makefile = MAKEFILE->( $Mod->status->extract );
247 my $dist = $Mod->dist;
248 ok( $dist, "Dist object built" );
250 ### check for a makefile.pl and 'write' one
251 ok( -s $makefile_pl, " Makefile.PL present" );
252 ok( $dist->write_makefile_pl( force => 0 ),
253 " Makefile.PL written" );
254 like( CPANPLUS::Error->stack_as_string, qr/Already created/,
255 " Prior existance noted" );
257 ### ok, unlink the makefile.pl, now really write one
260 ok( unlink($makefile_pl), "Deleting Makefile.PL");
261 ok( !-s $makefile_pl, " Makefile.PL deleted" );
262 ok( !-s $makefile, " Makefile deleted" );
263 ok($dist->write_makefile_pl," Makefile.PL written" );
265 ### see if we wrote anything sensible
266 my $fh = OPEN_FILE->( $makefile_pl );
267 ok( $fh, "Makefile.PL open for read" );
269 my $str = do { local $/; <$fh> };
270 like( $str, qr/### Auto-generated .+ by CPANPLUS ###/,
271 " Autogeneration noted" );
272 like( $str, '/'. $Mod->module .'/',
273 " Contains module name" );
274 like( $str, '/'. quotemeta($Mod->version) . '/',
275 " Contains version" );
276 like( $str, '/'. $Mod->author->author .'/',
277 " Contains author" );
278 like( $str, '/PREREQ_PM/', " Contains prereqs" );
279 like( $str, qr/$prereq.+0/, " Contains prereqs" );
283 ### seems ok, now delete it again and go via install()
284 ### to see if it picks up on the missing makefile.pl and
285 ### does the right thing
286 ok( unlink($makefile_pl), "Deleting Makefile.PL");
287 ok( !-s $makefile_pl, " Makefile.PL deleted" );
288 ok( $dist->status->mk_flush,"Dist status flushed" );
289 ok( $dist->prepare, " Dist->prepare run again" );
290 ok( $dist->create, " Dist->create run again" );
291 ok( -s $makefile_pl, " Makefile.PL present" );
292 like( CPANPLUS::Error->stack_as_string,
293 qr/attempting to generate one/,
294 " Makefile.PL generation attempt logged" );
296 ### now let's throw away the makefile.pl, flush the status and not
297 ### write a makefile.pl
299 local *CPANPLUS::Dist::MM::write_makefile_pl = sub { 1 };
304 ok(!-s $makefile_pl, "Makefile.PL deleted" );
305 ok(!-s $makefile, "Makefile deleted" );
306 ok( $dist->status->mk_flush,"Dist status flushed" );
307 ok(!$dist->prepare, " Dist->prepare failed" );
308 like( CPANPLUS::Error->stack_as_string,
309 qr/Could not find 'Makefile.PL'/i,
310 " Missing Makefile.PL noted" );
311 is( $dist->status->makefile, 0,
312 " Did not manage to create Makefile" );
315 ### now let's write a makefile.pl that just does 'die'
317 local *CPANPLUS::Dist::MM::write_makefile_pl =
318 __PACKAGE__->_custom_makefile_pl_sub( "exit 1;" );
320 ### there's no makefile.pl now, since the previous test failed
322 #ok( -e $makefile_pl, "Makefile.PL exists" );
323 #ok( unlink($makefile_pl), " Deleting Makefile.PL");
324 ok(!-s $makefile_pl, "Makefile.PL deleted" );
325 ok( $dist->status->mk_flush,"Dist status flushed" );
326 ok(!$dist->prepare, " Dist->prepare failed" );
327 like( CPANPLUS::Error->stack_as_string, qr/Could not run/s,
328 " Logged failed 'perl Makefile.PL'" );
329 is( $dist->status->makefile, 0,
330 " Did not manage to create Makefile" );
333 ### clean up afterwards ###
334 ok( unlink($makefile_pl), "Deleting Makefile.PL");
335 $dist->status->mk_flush;
339 ### test ENV setting in Makefile.PL
340 { ### use print() not die() -- we're redirecting STDERR in tests!
341 my $env = ENV_CPANPLUS_IS_EXECUTING;
342 my $sub = __PACKAGE__->_custom_makefile_pl_sub(
343 "print qq[ENV=\$ENV{$env}\n]; exit 1;" );
345 my $clone = $Mod->clone;
346 $clone->status->fetch( $Mod->status->fetch );
348 ok( $clone, 'Testing ENV settings $dist->prepare' );
349 ok( $clone->extract, ' Files extracted' );
350 ok( $clone->prepare, ' $mod->prepare worked first time' );
352 my $dist = $clone->status->dist;
353 my $makefile_pl = MAKEFILE_PL->( $clone->status->extract );
355 ok( $sub->($dist), " Custom Makefile.PL written" );
356 ok( -e $makefile_pl, " File exists" );
359 CPANPLUS::Error->flush;
361 my $rv = $dist->prepare( force => 1, verbose => 0 );
362 ok( !$rv, ' $dist->prepare failed' );
365 skip( "Can't test ENV{$env} -- no buffers available", 1 )
366 unless IPC::Cmd->can_capture_buffer;
368 my $re = quotemeta( $makefile_pl );
369 like( CPANPLUS::Error->stack_as_string, qr/ENV=$re/,
370 " \$ENV $env set correctly during execution");
373 ### and the ENV var should no longer be set now
374 ok( !$ENV{$env}, " ENV var now unset" );
377 sub _custom_makefile_pl_sub {
379 my $txt = shift or return;
383 my $self = $dist->parent;
384 my $fh = OPEN_FILE->(
385 MAKEFILE_PL->($self->status->extract), '>' );
395 # c-indentation-style: bsd
397 # indent-tabs-mode: nil
399 # vim: expandtab shiftwidth=4: