3 # Test ExtUtils::Install.
13 use File::Temp qw[tempdir];
15 use Test::More tests => 70;
17 use MakeMaker::Test::Setup::BFD;
19 BEGIN { use_ok('ExtUtils::Install') }
22 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
23 can_ok(__PACKAGE__, $func);
26 my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
29 ok( setup_recurs(), 'setup' );
31 ok( chdir File::Spec->updir );
32 ok( teardown_recurs(), 'teardown' );
34 # ensure the env doesn't pollute our tests
35 local $ENV{EU_INSTALL_ALWAYS_COPY};
36 local $ENV{EU_ALWAYS_COPY};
37 local $ENV{PERL_INSTALL_QUIET};
41 my $stdout = tie *STDOUT, 'TieOut';
42 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
47 ok( -d 'blib/lib', 'pm_to_blib created blib dir' );
48 ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' );
49 ok( -r 'blib/lib/auto', ' created autosplit dir' );
50 is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" );
52 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
55 ok( -d 'blib/lib', 'second run, blib dir still there' );
56 ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' );
57 ok( -r 'blib/lib/auto', ' autosplit still there' );
58 is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
61 from_to=>{ 'blib/lib' => 'install-test/lib/perl',
62 read => 'install-test/packlist',
63 write => 'install-test/packlist'
66 ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
67 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
68 ' .pm file installed (dry run)');
69 ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
71 install([ from_to=> { 'blib/lib' => 'install-test/lib/perl',
72 read => 'install-test/packlist',
73 write => 'install-test/packlist'
75 ok( -d 'install-test/lib/perl', 'install made dir' );
76 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
77 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
78 ok( -r 'install-test/packlist', ' packlist exists' );
80 open(PACKLIST, 'install-test/packlist' );
81 my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
84 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
86 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
87 is( keys %packlist, 1 );
88 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
91 # Test UNINST=1 preserving same versions in other dirs.
92 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
93 read => 'install-test/packlist',
94 write => 'install-test/packlist'
95 },uninstall_shadows=>1]);
96 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
97 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
98 ok( -r 'install-test/packlist', ' packlist exists' );
99 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
102 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
103 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
104 print DUMMY "Extra stuff\n";
108 # Test UNINST=0 does not remove other versions in other dirs.
110 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
112 local @INC = ('install-test/lib/perl');
113 local $ENV{PERL5LIB} = '';
114 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
115 read => 'install-test/packlist',
116 write => 'install-test/packlist'
118 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
119 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
120 ok( -r 'install-test/packlist', ' packlist exists' );
121 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
122 ' UNINST=0 left different' );
125 # Test UNINST=1 only warning when failing to remove an irrelevant shadow file
127 my $tfile='install-test/lib/perl/Big/Dummy.pm';
128 local $ExtUtils::Install::Testing = $tfile;
129 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
130 local $ENV{PERL5LIB} = '';
131 ok( -r $tfile, 'different install exists' );
133 local $SIG{__WARN__}=sub { push @warn, @_; return };
135 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
136 read => 'install-test/packlist',
137 write => 'install-test/packlist'
139 uninstall_shadows=>1]);
142 ok($ok,' we didnt die');
143 ok(0+@warn," we did warn");
144 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
145 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
146 ok( -r 'install-test/packlist', ' packlist exists' );
147 ok( -r $tfile, ' UNINST=1 failed to remove different' );
151 # Test UNINST=1 dieing when failing to remove an relevant shadow file
153 my $tfile='install-test/lib/perl/Big/Dummy.pm';
154 local $ExtUtils::Install::Testing = $tfile;
155 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
156 local $ENV{PERL5LIB} = '';
157 ok( -r $tfile, 'different install exists' );
159 local $SIG{__WARN__}=sub { push @warn,@_; return };
161 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
162 read => 'install-test/packlist',
163 write => 'install-test/packlist'
164 },uninstall_shadows=>1]);
167 ok(!$ok,' we did die');
168 ok(!@warn," we didnt warn");
169 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
170 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
171 ok( -r 'install-test/packlist', ' packlist exists' );
172 ok( -r $tfile,' UNINST=1 failed to remove different' );
175 # Test UNINST=1 removing other versions in other dirs.
177 local @INC = ('install-test/lib/perl');
178 local $ENV{PERL5LIB} = '';
179 ok( -r 'install-test/lib/perl/Big/Dummy.pm','different install exists' );
180 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
181 read => 'install-test/packlist',
182 write => 'install-test/packlist'
183 },uninstall_shadows=>1]);
184 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
185 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
186 ok( -r 'install-test/packlist', ' packlist exists' );
187 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
188 ' UNINST=1 removed different' );
191 # Test EU_ALWAYS_COPY triggers copy.
193 local @INC = ('install-test/lib/perl');
194 local $ENV{PERL5LIB} = '';
195 local $ENV{EU_INSTALL_ALWAYS_COPY}=1;
196 my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
197 my $sfile='blib/lib/Big/Dummy.pm';
198 ok(-r $tfile,"install file already exists");
199 ok(-r $sfile,"source file already exists");
200 utime time-600, time-600, $sfile or die "utime '$sfile' failed:$!";
201 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
202 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
203 read => 'install-test/packlist',
204 write => 'install-test/packlist'
205 },result=>\my %result]);
206 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
207 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
208 ok( -r 'install-test/packlist', ' packlist exists' );
210 skip "Times not preserved during copy by default", 1 if $^O eq 'VMS';
211 ok( (stat $tfile)[9]==(stat $sfile)[9],' Times are same');
213 ok( !$result{install_unchanged},' $result{install_unchanged} should be empty');
215 # Test nothing is copied.
217 local @INC = ('install-test/lib/perl');
218 local $ENV{PERL5LIB} = '';
219 local $ENV{EU_INSTALL_ALWAYS_COPY}=0;
220 my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
221 my $sfile='blib/lib/Big/Dummy.pm';
222 ok(-r $tfile,"install file already exists");
223 ok(-r $sfile,"source file already exists");
224 utime time-1200, time-1200, $sfile or die "utime '$sfile' failed:$!";
225 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
226 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
227 read => 'install-test/packlist',
228 write => 'install-test/packlist'
229 },result=>\my %result]);
230 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
231 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
232 ok( -r 'install-test/packlist', ' packlist exists' );
233 ok( (stat $tfile)[9]!=(stat$sfile)[9],' Times are different');
234 ok( !$result{install},' nothing should have been installed');
235 ok( $result{install_unchanged},' install_unchanged should be populated');