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