1#!/usr/bin/perl -w 2use strict; 3 4# Test ExtUtils::Install. 5 6BEGIN { 7 unshift @INC, 't/lib'; 8} 9 10use TieOut; 11use File::Path; 12use File::Spec; 13use File::Temp qw[tempdir]; 14 15use Test::More tests => 70; 16 17use MakeMaker::Test::Setup::BFD; 18 19BEGIN { 20 local $ENV{PERL_INSTALL_QUIET}; 21 use_ok('ExtUtils::Install'); 22} 23 24# Check exports. 25foreach my $func (qw(install uninstall pm_to_blib install_default)) { 26 can_ok(__PACKAGE__, $func); 27} 28 29my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 ); 30chdir $tmpdir; 31 32ok( setup_recurs(), 'setup' ); 33END { 34 ok( chdir File::Spec->updir ); 35 ok( teardown_recurs(), 'teardown' ); 36} 37# ensure the env doesn't pollute our tests 38local $ENV{EU_INSTALL_ALWAYS_COPY}; 39local $ENV{EU_ALWAYS_COPY}; 40 41chdir 'Big-Dummy'; 42 43my $stdout = tie *STDOUT, 'TieOut'; 44pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' }, 45 'blib/lib/auto' 46 ); 47END { rmtree 'blib' } 48 49ok( -d 'blib/lib', 'pm_to_blib created blib dir' ); 50ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' ); 51ok( -r 'blib/lib/auto', ' created autosplit dir' ); 52is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" ); 53 54pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' }, 55 'blib/lib/auto' 56 ); 57ok( -d 'blib/lib', 'second run, blib dir still there' ); 58ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' ); 59ok( -r 'blib/lib/auto', ' autosplit still there' ); 60is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" ); 61 62install( [ 63 from_to=>{ 'blib/lib' => 'install-test/lib/perl', 64 read => 'install-test/packlist', 65 write => 'install-test/packlist' 66 }, 67 dry_run=>1]); 68ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)'); 69ok( ! -r 'install-test/lib/perl/Big/Dummy.pm', 70 ' .pm file installed (dry run)'); 71ok( ! -r 'install-test/packlist', ' packlist exists (dry run)'); 72 73install([ from_to=> { 'blib/lib' => 'install-test/lib/perl', 74 read => 'install-test/packlist', 75 write => 'install-test/packlist' 76 } ]); 77ok( -d 'install-test/lib/perl', 'install made dir' ); 78ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' ); 79ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' ); 80ok( -r 'install-test/packlist', ' packlist exists' ); 81 82open(PACKLIST, 'install-test/packlist' ); 83my %packlist = map { chomp; ($_ => 1) } <PACKLIST>; 84close PACKLIST; 85 86# On case-insensitive filesystems (ie. VMS), the keys of the packlist might 87# be lowercase. :( 88my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm)); 89is( keys %packlist, 1 ); 90is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' ); 91 92 93# Test UNINST=1 preserving same versions in other dirs. 94install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl', 95 read => 'install-test/packlist', 96 write => 'install-test/packlist' 97 },uninstall_shadows=>1]); 98ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 99ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 100ok( -r 'install-test/packlist', ' packlist exists' ); 101ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' ); 102 103 104chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!; 105open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!; 106print DUMMY "Extra stuff\n"; 107close DUMMY; 108 109 110# Test UNINST=0 does not remove other versions in other dirs. 111{ 112 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' ); 113 114 local @INC = ('install-test/lib/perl'); 115 local $ENV{PERL5LIB} = ''; 116 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl', 117 read => 'install-test/packlist', 118 write => 'install-test/packlist' 119 }]); 120 ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 121 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 122 ok( -r 'install-test/packlist', ' packlist exists' ); 123 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 124 ' UNINST=0 left different' ); 125} 126 127# Test UNINST=1 only warning when failing to remove an irrelevant shadow file 128{ 129 my $tfile='install-test/lib/perl/Big/Dummy.pm'; 130 local $ExtUtils::Install::Testing = $tfile; 131 local @INC = ('install-test/other_lib/perl','install-test/lib/perl'); 132 local $ENV{PERL5LIB} = ''; 133 ok( -r $tfile, 'different install exists' ); 134 my @warn; 135 local $SIG{__WARN__}=sub { push @warn, @_; return }; 136 my $ok=eval { 137 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl', 138 read => 'install-test/packlist', 139 write => 'install-test/packlist' 140 }, 141 uninstall_shadows=>1]); 142 1 143 }; 144 ok($ok,' we didnt die'); 145 ok(0+@warn," we did warn"); 146 ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 147 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 148 ok( -r 'install-test/packlist', ' packlist exists' ); 149 ok( -r $tfile, ' UNINST=1 failed to remove different' ); 150 151} 152 153# Test UNINST=1 dieing when failing to remove an relevant shadow file 154{ 155 my $tfile='install-test/lib/perl/Big/Dummy.pm'; 156 local $ExtUtils::Install::Testing = $tfile; 157 local @INC = ('install-test/lib/perl','install-test/other_lib/perl'); 158 local $ENV{PERL5LIB} = ''; 159 ok( -r $tfile, 'different install exists' ); 160 my @warn; 161 local $SIG{__WARN__}=sub { push @warn,@_; return }; 162 my $ok=eval { 163 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl', 164 read => 'install-test/packlist', 165 write => 'install-test/packlist' 166 },uninstall_shadows=>1]); 167 1 168 }; 169 ok(!$ok,' we did die'); 170 ok(!@warn," we didnt warn"); 171 ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 172 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 173 ok( -r 'install-test/packlist', ' packlist exists' ); 174 ok( -r $tfile,' UNINST=1 failed to remove different' ); 175} 176 177# Test UNINST=1 removing other versions in other dirs. 178{ 179 local @INC = ('install-test/lib/perl'); 180 local $ENV{PERL5LIB} = ''; 181 ok( -r 'install-test/lib/perl/Big/Dummy.pm','different install exists' ); 182 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl', 183 read => 'install-test/packlist', 184 write => 'install-test/packlist' 185 },uninstall_shadows=>1]); 186 ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 187 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 188 ok( -r 'install-test/packlist', ' packlist exists' ); 189 ok( !-r 'install-test/lib/perl/Big/Dummy.pm', 190 ' UNINST=1 removed different' ); 191} 192 193# Test EU_ALWAYS_COPY triggers copy. 194{ 195 local @INC = ('install-test/lib/perl'); 196 local $ENV{PERL5LIB} = ''; 197 local $ENV{EU_INSTALL_ALWAYS_COPY}=1; 198 my $tfile='install-test/other_lib/perl/Big/Dummy.pm'; 199 my $sfile='blib/lib/Big/Dummy.pm'; 200 ok(-r $tfile,"install file already exists"); 201 ok(-r $sfile,"source file already exists"); 202 utime time-600, time-600, $sfile or die "utime '$sfile' failed:$!"; 203 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different'); 204 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl', 205 read => 'install-test/packlist', 206 write => 'install-test/packlist' 207 },result=>\my %result]); 208 ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 209 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 210 ok( -r 'install-test/packlist', ' packlist exists' ); 211SKIP: { 212 skip "Times not preserved during copy by default", 1 if $^O eq 'VMS'; 213 ok( (stat $tfile)[9]==(stat $sfile)[9],' Times are same'); 214} 215 ok( !$result{install_unchanged},' $result{install_unchanged} should be empty'); 216} 217# Test nothing is copied. 218{ 219 local @INC = ('install-test/lib/perl'); 220 local $ENV{PERL5LIB} = ''; 221 local $ENV{EU_INSTALL_ALWAYS_COPY}=0; 222 my $tfile='install-test/other_lib/perl/Big/Dummy.pm'; 223 my $sfile='blib/lib/Big/Dummy.pm'; 224 ok(-r $tfile,"install file already exists"); 225 ok(-r $sfile,"source file already exists"); 226 utime time-1200, time-1200, $sfile or die "utime '$sfile' failed:$!"; 227 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different'); 228 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl', 229 read => 'install-test/packlist', 230 write => 'install-test/packlist' 231 },result=>\my %result]); 232 ok( -d 'install-test/other_lib/perl', 'install made other dir' ); 233 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); 234 ok( -r 'install-test/packlist', ' packlist exists' ); 235 ok( (stat $tfile)[9]!=(stat$sfile)[9],' Times are different'); 236 ok( !$result{install},' nothing should have been installed'); 237 ok( $result{install_unchanged},' install_unchanged should be populated'); 238} 239