slight adjustment to tempdir cleanup in bootstrap test
[p5sagit/local-lib.git] / xt / bootstrap.t
1 use strict;
2 use warnings;
3 BEGIN {
4   if (@ARGV && $ARGV[0] eq '--check-version') {
5     my $module = $ARGV[1];
6     (my $file = "$module.pm") =~ s{::}{/}g;
7     eval {
8       require $file;
9       my $version = do { no strict; ${"${module}::VERSION"} };
10       print eval $version;
11     };
12     exit;
13   }
14 }
15
16 sub check_version {
17   my ($perl, $module) = @_;
18   my $version = `$perl $0 --check-version $module`;
19   chomp $version;
20   length $version ? $version : undef;
21 }
22
23 use Test::More;
24 use IPC::Open3;
25 use File::Temp;
26 use File::Spec;
27 use local::lib ();
28
29 my @perl;
30 while (@ARGV) {
31   my $arg = shift @ARGV;
32   if ($arg =~ /^--perl(?:=(.*))$/) {
33     push @perl, ($1 || shift @ARGV);
34   }
35   else {
36     warn "unrecognized option: $arg\n";
37   }
38 }
39 @perl = $^X
40   unless @perl;
41
42 my @modules = (
43   [ 'ExtUtils::MakeMaker' => 6.74 ],
44   [ 'ExtUtils::Install'   => 1.43 ],
45   [ 'Module::Build'       => 0.36 ],
46   [ 'CPAN'                => 1.82 ],
47 );
48
49 plan tests => @perl * (1+@modules);
50
51 for my $perl (@perl) {
52   local @INC = @INC;
53   local $ENV{PERL5LIB};
54   local $ENV{PERL_LOCAL_LIB_ROOT};
55   local $ENV{PERL_MM_OPT};
56   local $ENV{PERL_MB_OPT};
57   delete $ENV{PERL5LIB};
58   delete $ENV{PERL_LOCAL_LIB_ROOT};
59   delete $ENV{PERL_MM_OPT};
60   delete $ENV{PERL_MB_OPT};
61   my $home = File::Temp->newdir;
62   local $ENV{HOME} = $home->dirname;
63
64   diag "testing bootstrap with $perl";
65   for my $module (@modules) {
66     my $version = check_version($perl, $module->[0]);
67     if ($version && $version >= $module->[1]) {
68       diag "Can't test bootstrap of $module->[0], version $version already meets requirement of $module->[1]";
69     }
70   }
71
72   my $ll = File::Spec->catdir($home, 'local-lib');
73
74   open my $null_in, '<', File::Spec->devnull;
75   my $pid = open3 $null_in, my $out, undef, $perl, 'Makefile.PL', '--bootstrap='.$ll;
76   while (my $line = <$out>) {
77     note $line;
78   }
79   waitpid $pid, 0;
80
81   is $?, 0, 'Makefile.PL ran successfully'
82     or diag $out;
83
84   local::lib->setup_env_hash_for($ll);
85
86   for my $module (@modules) {
87     my $version = check_version($perl, $module->[0]);
88     cmp_ok $version, '>=', $module->[1], "bootstrap installed new enough $module->[0]"
89       or diag "PERL5LIB: $ENV{PERL5LIB}";
90   }
91 }