Cannot portably split on $Config{path_sep} -- use quotemeta($Config{path_sep}).
[p5sagit/p5-mst-13.2.git] / dist / ExtUtils-Install / t / Installapi2.t
CommitLineData
546acaf9 1#!/usr/bin/perl -w
2
3# Test ExtUtils::Install.
4
5BEGIN {
fb78ba4b 6 unshift @INC, 't/lib';
546acaf9 7}
546acaf9 8
9use strict;
10use TieOut;
11use File::Path;
12use File::Spec;
13
14use Test::More tests => 70;
15
16use MakeMaker::Test::Setup::BFD;
17
18BEGIN { use_ok('ExtUtils::Install') }
19
20# Check exports.
21foreach my $func (qw(install uninstall pm_to_blib install_default)) {
22 can_ok(__PACKAGE__, $func);
23}
24
25
26ok( setup_recurs(), 'setup' );
27END {
28 ok( chdir File::Spec->updir );
29 ok( teardown_recurs(), 'teardown' );
30}
3f6d40bd 31# ensure the env doesnt pollute our tests
32local $ENV{EU_INSTALL_ALWAYS_COPY};
33local $ENV{EU_ALWAYS_COPY};
34
546acaf9 35chdir 'Big-Dummy';
36
37my $stdout = tie *STDOUT, 'TieOut';
38pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
39 'blib/lib/auto'
40 );
41END { rmtree 'blib' }
42
43ok( -d 'blib/lib', 'pm_to_blib created blib dir' );
44ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' );
45ok( -r 'blib/lib/auto', ' created autosplit dir' );
46is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" );
47
48pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
49 'blib/lib/auto'
50 );
51ok( -d 'blib/lib', 'second run, blib dir still there' );
52ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' );
53ok( -r 'blib/lib/auto', ' autosplit still there' );
54is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
55
56install( [
57 from_to=>{ 'blib/lib' => 'install-test/lib/perl',
58 read => 'install-test/packlist',
59 write => 'install-test/packlist'
60 },
61 dry_run=>1]);
62ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
63ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
64 ' .pm file installed (dry run)');
65ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
66
67install([ from_to=> { 'blib/lib' => 'install-test/lib/perl',
68 read => 'install-test/packlist',
69 write => 'install-test/packlist'
70 } ]);
71ok( -d 'install-test/lib/perl', 'install made dir' );
72ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
73ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
74ok( -r 'install-test/packlist', ' packlist exists' );
75
76open(PACKLIST, 'install-test/packlist' );
77my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
78close PACKLIST;
79
80# On case-insensitive filesystems (ie. VMS), the keys of the packlist might
81# be lowercase. :(
82my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
83is( keys %packlist, 1 );
84is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
85
86
87# Test UNINST=1 preserving same versions in other dirs.
88install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
89 read => 'install-test/packlist',
90 write => 'install-test/packlist'
91 },uninstall_shadows=>1]);
92ok( -d 'install-test/other_lib/perl', 'install made other dir' );
93ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
94ok( -r 'install-test/packlist', ' packlist exists' );
95ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
96
97
98chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
99open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
100print DUMMY "Extra stuff\n";
101close DUMMY;
102
103
104# Test UNINST=0 does not remove other versions in other dirs.
105{
106 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
107
108 local @INC = ('install-test/lib/perl');
109 local $ENV{PERL5LIB} = '';
110 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
111 read => 'install-test/packlist',
112 write => 'install-test/packlist'
113 }]);
114 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
115 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
116 ok( -r 'install-test/packlist', ' packlist exists' );
117 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
118 ' UNINST=0 left different' );
119}
120
121# Test UNINST=1 only warning when failing to remove an irrelevent shadow file
122{
123 my $tfile='install-test/lib/perl/Big/Dummy.pm';
124 local $ExtUtils::Install::Testing = $tfile;
125 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
126 local $ENV{PERL5LIB} = '';
127 ok( -r $tfile, 'different install exists' );
128 my @warn;
129 local $SIG{__WARN__}=sub { push @warn, @_; return };
130 my $ok=eval {
131 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
132 read => 'install-test/packlist',
133 write => 'install-test/packlist'
134 },
135 uninstall_shadows=>1]);
136 1
137 };
138 ok($ok,' we didnt die');
139 ok(0+@warn," we did warn");
140 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
141 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
142 ok( -r 'install-test/packlist', ' packlist exists' );
143 ok( -r $tfile, ' UNINST=1 failed to remove different' );
144
145}
146
147# Test UNINST=1 dieing when failing to remove an relevent shadow file
148{
149 my $tfile='install-test/lib/perl/Big/Dummy.pm';
150 local $ExtUtils::Install::Testing = $tfile;
151 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
152 local $ENV{PERL5LIB} = '';
153 ok( -r $tfile, 'different install exists' );
154 my @warn;
155 local $SIG{__WARN__}=sub { push @warn,@_; return };
156 my $ok=eval {
157 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
158 read => 'install-test/packlist',
159 write => 'install-test/packlist'
160 },uninstall_shadows=>1]);
161 1
162 };
163 ok(!$ok,' we did die');
164 ok(!@warn," we didnt warn");
165 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
166 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
167 ok( -r 'install-test/packlist', ' packlist exists' );
168 ok( -r $tfile,' UNINST=1 failed to remove different' );
169}
170
171# Test UNINST=1 removing other versions in other dirs.
172{
173 local @INC = ('install-test/lib/perl');
174 local $ENV{PERL5LIB} = '';
175 ok( -r 'install-test/lib/perl/Big/Dummy.pm','different install exists' );
176 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
177 read => 'install-test/packlist',
178 write => 'install-test/packlist'
179 },uninstall_shadows=>1]);
180 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
181 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
182 ok( -r 'install-test/packlist', ' packlist exists' );
183 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
184 ' UNINST=1 removed different' );
185}
186
187# Test EU_ALWAYS_COPY triggers copy.
188{
189 local @INC = ('install-test/lib/perl');
190 local $ENV{PERL5LIB} = '';
3f6d40bd 191 local $ENV{EU_INSTALL_ALWAYS_COPY}=1;
546acaf9 192 my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
193 my $sfile='blib/lib/Big/Dummy.pm';
194 ok(-r $tfile,"install file already exists");
195 ok(-r $sfile,"source file already exists");
196 utime time-600, time-600, $sfile or die "utime '$sfile' failed:$!";
197 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
198 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
199 read => 'install-test/packlist',
200 write => 'install-test/packlist'
201 },result=>\my %result]);
202 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
203 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
204 ok( -r 'install-test/packlist', ' packlist exists' );
553b5000 205SKIP: {
206 skip "Times not preserved during copy by default", 1 if $^O eq 'VMS';
207 ok( (stat $tfile)[9]==(stat $sfile)[9],' Times are same');
208}
546acaf9 209 ok( !$result{install_unchanged},' $result{install_unchanged} should be empty');
210}
211# Test nothing is copied.
212{
213 local @INC = ('install-test/lib/perl');
214 local $ENV{PERL5LIB} = '';
3f6d40bd 215 local $ENV{EU_INSTALL_ALWAYS_COPY}=0;
546acaf9 216 my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
217 my $sfile='blib/lib/Big/Dummy.pm';
218 ok(-r $tfile,"install file already exists");
219 ok(-r $sfile,"source file already exists");
220 utime time-1200, time-1200, $sfile or die "utime '$sfile' failed:$!";
221 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
222 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
223 read => 'install-test/packlist',
224 write => 'install-test/packlist'
225 },result=>\my %result]);
226 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
227 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
228 ok( -r 'install-test/packlist', ' packlist exists' );
229 ok( (stat $tfile)[9]!=(stat$sfile)[9],' Times are different');
230 ok( !$result{install},' nothing should have been installed');
231 ok( $result{install_unchanged},' install_unchanged should be populated');
553b5000 232}