1# Test problems in Makefile.PL's and hint files.
2
3BEGIN {
4    unshift @INC, 't/lib';
5}
6chdir 't';
7
8use strict;
9use Test::More tests => 5;
10use ExtUtils::MM;
11use MakeMaker::Test::Utils;
12use File::Path;
13use TieOut;
14
15my $MM = bless { DIR => ['subdir'] }, 'MM';
16my $DIRNAME = 'Problem-Module';
17my %FILES = (
18    'Makefile.PL'   => <<'END',
19use ExtUtils::MakeMaker;
20WriteMakefile(NAME    => 'Problem::Module');
21END
22
23    'subdir/Makefile.PL'    => <<'END',
24printf "\@INC %s .\n", (grep { $_ eq '.' } @INC) ? "has" : "doesn't have";
25warn "I think I'm going to be sick\n";
26die "YYYAaaaakkk\n";
27END
28
29);
30
31hash2files($DIRNAME, \%FILES);
32END {
33    ok( chdir File::Spec->updir, 'chdir ..' );
34    ok( rmtree($DIRNAME), 'teardown' );
35}
36
37ok( chdir $DIRNAME, "chdir'd to Problem-Module" ) ||
38  diag("chdir failed: $!");
39
40
41# Make sure when Makefile.PL's break, they issue a warning.
42# Also make sure Makefile.PL's in subdirs still have '.' in @INC.
43{
44    my $stdout = tie *STDOUT, 'TieOut' or die;
45
46    my $warning = '';
47    local $SIG{__WARN__} = sub { $warning = join '', @_ };
48    eval { $MM->eval_in_subdirs; };
49
50    is( $stdout->read, qq{\@INC has .\n}, 'cwd in @INC' );
51    like( $@,
52          qr{^ERROR from evaluation of .*subdir.*Makefile.PL: YYYAaaaakkk},
53          'Makefile.PL death in subdir warns' );
54
55    untie *STDOUT;
56}
57