3 # Test ExtUtils::Install.
13 use File::Temp qw[tempdir];
15 use Test::More tests => 60;
17 use MakeMaker::Test::Setup::BFD;
20 local $ENV{PERL_INSTALL_QUIET};
21 use_ok('ExtUtils::Install');
23 # ensure the env doesn't pollute our tests
24 local $ENV{EU_INSTALL_ALWAYS_COPY};
25 local $ENV{EU_ALWAYS_COPY};
28 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
29 can_ok(__PACKAGE__, $func);
32 my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
35 ok( setup_recurs(), 'setup' );
37 ok( chdir File::Spec->updir, 'chdir ..');
38 ok( teardown_recurs(), 'teardown' );
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" );
55 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
58 ok( -d 'blib/lib', 'second run, blib dir still there' );
59 ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' );
60 ok( -r 'blib/lib/auto', ' autosplit still there' );
61 is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
64 install( { 'blib/lib' => 'install-test/lib/perl',
65 read => 'install-test/packlist',
66 write => 'install-test/packlist'
69 ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
70 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
71 ' .pm file installed (dry run)');
72 ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
74 install( { 'blib/lib' => 'install-test/lib/perl',
75 read => 'install-test/packlist',
76 write => 'install-test/packlist'
78 ok( -d 'install-test/lib/perl', 'install made dir' );
79 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
80 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
81 ok( -r 'install-test/packlist', ' packlist exists' );
83 open(PACKLIST, 'install-test/packlist' );
84 my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
87 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
89 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
90 is( keys %packlist, 1 );
91 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
94 # Test UNINST=1 preserving same versions in other dirs.
95 install( { 'blib/lib' => 'install-test/other_lib/perl',
96 read => 'install-test/packlist',
97 write => 'install-test/packlist'
100 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
101 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
102 ok( -r 'install-test/packlist', ' packlist exists' );
103 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
106 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
107 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
108 print DUMMY "Extra stuff\n";
112 # Test UNINST=0 does not remove other versions in other dirs.
114 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
116 local @INC = ('install-test/lib/perl');
117 local $ENV{PERL5LIB} = '';
118 install( { 'blib/lib' => 'install-test/other_lib/perl',
119 read => 'install-test/packlist',
120 write => 'install-test/packlist'
123 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
124 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
125 ok( -r 'install-test/packlist', ' packlist exists' );
126 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
127 ' UNINST=0 left different' );
130 # Test UNINST=1 only warning when failing to remove an irrelevant shadow file
132 my $tfile='install-test/lib/perl/Big/Dummy.pm';
133 local $ExtUtils::Install::Testing = $tfile;
134 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
135 local $ENV{PERL5LIB} = '';
136 ok( -r $tfile, 'different install exists' );
138 local $SIG{__WARN__}=sub { push @warn, @_; return };
140 install( { 'blib/lib' => 'install-test/other_lib/perl',
141 read => 'install-test/packlist',
142 write => 'install-test/packlist'
147 ok($ok,' we didnt die');
148 ok(0+@warn," we did warn");
149 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
150 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
151 ok( -r 'install-test/packlist', ' packlist exists' );
152 ok( -r $tfile, ' UNINST=1 failed to remove different' );
156 # Test UNINST=1 dieing when failing to remove an relevant shadow file
158 my $tfile='install-test/lib/perl/Big/Dummy.pm';
159 local $ExtUtils::Install::Testing = $tfile;
160 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
161 local $ENV{PERL5LIB} = '';
162 ok( -r $tfile, 'different install exists' );
164 local $SIG{__WARN__}=sub { push @warn,@_; return };
166 install( { 'blib/lib' => 'install-test/other_lib/perl',
167 read => 'install-test/packlist',
168 write => 'install-test/packlist'
173 ok(!$ok,' we did die');
174 ok(!@warn," we didnt warn");
175 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
176 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
177 ok( -r 'install-test/packlist', ' packlist exists' );
178 ok( -r $tfile,' UNINST=1 failed to remove different' );
181 # Test UNINST=1 removing other versions in other dirs.
183 local @INC = ('install-test/lib/perl');
184 local $ENV{PERL5LIB} = '';
185 install( { 'blib/lib' => 'install-test/other_lib/perl',
186 read => 'install-test/packlist',
187 write => 'install-test/packlist'
190 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
191 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
192 ok( -r 'install-test/packlist', ' packlist exists' );
193 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
194 ' UNINST=1 removed different' );
198 # do a -w style test, but based on just on file perms rather than UID
199 # (on UNIX, root sees everything as writeable)
203 my @stat = stat $file;
204 return 0 unless defined $stat[2]; # mode
205 return $stat[2] & 0200;
209 # really this test should be run on any platform that supports
210 # symbolic and hard links, but this representative sample should do for
214 # check hard and symbolic links
218 $^O =~ /^(aix|bsdos|darwin|freebsd|hpux|irix|linux|openbsd|solaris)$/;
219 skip "(sym)links not supported", 8 unless $has_links;
221 install([ from_to => { 'blib/lib/' => 'install-links',
222 read => 'install-links/packlist',
223 write => 'install-links/packlist'
227 # make orig file a hard link and check that it doesn't get messed up
229 my $bigdir = 'install-links/Big';
230 ok link("$bigdir/Dummy.pm", "$bigdir/DummyHard.pm"),
233 open(my $fh, ">>", "blib/lib/Big/Dummy.pm") or die $!;
234 print $fh "Extra stuff 2\n";
237 install([ from_to => { 'blib/lib/' => 'install-links',
238 read => 'install-links/packlist',
239 write => 'install-links/packlist'
243 ok( !writeable("$bigdir/DummyHard.pm"), 'DummyHard.pm not writeable' );
246 ok(compare("$bigdir/Dummy.pm", "$bigdir/DummyHard.pm"),
247 "hard-linked file should be different");
249 # make orig file a symlink and check that it doesn't get messed up
251 ok rename("$bigdir/Dummy.pm", "$bigdir/DummyOrig.pm"),
252 'rename DummyOrig.pm';
253 ok symlink('DummyOrig.pm', "$bigdir/Dummy.pm"),
257 open($fh, ">>", "blib/lib/Big/Dummy.pm") or die $!;
258 print $fh "Extra stuff 3\n";
261 install([ from_to => { 'blib/lib/' => 'install-links',
262 read => 'install-links/packlist',
263 write => 'install-links/packlist'
267 ok( !writeable("$bigdir/DummyOrig.pm"), 'DummyOrig.pm not writeable' );
268 ok( !-l "$bigdir/Dummy.pm", 'Dummy.pm not a link' );
269 ok(compare("$bigdir/Dummy.pm", "$bigdir/DummyOrig.pm"),
270 "orig file should be different");