3 # Test ExtUtils::Install.
6 if( $ENV{PERL_CORE} ) {
7 @INC = ('../../lib', '../lib', 'lib');
10 unshift @INC, 't/lib';
20 use Test::More tests => 70;
22 use MakeMaker::Test::Setup::BFD;
24 BEGIN { use_ok('ExtUtils::Install') }
27 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
28 can_ok(__PACKAGE__, $func);
32 ok( setup_recurs(), 'setup' );
34 ok( chdir File::Spec->updir );
35 ok( teardown_recurs(), 'teardown' );
37 # ensure the env doesnt pollute our tests
38 local $ENV{EU_INSTALL_ALWAYS_COPY};
39 local $ENV{EU_ALWAYS_COPY};
43 my $stdout = tie *STDOUT, 'TieOut';
44 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
49 ok( -d 'blib/lib', 'pm_to_blib created blib dir' );
50 ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' );
51 ok( -r 'blib/lib/auto', ' created autosplit dir' );
52 is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" );
54 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
57 ok( -d 'blib/lib', 'second run, blib dir still there' );
58 ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' );
59 ok( -r 'blib/lib/auto', ' autosplit still there' );
60 is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
63 from_to=>{ 'blib/lib' => 'install-test/lib/perl',
64 read => 'install-test/packlist',
65 write => 'install-test/packlist'
68 ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
69 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
70 ' .pm file installed (dry run)');
71 ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
73 install([ from_to=> { 'blib/lib' => 'install-test/lib/perl',
74 read => 'install-test/packlist',
75 write => 'install-test/packlist'
77 ok( -d 'install-test/lib/perl', 'install made dir' );
78 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
79 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
80 ok( -r 'install-test/packlist', ' packlist exists' );
82 open(PACKLIST, 'install-test/packlist' );
83 my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
86 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
88 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
89 is( keys %packlist, 1 );
90 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
93 # Test UNINST=1 preserving same versions in other dirs.
94 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
95 read => 'install-test/packlist',
96 write => 'install-test/packlist'
97 },uninstall_shadows=>1]);
98 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
99 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
100 ok( -r 'install-test/packlist', ' packlist exists' );
101 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
104 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
105 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
106 print DUMMY "Extra stuff\n";
110 # Test UNINST=0 does not remove other versions in other dirs.
112 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
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'
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' );
127 # Test UNINST=1 only warning when failing to remove an irrelevent shadow file
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' );
135 local $SIG{__WARN__}=sub { push @warn, @_; return };
137 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
138 read => 'install-test/packlist',
139 write => 'install-test/packlist'
141 uninstall_shadows=>1]);
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' );
153 # Test UNINST=1 dieing when failing to remove an relevent shadow file
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' );
161 local $SIG{__WARN__}=sub { push @warn,@_; return };
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]);
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' );
177 # Test UNINST=1 removing other versions in other dirs.
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' );
193 # Test EU_ALWAYS_COPY triggers copy.
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' );
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');
215 ok( !$result{install_unchanged},' $result{install_unchanged} should be empty');
217 # Test nothing is copied.
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');