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 my $stdout = tie *STDOUT, 'TieOut';
41 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
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" );
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 install( { '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( { '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( { 'blib/lib' => 'install-test/other_lib/perl',
93 read => 'install-test/packlist',
94 write => 'install-test/packlist'
97 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
98 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
99 ok( -r 'install-test/packlist', ' packlist exists' );
100 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
103 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
104 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
105 print DUMMY "Extra stuff\n";
109 # Test UNINST=0 does not remove other versions in other dirs.
111 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
113 local @INC = ('install-test/lib/perl');
114 local $ENV{PERL5LIB} = '';
115 install( { 'blib/lib' => 'install-test/other_lib/perl',
116 read => 'install-test/packlist',
117 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 irrelevant 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( { 'blib/lib' => 'install-test/other_lib/perl',
138 read => 'install-test/packlist',
139 write => 'install-test/packlist'
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 relevant 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( { 'blib/lib' => 'install-test/other_lib/perl',
164 read => 'install-test/packlist',
165 write => 'install-test/packlist'
170 ok(!$ok,' we did die');
171 ok(!@warn," we didnt warn");
172 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
173 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
174 ok( -r 'install-test/packlist', ' packlist exists' );
175 ok( -r $tfile,' UNINST=1 failed to remove different' );
178 # Test UNINST=1 removing other versions in other dirs.
180 local @INC = ('install-test/lib/perl');
181 local $ENV{PERL5LIB} = '';
182 install( { 'blib/lib' => 'install-test/other_lib/perl',
183 read => 'install-test/packlist',
184 write => 'install-test/packlist'
187 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
188 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
189 ok( -r 'install-test/packlist', ' packlist exists' );
190 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
191 ' UNINST=1 removed different' );
195 # really this test should be run on any platform that supports
196 # symbolic and hard links, but this representative sample should do for
200 # check hard and symbolic links
204 $^O =~ /^(aix|bsdos|darwin|freebsd|hpux|irix|linux|openbsd|solaris)$/;
205 skip "(sym)links not supported", 8 unless $has_links;
207 install([ from_to => { 'blib/lib/' => 'install-links',
208 read => 'install-links/packlist',
209 write => 'install-links/packlist'
213 # make orig file a hard link and check that it doesn't get messed up
215 my $bigdir = 'install-links/Big';
216 ok link("$bigdir/Dummy.pm", "$bigdir/DummyHard.pm"),
219 open(my $fh, ">>", "blib/lib/Big/Dummy.pm") or die $!;
220 print $fh "Extra stuff 2\n";
223 install([ from_to => { 'blib/lib/' => 'install-links',
224 read => 'install-links/packlist',
225 write => 'install-links/packlist'
230 skip 'everywhere is writable to root', 1 if $> == 0;
231 ok( !-w "$bigdir/DummyHard.pm", 'DummyHard.pm not writeable' );
235 ok(compare("$bigdir/Dummy.pm", "$bigdir/DummyHard.pm"),
236 "hard-linked file should be different");
238 # make orig file a symlink and check that it doesn't get messed up
240 ok rename("$bigdir/Dummy.pm", "$bigdir/DummyOrig.pm"),
241 'rename DummyOrig.pm';
242 ok symlink('DummyOrig.pm', "$bigdir/Dummy.pm"),
246 open($fh, ">>", "blib/lib/Big/Dummy.pm") or die $!;
247 print $fh "Extra stuff 3\n";
250 install([ from_to => { 'blib/lib/' => 'install-links',
251 read => 'install-links/packlist',
252 write => 'install-links/packlist'
257 skip 'everywhere is writable to root', 1 if $> == 0;
258 ok( !-w "$bigdir/DummyOrig.pm", 'DummyOrig.pm not writeable' );
260 ok( !-l "$bigdir/Dummy.pm", 'Dummy.pm not a link' );
261 ok(compare("$bigdir/Dummy.pm", "$bigdir/DummyOrig.pm"),
262 "orig file should be different");