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