Commit | Line | Data |
546acaf9 |
1 | #!/usr/bin/perl -w |
2 | |
3 | # Test ExtUtils::Install. |
4 | |
5 | BEGIN { |
fb78ba4b |
6 | unshift @INC, 't/lib'; |
546acaf9 |
7 | } |
546acaf9 |
8 | |
9 | use strict; |
10 | use TieOut; |
11 | use File::Path; |
12 | use File::Spec; |
13 | |
14 | use Test::More tests => 70; |
15 | |
16 | use MakeMaker::Test::Setup::BFD; |
17 | |
18 | BEGIN { use_ok('ExtUtils::Install') } |
19 | |
20 | # Check exports. |
21 | foreach my $func (qw(install uninstall pm_to_blib install_default)) { |
22 | can_ok(__PACKAGE__, $func); |
23 | } |
24 | |
25 | |
26 | ok( setup_recurs(), 'setup' ); |
27 | END { |
28 | ok( chdir File::Spec->updir ); |
29 | ok( teardown_recurs(), 'teardown' ); |
30 | } |
3f6d40bd |
31 | # ensure the env doesnt pollute our tests |
32 | local $ENV{EU_INSTALL_ALWAYS_COPY}; |
33 | local $ENV{EU_ALWAYS_COPY}; |
34 | |
546acaf9 |
35 | chdir 'Big-Dummy'; |
36 | |
37 | my $stdout = tie *STDOUT, 'TieOut'; |
38 | pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' }, |
39 | 'blib/lib/auto' |
40 | ); |
41 | END { rmtree 'blib' } |
42 | |
43 | ok( -d 'blib/lib', 'pm_to_blib created blib dir' ); |
44 | ok( -r 'blib/lib/Big/Dummy.pm', ' copied .pm file' ); |
45 | ok( -r 'blib/lib/auto', ' created autosplit dir' ); |
46 | is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" ); |
47 | |
48 | pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' }, |
49 | 'blib/lib/auto' |
50 | ); |
51 | ok( -d 'blib/lib', 'second run, blib dir still there' ); |
52 | ok( -r 'blib/lib/Big/Dummy.pm', ' .pm file still there' ); |
53 | ok( -r 'blib/lib/auto', ' autosplit still there' ); |
54 | is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" ); |
55 | |
56 | install( [ |
57 | from_to=>{ 'blib/lib' => 'install-test/lib/perl', |
58 | read => 'install-test/packlist', |
59 | write => 'install-test/packlist' |
60 | }, |
61 | dry_run=>1]); |
62 | ok( ! -d 'install-test/lib/perl', 'install made dir (dry run)'); |
63 | ok( ! -r 'install-test/lib/perl/Big/Dummy.pm', |
64 | ' .pm file installed (dry run)'); |
65 | ok( ! -r 'install-test/packlist', ' packlist exists (dry run)'); |
66 | |
67 | install([ from_to=> { 'blib/lib' => 'install-test/lib/perl', |
68 | read => 'install-test/packlist', |
69 | write => 'install-test/packlist' |
70 | } ]); |
71 | ok( -d 'install-test/lib/perl', 'install made dir' ); |
72 | ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' .pm file installed' ); |
73 | ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP', ' ignored .SKIP file' ); |
74 | ok( -r 'install-test/packlist', ' packlist exists' ); |
75 | |
76 | open(PACKLIST, 'install-test/packlist' ); |
77 | my %packlist = map { chomp; ($_ => 1) } <PACKLIST>; |
78 | close PACKLIST; |
79 | |
80 | # On case-insensitive filesystems (ie. VMS), the keys of the packlist might |
81 | # be lowercase. :( |
82 | my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm)); |
83 | is( keys %packlist, 1 ); |
84 | is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' ); |
85 | |
86 | |
87 | # Test UNINST=1 preserving same versions in other dirs. |
88 | install([from_to=> { 'blib/lib' => 'install-test/other_lib/perl', |
89 | read => 'install-test/packlist', |
90 | write => 'install-test/packlist' |
91 | },uninstall_shadows=>1]); |
92 | ok( -d 'install-test/other_lib/perl', 'install made other dir' ); |
93 | ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' ); |
94 | ok( -r 'install-test/packlist', ' packlist exists' ); |
95 | ok( -r 'install-test/lib/perl/Big/Dummy.pm', ' UNINST=1 preserved same' ); |
96 | |
97 | |
98 | chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!; |
99 | open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!; |
100 | print DUMMY "Extra stuff\n"; |
101 | close 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 |
205 | SKIP: { |
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 | } |