File: bootstrap.t

package info (click to toggle)
liblocal-lib-perl 2.000029-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 344 kB
  • sloc: perl: 1,141; makefile: 13
file content (152 lines) | stat: -rw-r--r-- 3,865 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use strict;
use warnings;

use lib 't/lib', 'xt/lib';
use Test::More 0.81_01;
use IPC::Open3;
use TempDir;
use File::Spec;
use File::Path qw(rmtree);
use File::Basename qw(dirname);
use local::lib ();
use ExtUtils::MakeMaker;
use Cwd qw(cwd);
use dist_util;

sub check_version {
  my ($perl, $module) = @_;
  my @inc = `$perl -le "print for \@INC"`;
  chomp @inc;
  (my $file = "$module.pm") =~ s{::}{/}g;
  ($file) = grep -e, map { "$_/$file" } @inc;
  return undef
    unless $file;
  my $version = MM->parse_version($file);
  eval $version;
}

my @perl;
my $verbose;
while (@ARGV) {
  my $arg = shift @ARGV;
  if ($arg eq '-v') {
    $verbose = 1;
  }
  elsif ($arg eq '--') {
    push @perl, @ARGV;
    @ARGV = ();
  }
  elsif ($arg =~ /^-/) {
    warn "unrecognized option: $arg\n";
  }
  else {
    push @perl, $arg;
  }
}

my $dist_dir = make_dist_dir;
my $cwd = cwd;
END {
  chdir $cwd;
  rmtree $dist_dir;
}

chdir $dist_dir;

@perl = local::lib::_perl
  unless @perl;

my %modules = (
  'ExtUtils::MakeMaker' => '7.00', # version INSTALL_BASE taken as string, not shell
  'ExtUtils::Install'   => '1.43', # version INSTALL_BASE was added
  'Module::Build'       => '0.36', # PERL_MB_OPT
  'CPAN'                => '1.82', # sudo support + CPAN::HandleConfig
);

plan tests => @perl * 2 * (2+2*keys %modules);

for my $perl (@perl) {
  local @INC = @INC;
  local $ENV{AUTOMATED_TESTING} = 1;
  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";
  my %old_versions;
  for my $module (sort keys %modules) {
    my $version = check_version($perl, $module);
    $old_versions{$module} = $version;
    if ($version && $version >= $modules{$module}) {
      diag "Can't test bootstrap of $module, version $version already meets requirement of $modules{$module}";
    }
  }

  my $home_base = mk_temp_dir('home-base');

  for my $home_tmpl ('home', 'spaces in home') {
    delete $ENV{PERL5LIB};
    delete $ENV{PERL_LOCAL_LIB_ROOT};
    delete $ENV{PERL_MM_OPT};
    delete $ENV{PERL_MB_OPT};
    local $ENV{HOME} = my $home = "$home_base/$home_tmpl";

    my $ll = File::Spec->catdir($home, 'local-lib');
    note "local::lib dir is $ll";

    unlink 'MYMETA.yml';
    unlink 'Makefile';

    open my $null_in, '<', File::Spec->devnull;
    my $pid = open3 $null_in, my $out, undef,
      $perl, 'Makefile.PL', '--bootstrap='.$ll, '--no-manpages';
    while (my $line = <$out>) {
      note $line
        if $verbose || $line =~ /^Running |^\s.* -- (?:NOT OK|OK|NA|TIMED OUT)$/;
    }
    waitpid $pid, 0;

    is $?, 0, 'Makefile.PL ran successfully';

    ok -e 'Makefile', 'Makefile created';

    my $prereqs = {};
    open my $fh, '<', 'Makefile'
      or die "Unable to open Makefile: $!";

    while (<$fh>) {
      last if /MakeMaker post_initialize section/;
      my ($p) = m{^[\#]\s+PREREQ_PM\s+=>\s+(.+)}
        or next;

      while ( $p =~ m/(?:\s)([\w\:]+)=>(?:q\[(.*?)\]|undef),?/g ) {
        $prereqs->{$1} = $2;
      }
    }
    close $fh;

    local::lib->setup_env_hash_for($ll);

    for my $module (sort keys %modules) {
      my $version = check_version($perl, $module);
      my $old_v = $old_versions{$module};
      my $want_v = $modules{$module};
      if (defined $old_v) {
        is $prereqs->{$module}, ($old_v >= $want_v ? undef : $want_v),
          "prereqs correct for $module";
        cmp_ok $version, '>=', $want_v, "bootstrap upgraded to new enough $module"
          or diag "PERL5LIB: $ENV{PERL5LIB}";
      }
      else {
        ok !exists $prereqs->{$module},
          "$module not listed as prereq";
        is $version, undef, "bootstrap didn't install new module $module";
      }
    }
  }
}