3 # Test ExtUtils::Install.
13 use File::Temp qw[tempdir];
15 use Test::More tests => 60;
17 use MakeMaker::Test::Setup::BFD;
19 BEGIN { use_ok('ExtUtils::Install') }
20 # ensure the env doesn't pollute our tests
21 local $ENV{EU_INSTALL_ALWAYS_COPY};
22 local $ENV{EU_ALWAYS_COPY};
25 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
26 can_ok(__PACKAGE__, $func);
29 my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
32 ok( setup_recurs(), 'setup' );
34 ok( chdir File::Spec->updir, 'chdir ..');
35 ok( teardown_recurs(), 'teardown' );
40 local $ENV{PERL_INSTALL_QUIET};
42 my $stdout = tie *STDOUT, 'TieOut';
43 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
48 ok( -d 'blib/lib', 'pm_to_blib created blib dir' );
49 ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' );
50 ok( -r 'blib/lib/auto', ' created autosplit dir' );
51 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 install( { '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( { '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( { 'blib/lib' => 'install-test/other_lib/perl',
95 read => 'install-test/packlist',
96 write => 'install-test/packlist'
99 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
100 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
101 ok( -r 'install-test/packlist', ' packlist exists' );
102 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
105 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
106 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
107 print DUMMY "Extra stuff\n";
111 # Test UNINST=0 does not remove other versions in other dirs.
113 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
115 local @INC = ('install-test/lib/perl');
116 local $ENV{PERL5LIB} = '';
117 install( { 'blib/lib' => 'install-test/other_lib/perl',
118 read => 'install-test/packlist',
119 write => 'install-test/packlist'
122 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
123 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
124 ok( -r 'install-test/packlist', ' packlist exists' );
125 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
126 ' UNINST=0 left different' );
129 # Test UNINST=1 only warning when failing to remove an irrelevant shadow file
131 my $tfile='install-test/lib/perl/Big/Dummy.pm';
132 local $ExtUtils::Install::Testing = $tfile;
133 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
134 local $ENV{PERL5LIB} = '';
135 ok( -r $tfile, 'different install exists' );
137 local $SIG{__WARN__}=sub { push @warn, @_; return };
139 install( { 'blib/lib' => 'install-test/other_lib/perl',
140 read => 'install-test/packlist',
141 write => 'install-test/packlist'
146 ok($ok,' we didnt die');
147 ok(0+@warn," we did warn");
148 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
149 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
150 ok( -r 'install-test/packlist', ' packlist exists' );
151 ok( -r $tfile, ' UNINST=1 failed to remove different' );
155 # Test UNINST=1 dieing when failing to remove an relevant shadow file
157 my $tfile='install-test/lib/perl/Big/Dummy.pm';
158 local $ExtUtils::Install::Testing = $tfile;
159 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
160 local $ENV{PERL5LIB} = '';
161 ok( -r $tfile, 'different install exists' );
163 local $SIG{__WARN__}=sub { push @warn,@_; return };
165 install( { 'blib/lib' => 'install-test/other_lib/perl',
166 read => 'install-test/packlist',
167 write => 'install-test/packlist'
172 ok(!$ok,' we did die');
173 ok(!@warn," we didnt warn");
174 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
175 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
176 ok( -r 'install-test/packlist', ' packlist exists' );
177 ok( -r $tfile,' UNINST=1 failed to remove different' );
180 # Test UNINST=1 removing other versions in other dirs.
182 local @INC = ('install-test/lib/perl');
183 local $ENV{PERL5LIB} = '';
184 install( { 'blib/lib' => 'install-test/other_lib/perl',
185 read => 'install-test/packlist',
186 write => 'install-test/packlist'
189 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
190 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
191 ok( -r 'install-test/packlist', ' packlist exists' );
192 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
193 ' UNINST=1 removed different' );
197 # do a -w style test, but based on just on file perms rather than UID
198 # (on UNIX, root sees everything as writeable)
202 my @stat = stat $file;
203 return 0 unless defined $stat[2]; # mode
204 return $stat[2] & 0200;
208 # really this test should be run on any platform that supports
209 # symbolic and hard links, but this representative sample should do for
213 # check hard and symbolic links
217 $^O =~ /^(aix|bsdos|darwin|freebsd|hpux|irix|linux|openbsd|solaris)$/;
218 skip "(sym)links not supported", 8 unless $has_links;
220 install([ from_to => { 'blib/lib/' => 'install-links',
221 read => 'install-links/packlist',
222 write => 'install-links/packlist'
226 # make orig file a hard link and check that it doesn't get messed up
228 my $bigdir = 'install-links/Big';
229 ok link("$bigdir/Dummy.pm", "$bigdir/DummyHard.pm"),
232 open(my $fh, ">>", "blib/lib/Big/Dummy.pm") or die $!;
233 print $fh "Extra stuff 2\n";
236 install([ from_to => { 'blib/lib/' => 'install-links',
237 read => 'install-links/packlist',
238 write => 'install-links/packlist'
242 ok( !writeable("$bigdir/DummyHard.pm"), 'DummyHard.pm not writeable' );
245 ok(compare("$bigdir/Dummy.pm", "$bigdir/DummyHard.pm"),
246 "hard-linked file should be different");
248 # make orig file a symlink and check that it doesn't get messed up
250 ok rename("$bigdir/Dummy.pm", "$bigdir/DummyOrig.pm"),
251 'rename DummyOrig.pm';
252 ok symlink('DummyOrig.pm', "$bigdir/Dummy.pm"),
256 open($fh, ">>", "blib/lib/Big/Dummy.pm") or die $!;
257 print $fh "Extra stuff 3\n";
260 install([ from_to => { 'blib/lib/' => 'install-links',
261 read => 'install-links/packlist',
262 write => 'install-links/packlist'
266 ok( !writeable("$bigdir/DummyOrig.pm"), 'DummyOrig.pm not writeable' );
267 ok( !-l "$bigdir/Dummy.pm", 'Dummy.pm not a link' );
268 ok(compare("$bigdir/Dummy.pm", "$bigdir/DummyOrig.pm"),
269 "orig file should be different");