postamble.t revision 1.2
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
17use File::Temp qw[tempdir];
18my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
19chdir $tmpdir;
20perl_lib;
21$| = 1;
22
23my $Makefile = makefile_name;
24
25ok( setup_recurs(), 'setup' );
26END {
27    ok( chdir File::Spec->updir );
28    ok( teardown_recurs(), 'teardown' );
29}
30
31ok( chdir 'Big-Dummy', q{chdir'd to Big-Dummy} ) ||
32        diag("chdir failed: $!");
33
34{
35    my $warnings = '';
36    local $SIG{__WARN__} = sub {
37        if ( $Config{usecrosscompile} ) {
38            # libraries might not be present on the target system
39            # when cross-compiling
40            return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/
41        }
42        $warnings = join '', @_;
43    };
44
45    my $stdout = tie *STDOUT, 'TieOut' or die;
46    my $mm = WriteMakefile(
47                           NAME            => 'Big::Dummy',
48                           VERSION_FROM    => 'lib/Big/Dummy.pm',
49                           postamble       => {
50                                               FOO => 1,
51                                               BAR => "fugawazads"
52                                              }
53                          );
54    is( $warnings, '', 'postamble argument not warned about' );
55}
56
57sub MY::postamble {
58    my($self, %extra) = @_;
59
60    is_deeply( \%extra, { FOO => 1, BAR => 'fugawazads' },
61               'postamble args passed' );
62
63    return <<OUT;
64# This makes sure the postamble gets written
65OUT
66
67}
68
69
70ok( open(MAKEFILE, $Makefile) ) or diag "Can't open $Makefile: $!";
71{ local $/;
72  like( <MAKEFILE>, qr/^\# This makes sure the postamble gets written\n/m,
73        'postamble added to the Makefile' );
74}
75close MAKEFILE;
76