3df6e7edc5977b6f2c0f9bf931985b640ce11096
[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
62   diag "testing bootstrap with $perl";
63   for my $module (@modules) {
64     my $version = check_version($perl, $module->[0]);
65     if ($version && $version >= $module->[1]) {
66       diag "Can't test bootstrap of $module->[0], version $version already meets requirement of $module->[1]";
67     }
68   }
69
70   $ENV{HOME} = my $home = File::Temp::tempdir( CLEANUP => 1 );
71   my $ll = File::Spec->catdir($home, 'local-lib');
72
73   open my $null_in, '<', File::Spec->devnull;
74   my $pid = open3 $null_in, my $out, undef, $perl, 'Makefile.PL', '--bootstrap='.$ll;
75   while (my $line = <$out>) {
76     note $line;
77   }
78   waitpid $pid, 0;
79
80   is $?, 0, 'Makefile.PL ran successfully'
81     or diag $out;
82
83   local::lib->setup_env_hash_for($ll);
84
85   for my $module (@modules) {
86     my $version = check_version($perl, $module->[0]);
87     cmp_ok $version, '>=', $module->[1], "bootstrap installed new enough $module->[0]"
88       or diag "PERL5LIB: $ENV{PERL5LIB}";
89
90   }
91 }