3 # Test ExtUtils::Install.
6 if( $ENV{PERL_CORE} ) {
7 @INC = ('../../lib', '../lib', 'lib');
10 unshift @INC, 't/lib';
20 use Test::More tests => 52;
22 use MakeMaker::Test::Setup::BFD;
24 BEGIN { use_ok('ExtUtils::Install') }
27 foreach my $func (qw(install uninstall pm_to_blib install_default)) {
28 can_ok(__PACKAGE__, $func);
32 ok( setup_recurs(), 'setup' );
34 ok( chdir File::Spec->updir );
35 ok( teardown_recurs(), 'teardown' );
40 my $stdout = tie *STDOUT, 'TieOut';
41 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
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" );
51 pm_to_blib( { 'lib/Big/Dummy.pm' => 'blib/lib/Big/Dummy.pm' },
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" );
59 install( { 'blib/lib' => 'install-test/lib/perl',
60 read => 'install-test/packlist',
61 write => 'install-test/packlist'
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)');
69 install( { 'blib/lib' => 'install-test/lib/perl',
70 read => 'install-test/packlist',
71 write => 'install-test/packlist'
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' );
78 open(PACKLIST, 'install-test/packlist' );
79 my %packlist = map { chomp; ($_ => 1) } <PACKLIST>;
82 # On case-insensitive filesystems (ie. VMS), the keys of the packlist might
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' );
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'
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' );
101 chmod 0644, 'blib/lib/Big/Dummy.pm' or die $!;
102 open(DUMMY, ">>blib/lib/Big/Dummy.pm") or die $!;
103 print DUMMY "Extra stuff\n";
107 # Test UNINST=0 does not remove other versions in other dirs.
109 ok( -r 'install-test/lib/perl/Big/Dummy.pm', 'different install exists' );
111 local @INC = ('install-test/lib/perl');
112 local $ENV{PERL5LIB} = '';
113 install( { 'blib/lib' => 'install-test/other_lib/perl',
114 read => 'install-test/packlist',
115 write => 'install-test/packlist'
118 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
119 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
120 ok( -r 'install-test/packlist', ' packlist exists' );
121 ok( -r 'install-test/lib/perl/Big/Dummy.pm',
122 ' UNINST=0 left different' );
125 # Test UNINST=1 only warning when failing to remove an irrelevent shadow file
127 my $tfile='install-test/lib/perl/Big/Dummy.pm';
128 local $ExtUtils::Install::Testing = $tfile;
129 local @INC = ('install-test/other_lib/perl','install-test/lib/perl');
130 local $ENV{PERL5LIB} = '';
131 ok( -r $tfile, 'different install exists' );
133 local $SIG{__WARN__}=sub { push @warn, @_; return };
135 install( { 'blib/lib' => 'install-test/other_lib/perl',
136 read => 'install-test/packlist',
137 write => 'install-test/packlist'
142 ok($ok,' we didnt die');
143 ok(0+@warn," we did warn");
144 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
145 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
146 ok( -r 'install-test/packlist', ' packlist exists' );
147 ok( -r $tfile, ' UNINST=1 failed to remove different' );
151 # Test UNINST=1 dieing when failing to remove an relevent shadow file
153 my $tfile='install-test/lib/perl/Big/Dummy.pm';
154 local $ExtUtils::Install::Testing = $tfile;
155 local @INC = ('install-test/lib/perl','install-test/other_lib/perl');
156 local $ENV{PERL5LIB} = '';
157 ok( -r $tfile, 'different install exists' );
159 local $SIG{__WARN__}=sub { push @warn,@_; return };
161 install( { 'blib/lib' => 'install-test/other_lib/perl',
162 read => 'install-test/packlist',
163 write => 'install-test/packlist'
168 ok(!$ok,' we did die');
169 ok(!@warn," we didnt warn");
170 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
171 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
172 ok( -r 'install-test/packlist', ' packlist exists' );
173 ok( -r $tfile,' UNINST=1 failed to remove different' );
176 # Test UNINST=1 removing other versions in other dirs.
178 local @INC = ('install-test/lib/perl');
179 local $ENV{PERL5LIB} = '';
180 install( { 'blib/lib' => 'install-test/other_lib/perl',
181 read => 'install-test/packlist',
182 write => 'install-test/packlist'
185 ok( -d 'install-test/other_lib/perl', 'install made other dir' );
186 ok( -r 'install-test/other_lib/perl/Big/Dummy.pm', ' .pm file installed' );
187 ok( -r 'install-test/packlist', ' packlist exists' );
188 ok( !-r 'install-test/lib/perl/Big/Dummy.pm',
189 ' UNINST=1 removed different' );