1#!/usr/bin/perl -w
2
3use strict;
4use warnings;
5
6use lib 't/lib';
7
8use File::Temp qw[tempdir];
9my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
10use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
11chdir $tmpdir;
12use File::Spec;
13
14use Test::More tests => 3;
15
16# Having the CWD in @INC masked a bug in finding hint files
17my $curdir = File::Spec->curdir;
18@INC = grep { $_ ne $curdir && $_ ne '.' } @INC;
19
20use ExtUtils::MakeMaker;
21
22# Make a hints directory for testing
23mkdir('hints', 0777);
24(my $os = $^O) =~ s/\./_/g;
25my $Hint_File = File::Spec->catfile('hints', "$os.pl");
26
27
28my $mm = bless {}, 'ExtUtils::MakeMaker';
29
30# Write a hints file for testing
31{
32    open my $hint_fh, ">", $Hint_File || die "Can't write dummy hints file $Hint_File: $!";
33    print $hint_fh <<'CLOO';
34$self->{CCFLAGS} = 'basset hounds got long ears';
35CLOO
36}
37
38# Test our hint file is detected
39{
40    my $stderr = '';
41    local $SIG{__WARN__} = sub { $stderr .= join '', @_ };
42
43    $mm->check_hints;
44    is( $mm->{CCFLAGS}, 'basset hounds got long ears' );
45    is( $stderr, "" );
46}
47
48
49# Test a hint file which dies
50{
51    open my $hint_fh, ">", $Hint_File || die "Can't write dummy hints file $Hint_File: $!";
52    print $hint_fh <<'CLOO';
53die "Argh!\n";
54CLOO
55}
56
57
58# Test the hint file which produces errors
59{
60    my $stderr = '';
61    local $SIG{__WARN__} = sub { $stderr .= join '', @_ };
62
63    $mm->check_hints;
64    is( $stderr, <<OUT, 'hint files produce errors' );
65Argh!
66OUT
67}
68
69END {
70    use File::Path;
71    rmtree ['hints'];
72}
73