1#!/usr/bin/perl -w
2
3# This tests MakeMaker against recursive builds
4
5BEGIN {
6    unshift @INC, 't/lib';
7}
8
9use strict;
10use warnings;
11use MakeMaker::Test::Utils;
12use Config;
13use ExtUtils::MM;
14use Test::More
15    !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'}
16    ? (skip_all => "cross-compiling and make not available")
17    : (tests => 28);
18use File::Temp qw[tempdir];
19use File::Path;
20
21# 'make disttest' sets a bunch of environment variables which interfere
22# with our testing.
23delete @ENV{qw(PREFIX LIB MAKEFLAGS)};
24
25my $DIRNAME = 'Recurs';
26my $BASICMPL = <<'END';
27use ExtUtils::MakeMaker;
28WriteMakefile(NAME => 'Recurs', VERSION => 1.00);
29END
30my %FILES = (
31    'Makefile.PL'          => $BASICMPL,
32
33    'prj2/Makefile.PL'     => <<'END',
34use ExtUtils::MakeMaker;
35WriteMakefile(NAME => 'Recurs::prj2', VERSION => 1.00);
36END
37
38    # Check if a test failure in a subdir causes make test to fail
39    'prj2/t/fail.t'         => <<'END',
40#!/usr/bin/perl -w
41print "1..1\n";
42print "not ok 1\n";
43END
44);
45
46my $perl = which_perl();
47
48chdir 't';
49perl_lib; # sets $ENV{PERL5LIB} relative to t/
50
51my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
52use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
53chdir $tmpdir;
54
55$| = 1;
56
57hash2files($DIRNAME, \%FILES);
58END {
59    ok( chdir File::Spec->updir );
60    ok( rmtree($DIRNAME), 'teardown' );
61}
62
63ok( chdir($DIRNAME), q{chdir'd to Recurs} ) ||
64    diag("chdir failed: $!");
65
66
67# Check recursive Makefile building.
68my @mpl_out = run(qq{$perl Makefile.PL});
69
70cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
71  diag(@mpl_out);
72
73my $makefile = makefile_name();
74
75ok( -e $makefile, 'Makefile written' );
76ok( -e File::Spec->catfile('prj2',$makefile), 'sub Makefile written' );
77
78my $make = make_run();
79
80my $make_out = run("$make");
81is( $?, 0, 'recursive make exited normally' ) || diag $make_out;
82
83ok( chdir File::Spec->updir );
84ok( rmtree($DIRNAME), 'cleaning out recurs' );
85hash2files($DIRNAME, \%FILES);
86ok( chdir($DIRNAME), q{chdir'd to Recurs} ) ||
87    diag("chdir failed: $!");
88
89
90# Check NORECURS
91@mpl_out = run(qq{$perl Makefile.PL "NORECURS=1"});
92
93cmp_ok( $?, '==', 0, 'Makefile.PL NORECURS=1 exited with zero' ) ||
94  diag(@mpl_out);
95
96$makefile = makefile_name();
97
98ok( -e $makefile, 'Makefile written' );
99ok( !-e File::Spec->catfile('prj2',$makefile), 'sub Makefile not written' );
100
101$make = make_run();
102
103run("$make");
104is( $?, 0, 'recursive make exited normally' );
105
106
107ok( chdir File::Spec->updir );
108ok( rmtree($DIRNAME), 'cleaning out recurs' );
109hash2files($DIRNAME, \%FILES);
110ok( chdir($DIRNAME), q{chdir'd to Recurs} ) ||
111    diag("chdir failed: $!");
112
113
114# Check that arguments aren't stomped when they have .. prepended
115# [rt.perl.org 4345]
116@mpl_out = run(qq{$perl Makefile.PL "INST_SCRIPT=cgi"});
117
118cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
119  diag(@mpl_out);
120
121$makefile = makefile_name();
122my $submakefile = File::Spec->catfile('prj2',$makefile);
123
124ok( -e $makefile,    'Makefile written' );
125ok( -e $submakefile, 'sub Makefile written' );
126
127my $inst_script = File::Spec->catdir(File::Spec->updir, 'cgi');
128ok( open(MAKEFILE, $submakefile) ) || diag("Can't open $submakefile: $!");
129{ local $/;
130  like( <MAKEFILE>, qr/^\s*INST_SCRIPT\s*=\s*\Q$inst_script\E/m,
131        'prepend .. not stomping WriteMakefile args' )
132}
133close MAKEFILE;
134
135
136{
137    # Quiet "make test" failure noise
138    close *STDERR;
139
140    my $test_out = run("$make test");
141    isnt $?, 0, 'test failure in a subdir causes make to fail';
142}
143
144# test override of top_targets in sub-M.PL with no pure_nolink doesn't break
145ok( chdir File::Spec->updir );
146ok( rmtree($DIRNAME), 'cleaning out recurs' );
147hash2files($DIRNAME, {
148    'Makefile.PL'          => $BASICMPL,
149
150    'subdir/Makefile.PL'   => <<'EOF',
151use ExtUtils::MakeMaker;
152WriteMakefile(
153    NAME   => 'Recurs::subdir',
154    SKIP   => [qw(all static static_lib dynamic dynamic_lib)],
155);
156
157sub MY::top_targets {'
158all :: static
159
160pure_all :: static
161
162static :: libfcrypt$(LIB_EXT)
163
164libfcrypt$(LIB_EXT) :
165	$(TOUCH) libfcrypt$(LIB_EXT)
166
167dynamic :
168	$(NOOP)
169';
170}
171EOF
172
173});
174ok( chdir($DIRNAME), q{chdir'd to Recurs} ) ||
175    diag("chdir failed: $!");
176@mpl_out = run(qq{$perl Makefile.PL});
177
178cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
179  diag(@mpl_out);
180
181$make_out = run($make);
182is( $?, 0, 'recursive make exited normally' ) || diag $make_out;
183