This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix warning.
[perl5.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 => 33;
21
22 use MakeMaker::Test::Setup::BFD;
23
24 BEGIN { use_ok('ExtUtils::Install') }
25
26 # Check exports.
27 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
28     can_ok(__PACKAGE__, $func);
29 }
30
31
32 ok( setup_recurs(), 'setup' );
33 END {
34     ok( chdir File::Spec->updir );
35     ok( teardown_recurs(), 'teardown' );
36 }
37
38 chdir 'Big-Dummy';
39
40 my $stdout = tie *STDOUT, 'TieOut';
41 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
42             'blib/lib/auto'
43           );
44 END { rmtree 'blib' }
45
46 ok( -d 'blib/lib',              'pm_to_blib created blib dir' );
47 ok( -r 'blib/lib/Big/Dummy.pm', '  copied .pm file' );
48 ok( -r 'blib/lib/auto',         '  created autosplit dir' );
49 is( $stdout->read, "cp lib/Big/Dummy.pm blib/lib/Big/Dummy.pm\n" );
50
51 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
52             'blib/lib/auto'
53           );
54 ok( -d 'blib/lib',              'second run, blib dir still there' );
55 ok( -r 'blib/lib/Big/Dummy.pm', '  .pm file still there' );
56 ok( -r 'blib/lib/auto',         '  autosplit still there' );
57 is( $stdout->read, "Skip blib/lib/Big/Dummy.pm (unchanged)\n" );
58
59 install( { 'blib/lib' => 'install-test/lib/perl',
60            read   => 'install-test/packlist',
61            write  => 'install-test/packlist'
62          },
63        0, 1);
64 ok( ! -d 'install-test/lib/perl',        'install made dir (dry run)');
65 ok( ! -r 'install-test/lib/perl/Big/Dummy.pm',
66                                          '  .pm file installed (dry run)');
67 ok( ! -r 'install-test/packlist',        '  packlist exists (dry run)');
68
69 install( { 'blib/lib' => 'install-test/lib/perl',
70            read   => 'install-test/packlist',
71            write  => 'install-test/packlist'
72          } );
73 ok( -d 'install-test/lib/perl',                 'install made dir' );
74 ok( -r 'install-test/lib/perl/Big/Dummy.pm',    '  .pm file installed' );
75 ok(!-r 'install-test/lib/perl/Big/Dummy.SKIP',  '  ignored .SKIP file' );
76 ok( -r 'install-test/packlist',                 '  packlist exists' );
77
78 open(PACKLIST, 'install-test/packlist' );
79 my %packlist = map { chomp;  ($_ => 1) } <PACKLIST>;
80 close PACKLIST;
81
82 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
83 # be lowercase. :(
84 my $native_dummy = File::Spec->catfile(qw(install-test lib perl Big Dummy.pm));
85 is( keys %packlist, 1 );
86 is( lc((keys %packlist)[0]), lc $native_dummy, 'packlist written' );
87
88
89 # Test UNINST=1 preserving same versions in other dirs.
90 install( { 'blib/lib' => 'install-test/other_lib/perl',
91            read   => 'install-test/packlist',
92            write  => 'install-test/packlist'
93          },
94        0, 0, 1);
95 ok( -d 'install-test/other_lib/perl',        'install made other dir' );
96 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', '  .pm file installed' );
97 ok( -r 'install-test/packlist',              '  packlist exists' );
98 ok( -r 'install-test/lib/perl/Big/Dummy.pm', '  UNINST=1 preserved same' );
99
100
101
102 # Test UNINST=1 removing other versions in other dirs.
103 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
104 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
105 print DUMMY "Extra stuff\n";
106 close DUMMY;
107
108 {
109   local @INC = ('install-test/lib/perl');
110   local $ENV{PERL5LIB} = '';
111   install( { 'blib/lib' => 'install-test/other_lib/perl',
112            read   => 'install-test/packlist',
113            write  => 'install-test/packlist'
114          },
115        0, 0, 1);
116   ok( -d 'install-test/other_lib/perl',        'install made other dir' );
117   ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', '  .pm file installed' );
118   ok( -r 'install-test/packlist',              '  packlist exists' );
119   ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
120                                              '  UNINST=1 removed different' );
121 }