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
1 #!/usr/bin/perl -w
2
3 # Test ExtUtils::Install.
4
5 BEGIN {
6     unshift @INC, 't/lib';
7 }
8
9 use strict;
10 use TieOut;
11 use File::Path;
12 use File::Spec;
13
14 use Test::More tests => 52;
15
16 use MakeMaker::Test::Setup::BFD;
17
18 BEGIN { use_ok('ExtUtils::Install') }
19 # ensure the env doesnt pollute our tests
20 local $ENV{EU_INSTALL_ALWAYS_COPY};
21 local $ENV{EU_ALWAYS_COPY};    
22
23 # Check exports.
24 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
25     can_ok(__PACKAGE__, $func);
26 }
27
28
29 ok( setup_recurs(), 'setup' );
30 END {
31     ok( chdir File::Spec->updir );
32     ok( teardown_recurs(), 'teardown' );
33 }
34
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( { 'blib/lib' => 'install-test/lib/perl',
57            read   => 'install-test/packlist',
58            write  => 'install-test/packlist'
59          },
60        0, 1);
61 ok( ! -d 'install-test/lib/perl',        'install made dir (dry run)');
62 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
63                                          '  .pm file installed (dry run)');
64 ok( ! -r 'install-test/packlist',        '  packlist exists (dry run)');
65
66 install( { 'blib/lib' => 'install-test/lib/perl',
67            read   => 'install-test/packlist',
68            write  => 'install-test/packlist'
69          } );
70 ok( -d 'install-test/lib/perl',                 'install made dir' );
71 ok( -r 'install-test/lib/perl/Big/Dummy.pm',    '  .pm file installed' );
72 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP',  '  ignored .SKIP file' );
73 ok( -r 'install-test/packlist',                 '  packlist exists' );
74
75 open(PACKLIST, 'install-test/packlist' );
76 my %packlist = map { chomp;  ($_ => 1) } <PACKLIST>;
77 close PACKLIST;
78
79 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
80 # be lowercase. :(
81 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
82 is( keys %packlist, 1 );
83 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
84
85
86 # Test UNINST=1 preserving same versions in other dirs.
87 install( { 'blib/lib' => 'install-test/other_lib/perl',
88            read   => 'install-test/packlist',
89            write  => 'install-test/packlist'
90          },
91        0, 0, 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( { '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
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 }
172
173 # Test UNINST=1 removing other versions in other dirs.
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 }
188