slight adjustment to tempdir cleanup in bootstrap 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
31cf174a 16sub check_version {
17 my ($perl, $module) = @_;
18 my $version = `$perl $0 --check-version $module`;
19 chomp $version;
20 length $version ? $version : undef;
18f3e0b5 21}
31cf174a 22
23use Test::More;
24use IPC::Open3;
3f7d1689 25use File::Temp;
26use File::Spec;
27use local::lib ();
28
31cf174a 29my @perl;
30while (@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 }
3f7d1689 38}
31cf174a 39@perl = $^X
40 unless @perl;
3f7d1689 41
42my @modules = (
43 [ 'ExtUtils::MakeMaker' => 6.74 ],
44 [ 'ExtUtils::Install' => 1.43 ],
45 [ 'Module::Build' => 0.36 ],
46 [ 'CPAN' => 1.82 ],
47);
3f7d1689 48
31cf174a 49plan tests => @perl * (1+@modules);
50
51for 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};
aab637e3 61 my $home = File::Temp->newdir;
62 local $ENV{HOME} = $home->dirname;
31cf174a 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 }
3f7d1689 70 }
3f7d1689 71
31cf174a 72 my $ll = File::Spec->catdir($home, 'local-lib');
3f7d1689 73
31cf174a 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);
3f7d1689 85
31cf174a 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}";
31cf174a 90 }
3f7d1689 91}