Commit | Line | Data |
3f7d1689 |
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 | |
31cf174a |
16 | sub 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 | |
23 | use Test::More; |
24 | use IPC::Open3; |
3f7d1689 |
25 | use File::Temp; |
26 | use File::Spec; |
27 | use local::lib (); |
28 | |
31cf174a |
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 | } |
3f7d1689 |
38 | } |
31cf174a |
39 | @perl = $^X |
40 | unless @perl; |
3f7d1689 |
41 | |
42 | my @modules = ( |
43 | [ 'ExtUtils::MakeMaker' => 6.74 ], |
44 | [ 'ExtUtils::Install' => 1.43 ], |
45 | [ 'Module::Build' => 0.36 ], |
46 | [ 'CPAN' => 1.82 ], |
47 | ); |
3f7d1689 |
48 | |
31cf174a |
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 | } |
3f7d1689 |
68 | } |
3f7d1689 |
69 | |
31cf174a |
70 | $ENV{HOME} = my $home = File::Temp::tempdir( CLEANUP => 1 ); |
71 | my $ll = File::Spec->catdir($home, 'local-lib'); |
3f7d1689 |
72 | |
31cf174a |
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); |
3f7d1689 |
84 | |
31cf174a |
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 | } |
3f7d1689 |
91 | } |