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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
#!/usr/bin/perl -w
use strict;
use lib 't/lib';
use MBTest tests => 58;
blib_load('Module::Build');
my $tmp = MBTest->tmpdir;
use DistGen;
my $dist = DistGen->new( dir => $tmp );
$dist->regen;
$dist->chdir_in;
#########################
# Test object creation
{
my $mb = Module::Build->new( module_name => $dist->name );
ok $mb;
is $mb->module_name, $dist->name;
is $mb->build_class, 'Module::Build';
is $mb->dist_name, $dist->name;
$mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 );
ok $mb;
ok $mb->module_name; # Set via heuristics
is $mb->dist_name, $dist->name;
}
# Make sure actions are defined, and known_actions works as class method
{
my %actions = map {$_, 1} Module::Build->known_actions;
ok $actions{clean};
ok $actions{distdir};
}
# Test prerequisite checking
{
local @INC = (File::Spec->catdir( $dist->dirname, 'lib' ), @INC);
my $flagged = 0;
local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /@{[$dist->name]}/};
my $mb = Module::Build->new(
module_name => $dist->name,
requires => {$dist->name => 0},
);
ok ! $flagged;
ok ! $mb->prereq_failures;
$mb->dispatch('realclean');
$dist->clean;
$flagged = 0;
$mb = Module::Build->new(
module_name => $dist->name,
requires => {$dist->name => 3.14159265},
);
ok $flagged;
ok $mb->prereq_failures;
ok $mb->prereq_failures->{requires}{$dist->name};
is $mb->prereq_failures->{requires}{$dist->name}{have}, "0.01";
is $mb->prereq_failures->{requires}{$dist->name}{need}, "3.14159265";
$mb->dispatch('realclean');
$dist->clean;
# Make sure check_installed_status() works as a class method
my $info = Module::Build->check_installed_status('File::Spec', 0);
ok $info->{ok};
is $info->{have}, $File::Spec::VERSION;
# Make sure check_installed_status() works with an advanced spec
$info = Module::Build->check_installed_status('File::Spec', '> 0');
ok $info->{ok};
# Use 2 lines for this, to avoid a "used only once" warning
local $Foo::Module::VERSION;
$Foo::Module::VERSION = '1.01_02';
$info = Module::Build->check_installed_status('Foo::Module', '1.01_02');
ok $info->{ok} or diag($info->{message});
}
{
# Make sure the correct warning message is generated when an
# optional prereq isn't installed
my $flagged = 0;
local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /ModuleBuildNonExistent is not installed/};
my $mb = Module::Build->new(
module_name => $dist->name,
recommends => {ModuleBuildNonExistent => 3},
);
ok $flagged;
$dist->clean;
}
# Test verbosity
{
my $mb = Module::Build->new(module_name => $dist->name);
$mb->add_to_cleanup('save_out');
# Use uc() so we don't confuse the current test output
like uc(stdout_of( sub {$mb->dispatch('test', verbose => 1)} )), qr/^OK \d/m;
like uc(stdout_of( sub {$mb->dispatch('test', verbose => 0)} )), qr/\.\. ?OK/;
$mb->dispatch('realclean');
$dist->clean;
}
# Make sure 'config' entries are respected on the command line, and that
# Getopt::Long specs work as expected.
{
use Config;
$dist->change_build_pl
({
module_name => @{[$dist->name]},
license => 'perl',
get_options => { foo => {},
bar => { type => '+' },
bat => { type => '=s' },
dee => { type => '=s',
default => 'goo'
},
}
});
$dist->regen;
eval {Module::Build->run_perl_script('Build.PL', [], ['--nouse-rcfile', '--config', "foocakes=barcakes", '--foo', '--bar', '--bar', '-bat=hello', 'gee=whiz', '--any', 'hey', '--destdir', 'yo', '--verbose', '1'])};
is $@, '';
my $mb = Module::Build->resume;
ok $mb->valid_property('config');
is $mb->config('cc'), $Config{cc};
is $mb->config('foocakes'), 'barcakes';
# Test args().
is $mb->args('foo'), 1;
is $mb->args('bar'), 2, 'bar';
is $mb->args('bat'), 'hello', 'bat';
is $mb->args('gee'), 'whiz';
is $mb->args('any'), 'hey';
is $mb->args('dee'), 'goo';
is $mb->destdir, 'yo';
my %runtime = $mb->runtime_params;
is_deeply \%runtime,
{
verbose => 1,
destdir => 'yo',
use_rcfile => 0,
config => { foocakes => 'barcakes' },
};
ok my $argsref = $mb->args;
is $argsref->{foo}, 1;
$argsref->{doo} = 'hee';
is $mb->args('doo'), 'hee';
ok my %args = $mb->args;
is $args{foo}, 1;
# revert test distribution to pristine state because we modified a file
$dist->regen( clean => 1 );
}
# Test author stuff
{
my $mb = Module::Build->new(
module_name => $dist->name,
dist_author => 'Foo Meister <foo@example.com>',
build_class => 'My::Big::Fat::Builder',
);
ok $mb;
ok ref($mb->dist_author), 'dist_author converted to array if simple string';
is $mb->dist_author->[0], 'Foo Meister <foo@example.com>';
is $mb->build_class, 'My::Big::Fat::Builder';
}
# Test conversion of shell strings
{
my $mb = Module::Build->new(
module_name => $dist->name,
dist_author => 'Foo Meister <foo@example.com>',
extra_compiler_flags => '-I/foo -I/bar',
extra_linker_flags => '-L/foo -L/bar',
);
ok $mb;
is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";
# Try again with command-line args
eval {Module::Build->run_perl_script('Build.PL', [], ['--extra_compiler_flags', '-I/foo -I/bar',
'--extra_linker_flags', '-L/foo -L/bar'])};
$mb = Module::Build->resume;
ok $mb;
is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";
}
# Test include_dirs.
{
ok my $mb = Module::Build->new(
module_name => $dist->name,
include_dirs => [qw(/foo /bar)],
);
is_deeply $mb->include_dirs, ['/foo', '/bar'], 'Should have include dirs';
# Try a string.
ok $mb = Module::Build->new(
module_name => $dist->name,
include_dirs => '/foo',
);
is_deeply $mb->include_dirs, ['/foo'], 'Should have string include dir';
# Try again with command-line args
eval { Module::Build->run_perl_script(
'Build.PL', [],
['--include_dirs', '/foo', '--include_dirs', '/bar' ],
) };
ok $mb = Module::Build->resume;
is_deeply $mb->include_dirs, ['/foo', '/bar'], 'Should have include dirs';
eval { Module::Build->run_perl_script(
'Build.PL', [],
['--include_dirs', '/foo' ],
) };
ok $mb = Module::Build->resume;
is_deeply $mb->include_dirs, ['/foo'], 'Should have single include dir';
}
|