clean up bootstrapping test
[p5sagit/local-lib.git] / xt / bootstrap.t
CommitLineData
3f7d1689 1use strict;
2use warnings;
3BEGIN {
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
16use Test::More;
18f3e0b5 17BEGIN {
18 if (!eval {require Capture::Tiny}) {
19 plan skip_all => 'Capture::Tiny required to test bootstrapping';
20 }
21}
3f7d1689 22use File::Temp;
23use File::Spec;
24use local::lib ();
25
26delete $ENV{PERL5LIB};
27delete $ENV{PERL_LOCAL_LIB_ROOT};
28delete $ENV{PERL_MM_OPT};
29delete $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
35sub check_version {
36 my $module = shift;
37 my $version = `$^X $0 --check-version $module`;
38 chomp $version;
39 length $version ? $version : undef;
40}
41
42my @modules = (
43 [ 'ExtUtils::MakeMaker' => 6.74 ],
44 [ 'ExtUtils::Install' => 1.43 ],
45 [ 'Module::Build' => 0.36 ],
46 [ 'CPAN' => 1.82 ],
47);
48plan tests => 1+@modules;
49
50for my $module (@modules) {
51 my $version = check_version($module->[0]);
52 if ($version && $version >= $module->[1]) {
18f3e0b5 53 diag "Can't test bootstrap of $module->[0], version $version already meets requirement of $module->[1]";
3f7d1689 54 }
55}
56
57$ENV{HOME} = my $home = File::Temp::tempdir( CLEANUP => 1 );
18f3e0b5 58mkdir my $ll = File::Spec->catdir($home, 'perl5');
59local::lib->import($ll);
3f7d1689 60
18f3e0b5 61my $result;
62my $out = Capture::Tiny::capture_merged {
63 $result = system($^X, 'Makefile.PL', '--bootstrap');
64};
65is $result, 0, 'Makefile.PL ran successfully'
66 or diag $out;
3f7d1689 67
68for my $module (@modules) {
69 my $version = check_version($module->[0]);
70 cmp_ok $version, '>=', $module->[1], "bootstrap installed new enough $module->[0]";
71}