3 # Test ExtUtils::Install.
6 if( $ENV{PERL_CORE} ) {
7 @INC = ('../../lib', '../lib', 'lib');
10 unshift @INC, 't/lib';
20 use Test::More tests => 70;
22 use MakeMaker::Test::Setup::BFD;
24 BEGIN { use_ok('ExtUtils::Install') }
27 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
28 can_ok(__PACKAGE__, $func);
32 ok( setup_recurs(), 'setup' );
34 ok( chdir File::Spec->updir );
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" );
51 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
54 ok( -d 'blib/lib', 'second run, blib dir still there' );
55 ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' );
56 ok( -r 'blib/lib/auto', ' autosplit still there' );
57 is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
60 from_to=>{ 'blib/lib' => 'install-test/lib/perl',
61 read => 'install-test/packlist',
62 write => 'install-test/packlist'
65 ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
66 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
67 ' .pm file installed (dry run)');
68 ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
70 install([ from_to=> { 'blib/lib' => 'install-test/lib/perl',
71 read => 'install-test/packlist',
72 write => 'install-test/packlist'
74 ok( -d 'install-test/lib/perl', 'install made dir' );
75 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
76 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
77 ok( -r 'install-test/packlist', ' packlist exists' );
79 open(PACKLIST, 'install-test/packlist' );
80 my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
83 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
85 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
86 is( keys %packlist, 1 );
87 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
90 # Test UNINST=1 preserving same versions in other dirs.
91 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
92 read => 'install-test/packlist',
93 write => 'install-test/packlist'
94 },uninstall_shadows=>1]);
95 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
96 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
97 ok( -r 'install-test/packlist', ' packlist exists' );
98 ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' );
101 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
102 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
103 print DUMMY "Extra stuff\n";
107 # Test UNINST=0 does not remove other versions in other dirs.
109 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
111 local @INC = ('install-test/lib/perl');
112 local $ENV{PERL5LIB} = '';
113 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
114 read => 'install-test/packlist',
115 write => 'install-test/packlist'
117 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
118 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
119 ok( -r 'install-test/packlist', ' packlist exists' );
120 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
121 ' UNINST=0 left different' );
124 # Test UNINST=1 only warning when failing to remove an irrelevent shadow file
126 my $tfile='install-test/lib/perl/Big/Dummy.pm';
127 local $ExtUtils::Install::Testing = $tfile;
128 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
129 local $ENV{PERL5LIB} = '';
130 ok( -r $tfile, 'different install exists' );
132 local $SIG{__WARN__}=sub { push @warn, @_; return };
134 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
135 read => 'install-test/packlist',
136 write => 'install-test/packlist'
138 uninstall_shadows=>1]);
141 ok($ok,' we didnt die');
142 ok(0+@warn," we did warn");
143 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
144 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
145 ok( -r 'install-test/packlist', ' packlist exists' );
146 ok( -r $tfile, ' UNINST=1 failed to remove different' );
150 # Test UNINST=1 dieing when failing to remove an relevent shadow file
152 my $tfile='install-test/lib/perl/Big/Dummy.pm';
153 local $ExtUtils::Install::Testing = $tfile;
154 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
155 local $ENV{PERL5LIB} = '';
156 ok( -r $tfile, 'different install exists' );
158 local $SIG{__WARN__}=sub { push @warn,@_; return };
160 install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl',
161 read => 'install-test/packlist',
162 write => 'install-test/packlist'
163 },uninstall_shadows=>1]);
166 ok(!$ok,' we did die');
167 ok(!@warn," we didnt warn");
168 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
169 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
170 ok( -r 'install-test/packlist', ' packlist exists' );
171 ok( -r $tfile,' UNINST=1 failed to remove different' );
174 # Test UNINST=1 removing other versions in other dirs.
176 local @INC = ('install-test/lib/perl');
177 local $ENV{PERL5LIB} = '';
178 ok( -r 'install-test/lib/perl/Big/Dummy.pm','different install exists' );
179 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
180 read => 'install-test/packlist',
181 write => 'install-test/packlist'
182 },uninstall_shadows=>1]);
183 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
184 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
185 ok( -r 'install-test/packlist', ' packlist exists' );
186 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
187 ' UNINST=1 removed different' );
190 # Test EU_ALWAYS_COPY triggers copy.
192 local @INC = ('install-test/lib/perl');
193 local $ENV{PERL5LIB} = '';
194 local $ENV{EU_ALWAYS_COPY}=1;
195 my $tfile='install-test/other_lib/perl/Big/Dummy.pm';
196 my $sfile='blib/lib/Big/Dummy.pm';
197 ok(-r $tfile,"install file already exists");
198 ok(-r $sfile,"source file already exists");
199 utime time-600, time-600, $sfile or die "utime '$sfile' failed:$!";
200 ok( (stat $tfile)[9]!=(stat $sfile)[9],' Times are different');
201 install([from_to=>{ 'blib/lib' => 'install-test/other_lib/perl',
202 read => 'install-test/packlist',
203 write => 'install-test/packlist'
204 },result=>\my %result]);
205 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
206 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
207 ok( -r 'install-test/packlist', ' packlist exists' );
208 ok( (stat $tfile)[9]==(stat$sfile)[9],' Times are same');
209 ok( !$result{install_unchanged},' $result{install_unchanged} should be empty');
211 # Test nothing is copied.
213 local @INC = ('install-test/lib/perl');
214 local $ENV{PERL5LIB} = '';
215 local $ENV{EU_ALWAYS_COPY}=0;
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');