4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
9 # Don't let our own verbosity/test_file get mixed up with our subprocess's
10 my @makefile_keys = qw(TEST_VERBOSE HARNESS_VERBOSE TEST_FILES MAKEFLAGS);
11 local @ENV{@makefile_keys};
12 delete @ENV{@makefile_keys};
14 my @makefile_types = qw(small passthrough traditional);
15 my $tests_per_type = 10;
16 if ( $Config{make} && find_in_path($Config{make}) ) {
17 plan tests => 30 + @makefile_types*$tests_per_type;
19 plan skip_all => "Don't know how to invoke 'make'";
24 #########################
28 my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
31 my $dist = DistGen->new( dir => $tmp );
34 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
37 #########################
40 use Module::Build::Compat;
42 use Carp; $SIG{__WARN__} = \&Carp::cluck;
44 my @make = $Config{make} eq 'nmake' ? ('nmake', '-nologo') : ($Config{make});
46 #########################
49 my $mb = Module::Build->new_from_context;
52 foreach my $type (@makefile_types) {
53 Module::Build::Compat->create_makefile_pl($type, $mb);
54 test_makefile_creation($mb);
56 ok $mb->do_system(@make);
58 # Can't let 'test' STDOUT go to our STDOUT, or it'll confuse Test::Harness.
60 my $output = stdout_of( sub {
61 $success = $mb->do_system(@make, 'test');
64 like uc $output, qr{DONE\.|SUCCESS};
66 ok $mb->do_system(@make, 'realclean');
68 # Try again with some Makefile.PL arguments
69 test_makefile_creation($mb, [], 'INSTALLDIRS=vendor', 1);
71 1 while unlink 'Makefile.PL';
72 ok ! -e 'Makefile.PL';
76 # Make sure fake_makefile() can run without 'build_class', as it may be
77 # in older-generated Makefile.PLs
79 local $SIG{__WARN__} = sub { $warning = shift; };
80 my $maketext = eval { Module::Build::Compat->fake_makefile(makefile => 'Makefile') };
82 like $maketext, qr/^realclean/m;
83 like $warning, qr/build_class/;
87 # Make sure custom builder subclass is used in the created
88 # Makefile.PL - make sure it fails in the right way here.
89 local @Foo::Builder::ISA = qw(Module::Build);
90 my $foo_builder = Foo::Builder->new_from_context;
91 foreach my $style ('passthrough', 'small') {
92 Module::Build::Compat->create_makefile_pl($style, $foo_builder);
95 # Should fail with "can't find Foo/Builder.pm"
96 my $warning = stderr_of
98 my $result = $mb->run_perl_script('Makefile.PL');
101 like $warning, qr{Foo/Builder.pm};
104 # Now make sure it can actually work.
105 my $bar_builder = Module::Build->subclass( class => 'Bar::Builder' )->new_from_context;
106 foreach my $style ('passthrough', 'small') {
107 Module::Build::Compat->create_makefile_pl($style, $bar_builder);
109 ok $mb->run_perl_script('Makefile.PL');
114 # Make sure various Makefile.PL arguments are supported
115 Module::Build::Compat->create_makefile_pl('passthrough', $mb);
117 my $libdir = File::Spec->catdir( $cwd, 't', 'libdir' );
118 my $result = $mb->run_perl_script('Makefile.PL', [],
129 my $new_build = Module::Build->resume();
130 is $new_build->installdirs, 'core';
131 is $new_build->verbose, 1;
132 is $new_build->install_destination('lib'), $libdir;
133 is $new_build->extra_compiler_flags->[0], '-DPERL_POLLUTE';
135 # Make sure those switches actually had an effect
136 my ($ran_ok, $output);
137 $output = stdout_of( sub { $ran_ok = $new_build->do_system(@make, 'test') } );
139 $output =~ s/^/# /gm; # Don't confuse our own test output
140 like $output, qr/(?:# ok \d+\s+)+/, 'Should be verbose';
142 # Make sure various Makefile arguments are supported
143 $output = stdout_of( sub { $ran_ok = $mb->do_system(@make, 'test', 'TEST_VERBOSE=0') } );
145 $output =~ s/^/# /gm; # Don't confuse our own test output
146 like $output, qr/(?:# .+basic\.+ok\s+(?:[\d.]s\s*)?)+# All tests/,
147 'Should be non-verbose';
149 $mb->delete_filetree($libdir);
150 ok ! -e $libdir, "Sample installation directory should be cleaned up";
152 $mb->do_system(@make, 'realclean');
153 ok ! -e 'Makefile', "Makefile shouldn't exist";
155 1 while unlink 'Makefile.PL';
156 ok ! -e 'Makefile.PL';
159 { # Make sure tilde-expansion works
161 # C<glob> on MSWin32 uses $ENV{HOME} if defined to do tilde-expansion
162 local $ENV{HOME} = 'C:/' if $^O =~ /MSWin/ && !exists( $ENV{HOME} );
164 Module::Build::Compat->create_makefile_pl('passthrough', $mb);
166 $mb->run_perl_script('Makefile.PL', [], ['INSTALL_BASE=~/foo']);
167 my $b2 = Module::Build->current;
168 ok $b2->install_base;
169 unlike $b2->install_base, qr/^~/, "Tildes should be expanded";
171 $mb->do_system(@make, 'realclean');
172 1 while unlink 'Makefile.PL';
174 #########################################################
176 sub test_makefile_creation {
177 my ($build, $preargs, $postargs, $cleanup) = @_;
179 my $result = $build->run_perl_script('Makefile.PL', $preargs, $postargs);
181 ok -e 'Makefile', "Makefile should exist";
184 $build->do_system(@make, 'realclean');
185 ok ! -e 'Makefile', "Makefile shouldn't exist";
191 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";