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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
#!/usr/bin/perl -w
# Test ExtUtils::Install.
BEGIN {
unshift @INC, 't/lib';
}
use strict;
use TieOut;
use File::Path;
use File::Spec;
use File::Temp qw[tempdir];
use Test::More tests => 70;
use MakeMaker::Test::Setup::BFD;
BEGIN { use_ok('ExtUtils::Install') }
# Check exports.
foreach my $func (qw(install uninstall pm_to_blib install_default)) {
can_ok(__PACKAGE__, $func);
}
my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
chdir $tmpdir;
ok( setup_recurs(), 'setup' );
END {
ok( chdir File::Spec->updir );
ok( teardown_recurs(), 'teardown' );
}
# ensure the env doesn't pollute our tests
local $ENV{EU_INSTALL_ALWAYS_COPY};
local $ENV{EU_ALWAYS_COPY};
chdir 'Big-Dummy';
my $stdout = tie *STDOUT, 'TieOut';
pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
'blib/lib/auto'
);
END { rmtree 'blib' }
ok( -d 'blib/lib', 'pm_to_blib created blib dir' );
ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' );
ok( -r 'blib/lib/auto', ' created autosplit dir' );
is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" );
pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
'blib/lib/auto'
);
ok( -d 'blib/lib', 'second run, blib dir still there' );
ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' );
ok( -r 'blib/lib/auto', ' autosplit still there' );
is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
install( [
from_to=>{ 'blib/lib' => 'install-test/lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},
dry_run=>1]);
ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
' .pm file installed (dry run)');
ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
install([ from_to=> { 'blib/lib' => 'install-test/lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
} ]);
ok( -d 'install-test/lib/perl', 'install made dir' );
ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
ok( -r 'install-test/packlist', ' packlist exists' );
open(PACKLIST, 'install-test/packlist' );
my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
close PACKLIST;
# On case-insensitive filesystems (ie. VMS), the keys of the packlist might
# be lowercase. :(
my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
is( keys %packlist, 1 );
is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
# Test UNINST=1 preserving same versions in other dirs.
install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},uninstall_shadows=>1]);
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
print DUMMY "Extra stuff\n";
close DUMMY;
# Test UNINST=0 does not remove other versions in other dirs.
{
ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
local @INC = ('install-test/lib/perl');
local $ENV{PERL5LIB} = '';
install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
}]);
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
ok( -r 'install-test/lib/perl/Big/Dummy.pm',
' UNINST=0 left different' );
}
# Test UNINST=1 only warning when failing to remove an irrelevant shadow file
{
my $tfile='install-test/lib/perl/Big/Dummy.pm';
local $ExtUtils::Install::Testing = $tfile;
local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
local $ENV{PERL5LIB} = '';
ok( -r $tfile, 'different install exists' );
my @warn;
local $SIG{__WARN__}=sub { push @warn, @_; return };
my $ok=eval {
install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},
uninstall_shadows=>1]);
1
};
ok($ok,' we didnt die');
ok(0+@warn," we did warn");
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
ok( -r $tfile, ' UNINST=1 failed to remove different' );
}
# Test UNINST=1 dieing when failing to remove an relevant shadow file
{
my $tfile='install-test/lib/perl/Big/Dummy.pm';
local $ExtUtils::Install::Testing = $tfile;
local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
local $ENV{PERL5LIB} = '';
ok( -r $tfile, 'different install exists' );
my @warn;
local $SIG{__WARN__}=sub { push @warn,@_; return };
my $ok=eval {
install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},uninstall_shadows=>1]);
1
};
ok(!$ok,' we did die');
ok(!@warn," we didnt warn");
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
ok( -r $tfile,' UNINST=1 failed to remove different' );
}
# Test UNINST=1 removing other versions in other dirs.
{
local @INC = ('install-test/lib/perl');
local $ENV{PERL5LIB} = '';
ok( -r 'install-test/lib/perl/Big/Dummy.pm','different install exists' );
install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},uninstall_shadows=>1]);
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
' UNINST=1 removed different' );
}
# Test EU_ALWAYS_COPY triggers copy.
{
local @INC = ('install-test/lib/perl');
local $ENV{PERL5LIB} = '';
local $ENV{EU_INSTALL_ALWAYS_COPY}=1;
my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
my $sfile='blib/lib/Big/Dummy.pm';
ok(-r $tfile,"install file already exists");
ok(-r $sfile,"source file already exists");
utime time-600, time-600, $sfile or die "utime '$sfile' failed:$!";
ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},result=>\my %result]);
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
SKIP: {
skip "Times not preserved during copy by default", 1 if $^O eq 'VMS';
ok( (stat $tfile)[9]==(stat $sfile)[9],' Times are same');
}
ok( !$result{install_unchanged},' $result{install_unchanged} should be empty');
}
# Test nothing is copied.
{
local @INC = ('install-test/lib/perl');
local $ENV{PERL5LIB} = '';
local $ENV{EU_INSTALL_ALWAYS_COPY}=0;
my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
my $sfile='blib/lib/Big/Dummy.pm';
ok(-r $tfile,"install file already exists");
ok(-r $sfile,"source file already exists");
utime time-1200, time-1200, $sfile or die "utime '$sfile' failed:$!";
ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
read => 'install-test/packlist',
write => 'install-test/packlist'
},result=>\my %result]);
ok( -d 'install-test/other_lib/perl', 'install made other dir' );
ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
ok( -r 'install-test/packlist', ' packlist exists' );
ok( (stat $tfile)[9]!=(stat$sfile)[9],' Times are different');
ok( !$result{install},' nothing should have been installed');
ok( $result{install_unchanged},' install_unchanged should be populated');
}
|