4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest tests => 55;
9 my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
12 my $dist = DistGen->new( dir => $tmp );
15 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
17 #########################
20 use_ok 'Module::Build';
23 skip "no blib in core", 1 if $ENV{PERL_CORE};
24 like $INC{'Module/Build.pm'}, qr/\bblib\b/, "Make sure Module::Build was loaded from blib/";
28 # Test object creation
30 my $mb = Module::Build->new( module_name => $dist->name );
32 is $mb->module_name, $dist->name;
33 is $mb->build_class, 'Module::Build';
34 is $mb->dist_name, $dist->name;
36 $mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 );
38 ok ! $mb->module_name; # Make sure it's defined
39 is $mb->dist_name, $dist->name;
42 # Make sure actions are defined, and known_actions works as class method
44 my %actions = map {$_, 1} Module::Build->known_actions;
49 # Test prerequisite checking
51 local @INC = (File::Spec->catdir( $dist->dirname, 'lib' ), @INC);
53 local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /@{[$dist->name]}/};
54 my $mb = Module::Build->new(
55 module_name => $dist->name,
56 requires => {$dist->name => 0},
59 ok ! $mb->prereq_failures;
60 $mb->dispatch('realclean');
64 $mb = Module::Build->new(
65 module_name => $dist->name,
66 requires => {$dist->name => 3.14159265},
69 ok $mb->prereq_failures;
70 ok $mb->prereq_failures->{requires}{$dist->name};
71 is $mb->prereq_failures->{requires}{$dist->name}{have}, 0.01;
72 is $mb->prereq_failures->{requires}{$dist->name}{need}, 3.14159265;
74 $mb->dispatch('realclean');
77 # Make sure check_installed_status() works as a class method
78 my $info = Module::Build->check_installed_status('File::Spec', 0);
80 is $info->{have}, $File::Spec::VERSION;
82 # Make sure check_installed_status() works with an advanced spec
83 $info = Module::Build->check_installed_status('File::Spec', '> 0');
86 # Use 2 lines for this, to avoid a "used only once" warning
87 local $Foo::Module::VERSION;
88 $Foo::Module::VERSION = '1.01_02';
90 $info = Module::Build->check_installed_status('Foo::Module', '1.01_02');
91 ok $info->{ok} or diag($info->{message});
95 # Make sure the correct warning message is generated when an
96 # optional prereq isn't installed
98 local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /ModuleBuildNonExistent is not installed/};
100 my $mb = Module::Build->new(
101 module_name => $dist->name,
102 recommends => {ModuleBuildNonExistent => 3},
110 my $mb = Module::Build->new(module_name => $dist->name);
112 $mb->add_to_cleanup('save_out');
113 # Use uc() so we don't confuse the current test output
114 like uc(stdout_of( sub {$mb->dispatch('test', verbose => 1)} )), qr/^OK \d/m;
115 like uc(stdout_of( sub {$mb->dispatch('test', verbose => 0)} )), qr/\.\.OK/;
117 $mb->dispatch('realclean');
121 # Make sure 'config' entries are respected on the command line, and that
122 # Getopt::Long specs work as expected.
125 $dist->change_file( 'Build.PL', <<"---" );
128 my \$build = Module::Build->new(
129 module_name => @{[$dist->name]},
131 get_options => { foo => {},
132 bar => { type => '+' },
133 bat => { type => '=s' },
134 dee => { type => '=s',
140 \$build->create_build_script;
144 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'])};
147 my $mb = Module::Build->resume;
148 is $mb->config('cc'), $Config{cc};
149 is $mb->config('foocakes'), 'barcakes';
152 is $mb->args('foo'), 1;
153 is $mb->args('bar'), 2, 'bar';
154 is $mb->args('bat'), 'hello', 'bat';
155 is $mb->args('gee'), 'whiz';
156 is $mb->args('any'), 'hey';
157 is $mb->args('dee'), 'goo';
158 is $mb->destdir, 'yo';
159 is $mb->runtime_params('destdir'), 'yo';
160 is $mb->runtime_params('verbose'), '1';
161 ok ! $mb->runtime_params('license');
162 ok my %runtime = $mb->runtime_params;
163 is scalar keys %runtime, 4;
164 is $runtime{destdir}, 'yo';
165 is $runtime{verbose}, '1';
168 ok my $argsref = $mb->args;
169 is $argsref->{foo}, 1;
170 $argsref->{doo} = 'hee';
171 is $mb->args('doo'), 'hee';
172 ok my %args = $mb->args;
175 # revert test distribution to pristine state because we modified a file
176 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
178 $dist = DistGen->new( dir => $tmp );
180 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
185 my $mb = Module::Build->new(
186 module_name => $dist->name,
187 dist_author => 'Foo Meister <foo@example.com>',
188 build_class => 'My::Big::Fat::Builder',
191 ok ref($mb->dist_author), 'dist_author converted to array if simple string';
192 is $mb->dist_author->[0], 'Foo Meister <foo@example.com>';
193 is $mb->build_class, 'My::Big::Fat::Builder';
196 # Test conversion of shell strings
198 my $mb = Module::Build->new(
199 module_name => $dist->name,
200 dist_author => 'Foo Meister <foo@example.com>',
201 extra_compiler_flags => '-I/foo -I/bar',
202 extra_linker_flags => '-L/foo -L/bar',
205 is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
206 is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";
211 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";