This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor porting/diag.t and improve output format
[perl5.git] / dist / ExtUtils-Install / t / Install.t
CommitLineData
479d2113
MS
1#!/usr/bin/perl -w
2
3# Test ExtUtils::Install.
4
5BEGIN {
fb78ba4b 6 unshift @INC, 't/lib';
479d2113 7}
479d2113
MS
8
9use strict;
10use TieOut;
11use File::Path;
12use File::Spec;
13
f6d658cc 14use Test::More tests => 52;
a7d1454b
RGS
15
16use MakeMaker::Test::Setup::BFD;
479d2113
MS
17
18BEGIN { use_ok('ExtUtils::Install') }
3f6d40bd
SH
19# ensure the env doesnt pollute our tests
20local $ENV{EU_INSTALL_ALWAYS_COPY};
21local $ENV{EU_ALWAYS_COPY};
479d2113
MS
22
23# Check exports.
24foreach my $func (qw(install uninstall pm_to_blib install_default)) {
25 can_ok(__PACKAGE__, $func);
26}
27
28
a7d1454b
RGS
29ok( setup_recurs(), 'setup' );
30END {
31 ok( chdir File::Spec->updir );
32 ok( teardown_recurs(), 'teardown' );
33}
34
479d2113
MS
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 );
1df8d179
MS
41END { rmtree 'blib' }
42
479d2113
MS
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
ab00ffcd
SR
56install( { 'blib/lib' => 'install-test/lib/perl',
57 read => 'install-test/packlist',
58 write => 'install-test/packlist'
59 },
60 0, 1);
2530b651
MS
61ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)');
62ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
63 ' .pm file installed (dry run)');
64ok( ! -r 'install-test/packlist', ' packlist exists (dry run)');
479d2113
MS
65
66install( { 'blib/lib' => 'install-test/lib/perl',
67 read => 'install-test/packlist',
68 write => 'install-test/packlist'
69 } );
70ok( -d 'install-test/lib/perl', 'install made dir' );
71ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' );
3a465856 72ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' );
479d2113
MS
73ok( -r 'install-test/packlist', ' packlist exists' );
74
75open(PACKLIST, 'install-test/packlist' );
76my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
77close PACKLIST;
78
3a465856 79# On case-insensitive filesystems (ie. VMS), the keys of the packlist might
479d2113
MS
80# be lowercase. :(
81my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
82is( keys %packlist, 1 );
83is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
84
1df8d179
MS
85
86# Test UNINST=1 preserving same versions in other dirs.
87install( { 'blib/lib' => 'install-test/other_lib/perl',
88 read => 'install-test/packlist',
89 write => 'install-test/packlist'
90 },
91 0, 0, 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
1df8d179
MS
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
fef074f7
RGS
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( { 'blib/lib' => 'install-test/other_lib/perl',
111 read => 'install-test/packlist',
112 write => 'install-test/packlist'
113 },
114 0, 0, 0);
115 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
116 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
117 ok( -r 'install-test/packlist', ' packlist exists' );
118 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
119 ' UNINST=0 left different' );
120}
121
f6d658cc
YO
122# Test UNINST=1 only warning when failing to remove an irrelevent shadow file
123{
124 my $tfile='install-test/lib/perl/Big/Dummy.pm';
125 local $ExtUtils::Install::Testing = $tfile;
126 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
127 local $ENV{PERL5LIB} = '';
128 ok( -r $tfile, 'different install exists' );
129 my @warn;
130 local $SIG{__WARN__}=sub { push @warn, @_; return };
131 my $ok=eval {
132 install( { 'blib/lib' => 'install-test/other_lib/perl',
133 read => 'install-test/packlist',
134 write => 'install-test/packlist'
135 },
136 0, 0, 1);
137 1
138 };
139 ok($ok,' we didnt die');
140 ok(0+@warn," we did warn");
141 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
142 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
143 ok( -r 'install-test/packlist', ' packlist exists' );
144 ok( -r $tfile, ' UNINST=1 failed to remove different' );
145
146}
147
148# Test UNINST=1 dieing when failing to remove an relevent shadow file
149{
150 my $tfile='install-test/lib/perl/Big/Dummy.pm';
151 local $ExtUtils::Install::Testing = $tfile;
152 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
153 local $ENV{PERL5LIB} = '';
154 ok( -r $tfile, 'different install exists' );
155 my @warn;
156 local $SIG{__WARN__}=sub { push @warn,@_; return };
157 my $ok=eval {
158 install( { 'blib/lib' => 'install-test/other_lib/perl',
159 read => 'install-test/packlist',
160 write => 'install-test/packlist'
161 },
162 0, 0, 1);
163 1
164 };
165 ok(!$ok,' we did die');
166 ok(!@warn," we didnt warn");
167 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
168 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
169 ok( -r 'install-test/packlist', ' packlist exists' );
170 ok( -r $tfile,' UNINST=1 failed to remove different' );
171}
fef074f7
RGS
172
173# Test UNINST=1 removing other versions in other dirs.
1df8d179
MS
174{
175 local @INC = ('install-test/lib/perl');
176 local $ENV{PERL5LIB} = '';
177 install( { 'blib/lib' => 'install-test/other_lib/perl',
178 read => 'install-test/packlist',
179 write => 'install-test/packlist'
180 },
181 0, 0, 1);
182 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
183 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
184 ok( -r 'install-test/packlist', ' packlist exists' );
185 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
186 ' UNINST=1 removed different' );
187}
f6d658cc 188