postamble.t revision 1.3
1#!/usr/bin/perl -w
2
3# Wherein we ensure that postamble works ok.
4
5BEGIN {
6    unshift @INC, 't/lib';
7}
8
9use strict;
10use Config;
11use Test::More tests => 8;
12use MakeMaker::Test::Utils;
13use MakeMaker::Test::Setup::BFD;
14use ExtUtils::MakeMaker;
15use TieOut;
16
17chdir 't';
18perl_lib; # sets $ENV{PERL5LIB} relative to t/
19
20use File::Temp qw[tempdir];
21my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
22use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
23chdir $tmpdir;
24$| = 1;
25
26my $Makefile = makefile_name;
27
28ok( setup_recurs(), 'setup' );
29END {
30    ok( chdir File::Spec->updir );
31    ok( teardown_recurs(), 'teardown' );
32}
33
34ok( chdir 'Big-Dummy', q{chdir'd to Big-Dummy} ) ||
35        diag("chdir failed: $!");
36
37{
38    my $warnings = '';
39    local $SIG{__WARN__} = sub {
40        if ( $Config{usecrosscompile} ) {
41            # libraries might not be present on the target system
42            # when cross-compiling
43            return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/
44        }
45        $warnings = join '', @_;
46    };
47
48    my $stdout = tie *STDOUT, 'TieOut' or die;
49    my $mm = WriteMakefile(
50                           NAME            => 'Big::Dummy',
51                           VERSION_FROM    => 'lib/Big/Dummy.pm',
52                           postamble       => {
53                                               FOO => 1,
54                                               BAR => "fugawazads"
55                                              }
56                          );
57    is( $warnings, '', 'postamble argument not warned about' );
58}
59
60sub MY::postamble {
61    my($self, %extra) = @_;
62
63    is_deeply( \%extra, { FOO => 1, BAR => 'fugawazads' },
64               'postamble args passed' );
65
66    return <<OUT;
67# This makes sure the postamble gets written
68OUT
69
70}
71
72
73ok( open(MAKEFILE, $Makefile) ) or diag "Can't open $Makefile: $!";
74{ local $/;
75  like( <MAKEFILE>, qr/^\# This makes sure the postamble gets written\n/m,
76        'postamble added to the Makefile' );
77}
78close MAKEFILE;
79