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