5 use MBTest tests => 58;
7 blib_load('Module::Build');
9 my $tmp = MBTest->tmpdir;
12 my $dist = DistGen->new( dir => $tmp );
17 #########################
20 # Test object creation
22 my $mb = Module::Build->new( module_name => $dist->name );
24 is $mb->module_name, $dist->name;
25 is $mb->build_class, 'Module::Build';
26 is $mb->dist_name, $dist->name;
28 $mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 );
30 ok $mb->module_name; # Set via heuristics
31 is $mb->dist_name, $dist->name;
34 # Make sure actions are defined, and known_actions works as class method
36 my %actions = map {$_, 1} Module::Build->known_actions;
41 # Test prerequisite checking
43 local @INC = (File::Spec->catdir( $dist->dirname, 'lib' ), @INC);
45 local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /@{[$dist->name]}/};
46 my $mb = Module::Build->new(
47 module_name => $dist->name,
48 requires => {$dist->name => 0},
51 ok ! $mb->prereq_failures;
52 $mb->dispatch('realclean');
56 $mb = Module::Build->new(
57 module_name => $dist->name,
58 requires => {$dist->name => 3.14159265},
61 ok $mb->prereq_failures;
62 ok $mb->prereq_failures->{requires}{$dist->name};
63 is $mb->prereq_failures->{requires}{$dist->name}{have}, 0.01;
64 is $mb->prereq_failures->{requires}{$dist->name}{need}, 3.14159265;
66 $mb->dispatch('realclean');
69 # Make sure check_installed_status() works as a class method
70 my $info = Module::Build->check_installed_status('File::Spec', 0);
72 is $info->{have}, $File::Spec::VERSION;
74 # Make sure check_installed_status() works with an advanced spec
75 $info = Module::Build->check_installed_status('File::Spec', '> 0');
78 # Use 2 lines for this, to avoid a "used only once" warning
79 local $Foo::Module::VERSION;
80 $Foo::Module::VERSION = '1.01_02';
82 $info = Module::Build->check_installed_status('Foo::Module', '1.01_02');
83 ok $info->{ok} or diag($info->{message});
87 # Make sure the correct warning message is generated when an
88 # optional prereq isn't installed
90 local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /ModuleBuildNonExistent is not installed/};
92 my $mb = Module::Build->new(
93 module_name => $dist->name,
94 recommends => {ModuleBuildNonExistent => 3},
102 my $mb = Module::Build->new(module_name => $dist->name);
104 $mb->add_to_cleanup('save_out');
105 # Use uc() so we don't confuse the current test output
106 like uc(stdout_of( sub {$mb->dispatch('test', verbose => 1)} )), qr/^OK \d/m;
107 like uc(stdout_of( sub {$mb->dispatch('test', verbose => 0)} )), qr/\.\. ?OK/;
109 $mb->dispatch('realclean');
113 # Make sure 'config' entries are respected on the command line, and that
114 # Getopt::Long specs work as expected.
117 $dist->change_build_pl
119 module_name => @{[$dist->name]},
121 get_options => { foo => {},
122 bar => { type => '+' },
123 bat => { type => '=s' },
124 dee => { type => '=s',
131 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'])};
134 my $mb = Module::Build->resume;
135 ok $mb->valid_property('config');
137 is $mb->config('cc'), $Config{cc};
138 is $mb->config('foocakes'), 'barcakes';
141 is $mb->args('foo'), 1;
142 is $mb->args('bar'), 2, 'bar';
143 is $mb->args('bat'), 'hello', 'bat';
144 is $mb->args('gee'), 'whiz';
145 is $mb->args('any'), 'hey';
146 is $mb->args('dee'), 'goo';
147 is $mb->destdir, 'yo';
148 my %runtime = $mb->runtime_params;
154 config => { foocakes => 'barcakes' },
157 ok my $argsref = $mb->args;
158 is $argsref->{foo}, 1;
159 $argsref->{doo} = 'hee';
160 is $mb->args('doo'), 'hee';
161 ok my %args = $mb->args;
164 # revert test distribution to pristine state because we modified a file
165 $dist->regen( clean => 1 );
170 my $mb = Module::Build->new(
171 module_name => $dist->name,
172 dist_author => 'Foo Meister <foo@example.com>',
173 build_class => 'My::Big::Fat::Builder',
176 ok ref($mb->dist_author), 'dist_author converted to array if simple string';
177 is $mb->dist_author->[0], 'Foo Meister <foo@example.com>';
178 is $mb->build_class, 'My::Big::Fat::Builder';
181 # Test conversion of shell strings
183 my $mb = Module::Build->new(
184 module_name => $dist->name,
185 dist_author => 'Foo Meister <foo@example.com>',
186 extra_compiler_flags => '-I/foo -I/bar',
187 extra_linker_flags => '-L/foo -L/bar',
190 is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
191 is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";
193 # Try again with command-line args
194 eval {Module::Build->run_perl_script('Build.PL', [], ['--extra_compiler_flags', '-I/foo -I/bar',
195 '--extra_linker_flags', '-L/foo -L/bar'])};
196 $mb = Module::Build->resume;
198 is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
199 is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";
204 ok my $mb = Module::Build->new(
205 module_name => $dist->name,
206 include_dirs => [qw(/foo /bar)],
208 is_deeply $mb->include_dirs, ['/foo', '/bar'], 'Should have include dirs';
211 ok $mb = Module::Build->new(
212 module_name => $dist->name,
213 include_dirs => '/foo',
215 is_deeply $mb->include_dirs, ['/foo'], 'Should have string include dir';
217 # Try again with command-line args
218 eval { Module::Build->run_perl_script(
220 ['--include_dirs', '/foo', '--include_dirs', '/bar' ],
223 ok $mb = Module::Build->resume;
224 is_deeply $mb->include_dirs, ['/foo', '/bar'], 'Should have include dirs';
226 eval { Module::Build->run_perl_script(
228 ['--include_dirs', '/foo' ],
231 ok $mb = Module::Build->resume;
232 is_deeply $mb->include_dirs, ['/foo'], 'Should have single include dir';