summaryrefslogtreecommitdiff
path: root/cpan/ExtUtils-MakeMaker/t/hints.t
blob: af4d18367a5f7e9b717fdb881602e91e87d908d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl -w

use strict;
use warnings;

use lib 't/lib';

use File::Temp qw[tempdir];
my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
chdir $tmpdir;
use File::Spec;

use Test::More tests => 3;

# Having the CWD in @INC masked a bug in finding hint files
my $curdir = File::Spec->curdir;
@INC = grep { $_ ne $curdir && $_ ne '.' } @INC;

use ExtUtils::MakeMaker;

# Make a hints directory for testing
mkdir('hints', 0777);
(my $os = $^O) =~ s/\./_/g;
my $Hint_File = File::Spec->catfile('hints', "$os.pl");


my $mm = bless {}, 'ExtUtils::MakeMaker';

# Write a hints file for testing
{
    open my $hint_fh, ">", $Hint_File || die "Can't write dummy hints file $Hint_File: $!";
    print $hint_fh <<'CLOO';
$self->{CCFLAGS} = 'basset hounds got long ears';
CLOO
}

# Test our hint file is detected
{
    my $stderr = '';
    local $SIG{__WARN__} = sub { $stderr .= join '', @_ };

    $mm->check_hints;
    is( $mm->{CCFLAGS}, 'basset hounds got long ears' );
    is( $stderr, "Processing hints file $Hint_File\n" );
}


# Test a hint file which dies
{
    open my $hint_fh, ">", $Hint_File || die "Can't write dummy hints file $Hint_File: $!";
    print $hint_fh <<'CLOO';
die "Argh!\n";
CLOO
}


# Test the hint file which produces errors
{
    my $stderr = '';
    local $SIG{__WARN__} = sub { $stderr .= join '', @_ };

    $mm->check_hints;
    is( $stderr, <<OUT, 'hint files produce errors' );
Processing hints file $Hint_File
Argh!
OUT
}

END {
    use File::Path;
    rmtree ['hints'];
}