82dee7de92a0bd35 failed to add ext/lib/Makefile.PL. Oops.
[p5sagit/p5-mst-13.2.git] / ext / ExtUtils-MakeMaker / t / MakeMaker_Parameters.t
CommitLineData
b6d6132c 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
6BEGIN {
b78fd716 7 unshift @INC, 't/lib';
b6d6132c 8}
9
10use strict;
11use warnings;
12
13use ExtUtils::MakeMaker;
14use Test::More;
15
16my $mm = bless {}, "MM";
17
18sub 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
29sub 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
39is join("", $mm->_MakeMaker_Parameters_section()), <<'EXPECT', "nothing";
4facedc5 40# MakeMaker Parameters:
b6d6132c 41EXPECT
42
43test_round_trip({ NAME => "Foo" });
44test_round_trip({ NAME => "Foo", PREREQ_PM => { "Foo::Bar" => 0 } });
45test_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
67done_testing();
68