ExtUtils::MakeMaker 6.55_02
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / Install.t
1 #!/usr/bin/perl -w
2
3 # Test ExtUtils::Install.
4
5 BEGIN {
6     if( $ENV{PERL_CORE} ) {
7         @INC = ('../../lib', '../lib', 'lib');
8     }
9     else {
10         unshift @INC, 't/lib';
11     }
12 }
13 chdir 't';
14
15 use strict;
16 use TieOut;
17 use File::Path;
18 use File::Spec;
19
20 use Test::More tests => 52;
21
22 use MakeMaker::Test::Setup::BFD;
23
24 BEGIN { use_ok('ExtUtils::Install') }
25 # ensure the env doesnt pollute our tests
26 local $ENV{EU_INSTALL_ALWAYS_COPY};
27 local $ENV{EU_ALWAYS_COPY};    
28
29 # Check exports.
30 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
31     can_ok(__PACKAGE__, $func);
32 }
33
34
35 ok( setup_recurs(), 'setup' );
36 END {
37     ok( chdir File::Spec->updir );
38     ok( teardown_recurs(), 'teardown' );
39 }
40
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( { 'blib/lib' => 'install-test/lib/perl',
63            read   => 'install-test/packlist',
64            write  => 'install-test/packlist'
65          },
66        0, 1);
67 ok( ! -d 'install-test/lib/perl',        'install made dir (dry run)');
68 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
69                                          '  .pm file installed (dry run)');
70 ok( ! -r 'install-test/packlist',        '  packlist exists (dry run)');
71
72 install( { 'blib/lib' => 'install-test/lib/perl',
73            read   => 'install-test/packlist',
74            write  => 'install-test/packlist'
75          } );
76 ok( -d 'install-test/lib/perl',                 'install made dir' );
77 ok( -r 'install-test/lib/perl/Big/Dummy.pm',    '  .pm file installed' );
78 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP',  '  ignored .SKIP file' );
79 ok( -r 'install-test/packlist',                 '  packlist exists' );
80
81 open(PACKLIST, 'install-test/packlist' );
82 my %packlist = map { chomp;  ($_ => 1) } <PACKLIST>;
83 close PACKLIST;
84
85 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
86 # be lowercase. :(
87 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
88 is( keys %packlist, 1 );
89 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
90
91
92 # Test UNINST=1 preserving same versions in other dirs.
93 install( { 'blib/lib' => 'install-test/other_lib/perl',
94            read   => 'install-test/packlist',
95            write  => 'install-test/packlist'
96          },
97        0, 0, 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( { 'blib/lib' => 'install-test/other_lib/perl',
117            read   => 'install-test/packlist',
118            write  => 'install-test/packlist'
119          },
120        0, 0, 0);
121   ok( -d 'install-test/other_lib/perl',        'install made other dir' );
122   ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', '  .pm file installed' );
123   ok( -r 'install-test/packlist',              '  packlist exists' );
124   ok( -r 'install-test/lib/perl/Big/Dummy.pm',
125                                              '  UNINST=0 left different' );
126 }
127
128 # Test UNINST=1 only warning when failing to remove an irrelevent shadow file
129 {
130   my $tfile='install-test/lib/perl/Big/Dummy.pm';
131   local $ExtUtils::Install::Testing = $tfile; 
132   local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
133   local $ENV{PERL5LIB} = '';
134   ok( -r $tfile, 'different install exists' );
135   my @warn;
136   local $SIG{__WARN__}=sub { push @warn, @_; return };
137   my $ok=eval {
138     install( { 'blib/lib' => 'install-test/other_lib/perl',
139            read   => 'install-test/packlist',
140            write  => 'install-test/packlist'
141          },
142        0, 0, 1);
143     1
144   };
145   ok($ok,'  we didnt die');
146   ok(0+@warn,"  we did warn");
147   ok( -d 'install-test/other_lib/perl',        'install made other dir' );
148   ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', '  .pm file installed' );
149   ok( -r 'install-test/packlist',              '  packlist exists' );
150   ok( -r $tfile, '  UNINST=1 failed to remove different' );
151   
152 }
153
154 # Test UNINST=1 dieing when failing to remove an relevent shadow file
155 {
156   my $tfile='install-test/lib/perl/Big/Dummy.pm';
157   local $ExtUtils::Install::Testing = $tfile;
158   local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
159   local $ENV{PERL5LIB} = '';
160   ok( -r $tfile, 'different install exists' );
161   my @warn;
162   local $SIG{__WARN__}=sub { push @warn,@_; return };
163   my $ok=eval {
164     install( { 'blib/lib' => 'install-test/other_lib/perl',
165            read   => 'install-test/packlist',
166            write  => 'install-test/packlist'
167          },
168        0, 0, 1);
169     1
170   };
171   ok(!$ok,'  we did die');
172   ok(!@warn,"  we didnt warn");
173   ok( -d 'install-test/other_lib/perl',        'install made other dir' );
174   ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', '  .pm file installed' );
175   ok( -r 'install-test/packlist',              '  packlist exists' );
176   ok( -r $tfile,'  UNINST=1 failed to remove different' );
177 }
178
179 # Test UNINST=1 removing other versions in other dirs.
180 {
181   local @INC = ('install-test/lib/perl');
182   local $ENV{PERL5LIB} = '';
183   install( { 'blib/lib' => 'install-test/other_lib/perl',
184            read   => 'install-test/packlist',
185            write  => 'install-test/packlist'
186          },
187        0, 0, 1);
188   ok( -d 'install-test/other_lib/perl',        'install made other dir' );
189   ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', '  .pm file installed' );
190   ok( -r 'install-test/packlist',              '  packlist exists' );
191   ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
192                                              '  UNINST=1 removed different' );
193 }
194