4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest tests => 52;
7 use_ok 'Module::Build';
8 ensure_blib('Module::Build');
10 my $tmp = MBTest->tmpdir;
13 my $dist = DistGen->new( dir => $tmp );
18 #########################
21 # Test object creation
23 my $mb = Module::Build->new( module_name => $dist->name );
25 is $mb->module_name, $dist->name;
26 is $mb->build_class, 'Module::Build';
27 is $mb->dist_name, $dist->name;
29 $mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 );
31 ok ! $mb->module_name; # Make sure it's defined
32 is $mb->dist_name, $dist->name;
35 # Make sure actions are defined, and known_actions works as class method
37 my %actions = map {$_, 1} Module::Build->known_actions;
42 # Test prerequisite checking
44 local @INC = (File::Spec->catdir( $dist->dirname, 'lib' ), @INC);
46 local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /@{[$dist->name]}/};
47 my $mb = Module::Build->new(
48 module_name => $dist->name,
49 requires => {$dist->name => 0},
52 ok ! $mb->prereq_failures;
53 $mb->dispatch('realclean');
57 $mb = Module::Build->new(
58 module_name => $dist->name,
59 requires => {$dist->name => 3.14159265},
62 ok $mb->prereq_failures;
63 ok $mb->prereq_failures->{requires}{$dist->name};
64 is $mb->prereq_failures->{requires}{$dist->name}{have}, 0.01;
65 is $mb->prereq_failures->{requires}{$dist->name}{need}, 3.14159265;
67 $mb->dispatch('realclean');
70 # Make sure check_installed_status() works as a class method
71 my $info = Module::Build->check_installed_status('File::Spec', 0);
73 is $info->{have}, $File::Spec::VERSION;
75 # Make sure check_installed_status() works with an advanced spec
76 $info = Module::Build->check_installed_status('File::Spec', '> 0');
79 # Use 2 lines for this, to avoid a "used only once" warning
80 local $Foo::Module::VERSION;
81 $Foo::Module::VERSION = '1.01_02';
83 $info = Module::Build->check_installed_status('Foo::Module', '1.01_02');
84 ok $info->{ok} or diag($info->{message});
88 # Make sure the correct warning message is generated when an
89 # optional prereq isn't installed
91 local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /ModuleBuildNonExistent is not installed/};
93 my $mb = Module::Build->new(
94 module_name => $dist->name,
95 recommends => {ModuleBuildNonExistent => 3},
103 my $mb = Module::Build->new(module_name => $dist->name);
105 $mb->add_to_cleanup('save_out');
106 # Use uc() so we don't confuse the current test output
107 like uc(stdout_of( sub {$mb->dispatch('test', verbose => 1)} )), qr/^OK \d/m;
108 like uc(stdout_of( sub {$mb->dispatch('test', verbose => 0)} )), qr/\.\. ?OK/;
110 $mb->dispatch('realclean');
114 # Make sure 'config' entries are respected on the command line, and that
115 # Getopt::Long specs work as expected.
118 $dist->change_build_pl
120 module_name => @{[$dist->name]},
122 get_options => { foo => {},
123 bar => { type => '+' },
124 bat => { type => '=s' },
125 dee => { type => '=s',
132 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'])};
135 my $mb = Module::Build->resume;
136 ok $mb->valid_property('config');
138 is $mb->config('cc'), $Config{cc};
139 is $mb->config('foocakes'), 'barcakes';
142 is $mb->args('foo'), 1;
143 is $mb->args('bar'), 2, 'bar';
144 is $mb->args('bat'), 'hello', 'bat';
145 is $mb->args('gee'), 'whiz';
146 is $mb->args('any'), 'hey';
147 is $mb->args('dee'), 'goo';
148 is $mb->destdir, 'yo';
149 my %runtime = $mb->runtime_params;
155 config => { foocakes => 'barcakes' },
158 ok my $argsref = $mb->args;
159 is $argsref->{foo}, 1;
160 $argsref->{doo} = 'hee';
161 is $mb->args('doo'), 'hee';
162 ok my %args = $mb->args;
165 # revert test distribution to pristine state because we modified a file
167 $dist = DistGen->new( dir => $tmp );
174 my $mb = Module::Build->new(
175 module_name => $dist->name,
176 dist_author => 'Foo Meister <foo@example.com>',
177 build_class => 'My::Big::Fat::Builder',
180 ok ref($mb->dist_author), 'dist_author converted to array if simple string';
181 is $mb->dist_author->[0], 'Foo Meister <foo@example.com>';
182 is $mb->build_class, 'My::Big::Fat::Builder';
185 # Test conversion of shell strings
187 my $mb = Module::Build->new(
188 module_name => $dist->name,
189 dist_author => 'Foo Meister <foo@example.com>',
190 extra_compiler_flags => '-I/foo -I/bar',
191 extra_linker_flags => '-L/foo -L/bar',
194 is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
195 is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";
197 # Try again with command-line args
198 eval {Module::Build->run_perl_script('Build.PL', [], ['--extra_compiler_flags', '-I/foo -I/bar',
199 '--extra_linker_flags', '-L/foo -L/bar'])};
200 $mb = Module::Build->resume;
202 is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list";
203 is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list";