forked from hdp/module-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.t
142 lines (113 loc) · 4.04 KB
/
install.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use strict;
use Test;
BEGIN { plan tests => 27 }
use Module::Build;
use File::Spec;
use File::Path;
use Config;
ok(1);
require File::Spec->catfile('t', 'common.pl');
my $start_dir = Module::Build->cwd;
# Would be nice to just have a 'base_dir' parameter for M::B->new()
my $goto = File::Spec->catdir( $start_dir, 't', 'Sample' );
chdir $goto or die "can't chdir to $goto: $!";
my $build = new Module::Build( module_name => 'Sample',
script_files => [ 'script' ],
requires => { 'File::Spec' => 0 },
license => 'perl' );
ok $build;
my $destdir = File::Spec->catdir($start_dir, 't', 'install_test');
$build->add_to_cleanup($destdir);
{
eval {$build->dispatch('install', destdir => $destdir)};
ok $@, '';
my $libdir = strip_volume( $build->install_destination('lib') );
my $install_to = File::Spec->catfile($destdir, $libdir, 'Sample.pm');
print "Should have installed module as $install_to\n";
ok -e $install_to;
local @INC = (@INC, File::Spec->catdir($destdir, $libdir));
eval {require Sample};
ok $@, '';
}
{
eval {$build->dispatch('install', installdirs => 'core', destdir => $destdir)};
ok $@, '';
my $libdir = strip_volume( $Config{installprivlib} );
my $install_to = File::Spec->catfile($destdir, $libdir, 'Sample.pm');
print "Should have installed module as $install_to\n";
ok -e $install_to;
}
{
my $libdir = File::Spec->catdir(File::Spec->rootdir, 'foo', 'bar');
eval {$build->dispatch('install', install_path => {lib => $libdir}, destdir => $destdir)};
ok $@, '';
my $install_to = File::Spec->catfile($destdir, $libdir, 'Sample.pm');
print "Should have installed module as $install_to\n";
ok -e $install_to;
}
{
my $libdir = File::Spec->catdir(File::Spec->rootdir, 'foo', 'base');
eval {$build->dispatch('install', install_base => $libdir, destdir => $destdir)};
ok $@, '';
my $install_to = File::Spec->catfile($destdir, $libdir, 'lib', 'Sample.pm');
print "Should have installed module as $install_to\n";
ok -e $install_to;
}
{
$build->build_config(foo => 'bar');
$build->features(baz => 'quux');
eval {$build->dispatch('install', destdir => $destdir)};
ok $@, '';
my $libdir = strip_volume( $build->install_destination('lib') );
local @INC = (@INC, File::Spec->catdir($destdir, $libdir));
eval {require Sample::BuildConfig};
if ($@) {
ok $@, ''; # Show what the failure was
ok 1;
} else {
ok( Sample::BuildConfig->get('foo'), 'bar' );
ok( Sample::BuildConfig->feature('baz'), 'quux' );
}
}
eval {$build->dispatch('realclean')};
ok $@, '';
{
# Try again by running the script rather than with programmatic interface
my $libdir = File::Spec->catdir('', 'foo', 'lib');
eval {$build->run_perl_script('Build.PL', [], ['--install_path', "lib=$libdir"])};
ok $@, '';
eval {$build->run_perl_script('Build', [], ['install', '--destdir', $destdir])};
ok $@, '';
my $install_to = File::Spec->catfile($destdir, $libdir, 'Sample.pm');
print "# Should have installed module as $install_to\n";
ok -e $install_to;
my $basedir = File::Spec->catdir('', 'bar');
eval {$build->run_perl_script('Build', [], ['install', '--destdir', $destdir,
'--install_base', $basedir])};
ok $@, '';
my $relpath = $build->install_base_relative('lib');
$install_to = File::Spec->catfile($destdir, $basedir, $relpath, 'Sample.pm');
print "# Should have installed module as $install_to\n";
ok -e $install_to;
eval {$build->dispatch('realclean')};
ok $@, '';
}
{
# _find_file_by_type() isn't a public method, but this is currently
# the only easy way to test that it works properly.
my $pods = $build->_find_file_by_type('pod', 'lib');
ok keys %$pods, 1;
my $expect = $build->localize_file_path('lib/Sample/Docs.pod');
ok $pods->{$expect}, $expect;
my $pms = $build->_find_file_by_type('awefawef', 'lib');
ok $pms;
ok keys %$pms, 0;
$pms = $build->_find_file_by_type('pod', 'awefawef');
ok $pms;
ok keys %$pms, 0;
}
sub strip_volume {
my $dir = shift;
(undef, $dir) = File::Spec->splitpath( $dir, 1 );
return $dir;
}