Update Module::Build to 0.3603
[p5sagit/p5-mst-13.2.git] / cpan / Module-Build / t / install.t
CommitLineData
bb4e9162 1#!/usr/bin/perl -w
2
3use strict;
10b84a45 4use lib 't/lib';
613f422f 5use MBTest tests => 34;
bb4e9162 6
613f422f 7blib_load('Module::Build');
738349a8 8
9use Config;
bb4e9162 10use Cwd ();
11my $cwd = Cwd::cwd;
7a827510 12my $tmp = MBTest->tmpdir;
bb4e9162 13
14use DistGen;
15my $dist = DistGen->new( dir => $tmp );
16$dist->regen;
738349a8 17$dist->chdir_in;
bb4e9162 18
19#########################
20
bb4e9162 21
22$dist->add_file( 'script', <<'---' );
23#!perl -w
24print "Hello, World!\n";
25---
7a827510 26$dist->change_build_pl
27({
28 module_name => $dist->name,
bb4e9162 29 scripts => [ 'script' ],
30 license => 'perl',
31 requires => { 'File::Spec' => 0 },
7a827510 32});
bb4e9162 33$dist->regen;
34
35
36use File::Spec::Functions qw( catdir );
37
38my $mb = Module::Build->new_from_context(
39 # need default install paths to ensure manpages & HTML get generated
40 installdirs => 'site',
41 config => {
42 installman1dir => catdir($tmp, 'man', 'man1'),
43 installman3dir => catdir($tmp, 'man', 'man3'),
44 installhtml1dir => catdir($tmp, 'html'),
45 installhtml3dir => catdir($tmp, 'html'),
46
47 installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'),
48 installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'),
49 installsitehtml1dir => catdir($tmp, 'site', 'html'),
50 installsitehtml3dir => catdir($tmp, 'site', 'html'),
51 }
52
53);
54
55ok $mb;
56
57
3143ec60 58my $destdir = File::Spec->catdir($cwd, 't', 'install_test' . $$);
bb4e9162 59$mb->add_to_cleanup($destdir);
60
61{
62 eval {$mb->dispatch('install', destdir => $destdir)};
63 is $@, '';
7dc9e1b4 64
d1bd4ef0 65 my @libdir = strip_volume( $mb->install_destination('lib') );
66 my $install_to = File::Spec->catfile($destdir, @libdir, $dist->name ) . '.pm';
bb4e9162 67 file_exists($install_to);
7dc9e1b4 68
d1bd4ef0 69 local @INC = (@INC, File::Spec->catdir($destdir, @libdir));
bb4e9162 70 eval "require @{[$dist->name]}";
71 is $@, '';
7dc9e1b4 72
bb4e9162 73 # Make sure there's a packlist installed
74 my $archdir = $mb->install_destination('arch');
d1bd4ef0 75 my @dirs = strip_volume($archdir);
76 my $packlist = File::Spec->catfile
77 ($destdir, @dirs, 'auto', $dist->name, '.packlist');
bb4e9162 78 is -e $packlist, 1, "$packlist should be written";
79}
80
81{
82 eval {$mb->dispatch('install', installdirs => 'core', destdir => $destdir)};
83 is $@, '';
d1bd4ef0 84 my @libdir = strip_volume( $Config{installprivlib} );
85 my $install_to = File::Spec->catfile($destdir, @libdir, $dist->name ) . '.pm';
bb4e9162 86 file_exists($install_to);
87}
88
89{
90 my $libdir = File::Spec->catdir(File::Spec->rootdir, 'foo', 'bar');
91 eval {$mb->dispatch('install', install_path => {lib => $libdir}, destdir => $destdir)};
92 is $@, '';
d1bd4ef0 93 my @dirs = strip_volume($libdir);
94 my $install_to = File::Spec->catfile($destdir, @dirs, $dist->name ) . '.pm';
bb4e9162 95 file_exists($install_to);
96}
97
98{
99 my $libdir = File::Spec->catdir(File::Spec->rootdir, 'foo', 'base');
100 eval {$mb->dispatch('install', install_base => $libdir, destdir => $destdir)};
101 is $@, '';
d1bd4ef0 102 my @dirs = strip_volume($libdir);
103 my $install_to = File::Spec->catfile($destdir, @dirs, 'lib', 'perl5', $dist->name ) . '.pm';
bb4e9162 104 file_exists($install_to);
105}
106
107{
108 # Test the ConfigData stuff
7dc9e1b4 109
bb4e9162 110 $mb->config_data(foo => 'bar');
111 $mb->features(baz => 1);
112 $mb->auto_features(auto_foo => {requires => {'File::Spec' => 0}});
113 eval {$mb->dispatch('install', destdir => $destdir)};
114 is $@, '';
7dc9e1b4 115
d1bd4ef0 116 my @libdir = strip_volume( $mb->install_destination('lib') );
117 local @INC = (@INC, File::Spec->catdir($destdir, @libdir));
bb4e9162 118 eval "require @{[$dist->name]}::ConfigData";
119
120 is $mb->feature('auto_foo'), 1;
7dc9e1b4 121
bb4e9162 122 SKIP: {
123 skip $@, 5 if @_;
124
125 # Make sure the values are present
126 my $config = $dist->name . '::ConfigData';
127 is( $config->config('foo'), 'bar' );
128 ok( $config->feature('baz') );
129 ok( $config->feature('auto_foo') );
130 ok( not $config->feature('nonexistent') );
131
132 # Add a new value to the config set
133 $config->set_config(floo => 'bhlar');
134 is( $config->config('floo'), 'bhlar' );
135
136 # Make sure it actually got written
137 $config->write;
138 delete $INC{"@{[$dist->name]}/ConfigData.pm"};
139 {
140 local $^W; # Avoid warnings for subroutine redefinitions
141 eval "require $config";
142 }
143 is( $config->config('floo'), 'bhlar' );
144 }
145}
146
147
148eval {$mb->dispatch('realclean')};
149is $@, '';
150
151{
152 # Try again by running the script rather than with programmatic interface
153 my $libdir = File::Spec->catdir('', 'foo', 'lib');
154 eval {$mb->run_perl_script('Build.PL', [], ['--install_path', "lib=$libdir"])};
155 is $@, '';
7dc9e1b4 156
d1bd4ef0 157 my $cmd = 'Build';
158 $cmd .= ".COM" if $^O eq 'VMS';
159 eval {$mb->run_perl_script($cmd, [], ['install', '--destdir', $destdir])};
bb4e9162 160 is $@, '';
161 my $install_to = File::Spec->catfile($destdir, $libdir, $dist->name ) . '.pm';
162 file_exists($install_to);
163
164 my $basedir = File::Spec->catdir('', 'bar');
d1bd4ef0 165 eval {$mb->run_perl_script($cmd, [], ['install', '--destdir', $destdir,
bb4e9162 166 '--install_base', $basedir])};
167 is $@, '';
7dc9e1b4 168
bb4e9162 169 $install_to = File::Spec->catfile($destdir, $libdir, $dist->name ) . '.pm';
170 is -e $install_to, 1, "Look for file at $install_to";
7dc9e1b4 171
bb4e9162 172 eval {$mb->dispatch('realclean')};
173 is $@, '';
174}
175
176{
177 # Make sure 'install_path' overrides 'install_base'
178 my $mb = Module::Build->new( module_name => $dist->name,
179 install_base => File::Spec->catdir('', 'foo'),
180 install_path => {
181 lib => File::Spec->catdir('', 'bar')
182 }
183 );
184 ok $mb;
185 is $mb->install_destination('lib'), File::Spec->catdir('', 'bar');
186}
187
188{
189 $dist->add_file( 'lib/Simple/Docs.pod', <<'---' );
190=head1 NAME
191
192Simple::Docs - Simple pod
193
194=head1 AUTHOR
195
196Simple Man <simple@example.com>
197
198=cut
199---
200 $dist->regen;
201
202 # _find_file_by_type() isn't a public method, but this is currently
203 # the only easy way to test that it works properly.
204 my $pods = $mb->_find_file_by_type('pod', 'lib');
205 is keys %$pods, 1;
206 my $expect = $mb->localize_file_path('lib/Simple/Docs.pod');
d1bd4ef0 207
208 # TODO:
209 # True for traditional VMS, but will need to be changed when ODS-5 support
210 # for case preserved filenames is active.
211 # The issue is that the keys to the $pods hash are currently being set to
212 # lowercase on VMS so can not be found in exact case.
213
214 $expect = lc($expect) if $^O eq 'VMS';
215
bb4e9162 216 is $pods->{$expect}, $expect;
7dc9e1b4 217
bb4e9162 218 my $pms = $mb->_find_file_by_type('awefawef', 'lib');
219 ok $pms;
220 is keys %$pms, 0;
7dc9e1b4 221
bb4e9162 222 $pms = $mb->_find_file_by_type('pod', 'awefawef');
223 ok $pms;
224 is keys %$pms, 0;
225
226 # revert to pristine state
613f422f 227 $dist->regen( clean => 1 );
bb4e9162 228}
229
230sub strip_volume {
231 my $dir = shift;
232 (undef, $dir) = File::Spec->splitpath( $dir, 1 );
d1bd4ef0 233 my @dirs = File::Spec->splitdir($dir);
234 return @dirs;
bb4e9162 235}
236
237sub file_exists {
238 my $file = shift;
239 ok -e $file or diag("Expected $file to exist, but it doesn't");
240}
241