d50b992931d932aa67b4ea8d821fced8cde05e75
[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 use Test::More;
17 BEGIN {
18   if (!eval {require Capture::Tiny}) {
19     plan skip_all => 'Capture::Tiny required to test bootstrapping';
20   }
21 }
22 use File::Temp;
23 use File::Spec;
24 use local::lib ();
25
26 delete $ENV{PERL5LIB};
27 delete $ENV{PERL_LOCAL_LIB_ROOT};
28 delete $ENV{PERL_MM_OPT};
29 delete $ENV{PERL_MB_OPT};
30
31 #my @ll_path = File::Spec->splitpath($INC{'local/lib.pm'});
32 #my @ll_dir = File::Spec->splitdir($ll_path[1]);
33 #my $ll_dir = File::Spec->catpath($ll_path[0], File::Spec->catdir(@ll_dir[0 .. $#_-1]), '');
34
35 sub check_version {
36   my $module = shift;
37   my $version = `$^X $0 --check-version $module`;
38   chomp $version;
39   length $version ? $version : undef;
40 }
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 plan tests => 1+@modules;
49
50 for my $module (@modules) {
51   my $version = check_version($module->[0]);
52   if ($version && $version >= $module->[1]) {
53     diag "Can't test bootstrap of $module->[0], version $version already meets requirement of $module->[1]";
54   }
55 }
56
57 $ENV{HOME} = my $home = File::Temp::tempdir( CLEANUP => 1 );
58 mkdir my $ll = File::Spec->catdir($home, 'perl5');
59 local::lib->import($ll);
60
61 my $result;
62 my $out = Capture::Tiny::capture_merged {
63   $result = system($^X, 'Makefile.PL', '--bootstrap');
64 };
65 is $result, 0, 'Makefile.PL ran successfully'
66   or diag $out;
67
68 for my $module (@modules) {
69   my $version = check_version($module->[0]);
70   cmp_ok $version, '>=', $module->[1], "bootstrap installed new enough $module->[0]";
71 }