82dee7de92a0bd35 failed to add ext/lib/Makefile.PL. Oops.
[p5sagit/p5-mst-13.2.git] / ext / ExtUtils-MakeMaker / t / MakeMaker_Parameters.t
1 #!/usr/bin/perl -w
2
3 # Things like the CPAN shell rely on the "MakeMaker Parameters" section of the
4 # Makefile to learn a module's dependencies so we'd damn well better test it.
5
6 BEGIN {
7     unshift @INC, 't/lib';
8 }
9
10 use strict;
11 use warnings;
12
13 use ExtUtils::MakeMaker;
14 use Test::More;
15
16 my $mm = bless {}, "MM";
17
18 sub extract_params {
19     my $text = join "\n", @_;
20
21     $text =~ s{^\s* \# \s+ MakeMaker\ Parameters: \s*\n}{}x;
22     $text =~ s{^#}{}gms;
23     $text =~ s{\n}{,\n}g;
24
25     no strict 'subs';
26     return { eval "$text" };
27 }
28
29 sub test_round_trip {
30     my $args = shift;
31     my $want = @_ ? shift : $args;
32
33     my $have = extract_params($mm->_MakeMaker_Parameters_section($args));
34
35     local $Test::Builder::Level = $Test::Builder::Level + 1;
36     is_deeply $have, $want or diag explain $have, "\n", $want;
37 }
38
39 is join("", $mm->_MakeMaker_Parameters_section()), <<'EXPECT', "nothing";
40 #   MakeMaker Parameters:
41 EXPECT
42
43 test_round_trip({ NAME => "Foo" });
44 test_round_trip({ NAME => "Foo", PREREQ_PM => { "Foo::Bar" => 0 } });
45 test_round_trip({ NAME => "Foo", PREREQ_PM => { "Foo::Bar" => 1.23 } });
46
47 # Test the special case for BUILD_REQUIRES
48 {
49     my $have = {
50         NAME                => "Foo",
51         PREREQ_PM           => { "Foo::Bar" => 1.23 },
52         BUILD_REQUIRES      => { "Baz"      => 0.12 },
53     };
54
55     my $want = {
56         NAME                => "Foo",
57         PREREQ_PM           => {
58             "Foo::Bar"  => 1.23,
59             "Baz"       => 0.12,
60         },
61         BUILD_REQUIRES      => { "Baz"      => 0.12 },
62     };
63
64     test_round_trip( $have, $want );
65 }
66
67 done_testing();
68