1b39c5158Smillert#!/usr/bin/perl -w 2b39c5158Smillert 391f110e0Safresh1use strict; 491f110e0Safresh1use warnings; 591f110e0Safresh1 691f110e0Safresh1use lib 't/lib'; 7b39c5158Smillert 86fb12b70Safresh1use File::Temp qw[tempdir]; 96fb12b70Safresh1my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 ); 105759b3d2Safresh1use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup 116fb12b70Safresh1chdir $tmpdir; 12b39c5158Smillertuse File::Spec; 13b39c5158Smillert 14b39c5158Smillertuse Test::More tests => 3; 15b39c5158Smillert 16b39c5158Smillert# Having the CWD in @INC masked a bug in finding hint files 17b39c5158Smillertmy $curdir = File::Spec->curdir; 18b39c5158Smillert@INC = grep { $_ ne $curdir && $_ ne '.' } @INC; 19b39c5158Smillert 20b39c5158Smillertuse ExtUtils::MakeMaker; 21b39c5158Smillert 2291f110e0Safresh1# Make a hints directory for testing 2391f110e0Safresh1mkdir('hints', 0777); 2491f110e0Safresh1(my $os = $^O) =~ s/\./_/g; 2591f110e0Safresh1my $Hint_File = File::Spec->catfile('hints', "$os.pl"); 2691f110e0Safresh1 2791f110e0Safresh1 28b39c5158Smillertmy $mm = bless {}, 'ExtUtils::MakeMaker'; 2991f110e0Safresh1 3091f110e0Safresh1# Write a hints file for testing 3191f110e0Safresh1{ 3291f110e0Safresh1 open my $hint_fh, ">", $Hint_File || die "Can't write dummy hints file $Hint_File: $!"; 3391f110e0Safresh1 print $hint_fh <<'CLOO'; 3491f110e0Safresh1$self->{CCFLAGS} = 'basset hounds got long ears'; 3591f110e0Safresh1CLOO 3691f110e0Safresh1} 3791f110e0Safresh1 3891f110e0Safresh1# Test our hint file is detected 3991f110e0Safresh1{ 4091f110e0Safresh1 my $stderr = ''; 4191f110e0Safresh1 local $SIG{__WARN__} = sub { $stderr .= join '', @_ }; 4291f110e0Safresh1 43b39c5158Smillert $mm->check_hints; 44b39c5158Smillert is( $mm->{CCFLAGS}, 'basset hounds got long ears' ); 455759b3d2Safresh1 is( $stderr, "" ); 4691f110e0Safresh1} 47b39c5158Smillert 4891f110e0Safresh1 4991f110e0Safresh1# Test a hint file which dies 5091f110e0Safresh1{ 5191f110e0Safresh1 open my $hint_fh, ">", $Hint_File || die "Can't write dummy hints file $Hint_File: $!"; 5291f110e0Safresh1 print $hint_fh <<'CLOO'; 53b39c5158Smillertdie "Argh!\n"; 54b39c5158SmillertCLOO 5591f110e0Safresh1} 5691f110e0Safresh1 5791f110e0Safresh1 5891f110e0Safresh1# Test the hint file which produces errors 5991f110e0Safresh1{ 6091f110e0Safresh1 my $stderr = ''; 6191f110e0Safresh1 local $SIG{__WARN__} = sub { $stderr .= join '', @_ }; 62b39c5158Smillert 63b39c5158Smillert $mm->check_hints; 64*f2a19305Safresh1 is( $stderr, <<OUT, 'hint files produce errors' ); 65*f2a19305Safresh1Argh! 66*f2a19305Safresh1OUT 6791f110e0Safresh1} 68b39c5158Smillert 69b39c5158SmillertEND { 70b39c5158Smillert use File::Path; 71b39c5158Smillert rmtree ['hints']; 72b39c5158Smillert} 73