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