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