From: Graham Knop Date: Thu, 28 Nov 2013 03:04:07 +0000 (-0500) Subject: better bootstrapping test X-Git-Tag: v2.000_000~58 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=31cf174a82fa3ae4fecf62fcc34b6e854024d2db;p=p5sagit%2Flocal-lib.git better bootstrapping test improve bootstrap test, including testing with alternate perls --- diff --git a/xt/bootstrap.t b/xt/bootstrap.t index d50b992..3df6e7e 100755 --- a/xt/bootstrap.t +++ b/xt/bootstrap.t @@ -13,31 +13,31 @@ BEGIN { } } -use Test::More; -BEGIN { - if (!eval {require Capture::Tiny}) { - plan skip_all => 'Capture::Tiny required to test bootstrapping'; - } +sub check_version { + my ($perl, $module) = @_; + my $version = `$perl $0 --check-version $module`; + chomp $version; + length $version ? $version : undef; } + +use Test::More; +use IPC::Open3; use File::Temp; use File::Spec; use local::lib (); -delete $ENV{PERL5LIB}; -delete $ENV{PERL_LOCAL_LIB_ROOT}; -delete $ENV{PERL_MM_OPT}; -delete $ENV{PERL_MB_OPT}; - -#my @ll_path = File::Spec->splitpath($INC{'local/lib.pm'}); -#my @ll_dir = File::Spec->splitdir($ll_path[1]); -#my $ll_dir = File::Spec->catpath($ll_path[0], File::Spec->catdir(@ll_dir[0 .. $#_-1]), ''); - -sub check_version { - my $module = shift; - my $version = `$^X $0 --check-version $module`; - chomp $version; - length $version ? $version : undef; +my @perl; +while (@ARGV) { + my $arg = shift @ARGV; + if ($arg =~ /^--perl(?:=(.*))$/) { + push @perl, ($1 || shift @ARGV); + } + else { + warn "unrecognized option: $arg\n"; + } } +@perl = $^X + unless @perl; my @modules = ( [ 'ExtUtils::MakeMaker' => 6.74 ], @@ -45,27 +45,47 @@ my @modules = ( [ 'Module::Build' => 0.36 ], [ 'CPAN' => 1.82 ], ); -plan tests => 1+@modules; -for my $module (@modules) { - my $version = check_version($module->[0]); - if ($version && $version >= $module->[1]) { - diag "Can't test bootstrap of $module->[0], version $version already meets requirement of $module->[1]"; +plan tests => @perl * (1+@modules); + +for my $perl (@perl) { + local @INC = @INC; + local $ENV{PERL5LIB}; + local $ENV{PERL_LOCAL_LIB_ROOT}; + local $ENV{PERL_MM_OPT}; + local $ENV{PERL_MB_OPT}; + delete $ENV{PERL5LIB}; + delete $ENV{PERL_LOCAL_LIB_ROOT}; + delete $ENV{PERL_MM_OPT}; + delete $ENV{PERL_MB_OPT}; + + diag "testing bootstrap with $perl"; + for my $module (@modules) { + my $version = check_version($perl, $module->[0]); + if ($version && $version >= $module->[1]) { + diag "Can't test bootstrap of $module->[0], version $version already meets requirement of $module->[1]"; + } } -} -$ENV{HOME} = my $home = File::Temp::tempdir( CLEANUP => 1 ); -mkdir my $ll = File::Spec->catdir($home, 'perl5'); -local::lib->import($ll); + $ENV{HOME} = my $home = File::Temp::tempdir( CLEANUP => 1 ); + my $ll = File::Spec->catdir($home, 'local-lib'); -my $result; -my $out = Capture::Tiny::capture_merged { - $result = system($^X, 'Makefile.PL', '--bootstrap'); -}; -is $result, 0, 'Makefile.PL ran successfully' - or diag $out; + open my $null_in, '<', File::Spec->devnull; + my $pid = open3 $null_in, my $out, undef, $perl, 'Makefile.PL', '--bootstrap='.$ll; + while (my $line = <$out>) { + note $line; + } + waitpid $pid, 0; + + is $?, 0, 'Makefile.PL ran successfully' + or diag $out; + + local::lib->setup_env_hash_for($ll); -for my $module (@modules) { - my $version = check_version($module->[0]); - cmp_ok $version, '>=', $module->[1], "bootstrap installed new enough $module->[0]"; + for my $module (@modules) { + my $version = check_version($perl, $module->[0]); + cmp_ok $version, '>=', $module->[1], "bootstrap installed new enough $module->[0]" + or diag "PERL5LIB: $ENV{PERL5LIB}"; + + } }