This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update ExtUtils-MakeMaker to CPAN version 7.02
[perl5.git] / cpan / ExtUtils-MakeMaker / t / postamble.t
1 #!/usr/bin/perl -w
2
3 # Wherein we ensure that postamble works ok.
4
5 BEGIN {
6     unshift @INC, 't/lib';
7 }
8
9 use strict;
10 use Config;
11 use Test::More tests => 8;
12 use MakeMaker::Test::Utils;
13 use MakeMaker::Test::Setup::BFD;
14 use ExtUtils::MakeMaker;
15 use TieOut;
16
17 use File::Temp qw[tempdir];
18 my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
19 chdir $tmpdir;
20 perl_lib;
21 $| = 1;
22
23 my $Makefile = makefile_name;
24
25 ok( setup_recurs(), 'setup' );
26 END {
27     ok( chdir File::Spec->updir );
28     ok( teardown_recurs(), 'teardown' );
29 }
30
31 ok( 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
57 sub 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
65 OUT
66
67 }
68
69
70 ok( 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 }
75 close MAKEFILE;