File: MakeMaker_Parameters.t

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (68 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl -w

# Things like the CPAN shell rely on the "MakeMaker Parameters" section of the
# Makefile to learn a module's dependencies so we'd damn well better test it.

BEGIN {
    unshift @INC, 't/lib';
}

use strict;
use warnings;

use ExtUtils::MakeMaker;
use Test::More;

my $mm = bless {}, "MM";

sub extract_params {
    my $text = join "\n", @_;

    $text =~ s{^\s* \# \s+ MakeMaker\ Parameters: \s*\n}{}x;
    $text =~ s{^#}{}gms;
    $text =~ s{\n}{,\n}g;

    no strict 'subs';
    return { eval "$text" };
}

sub test_round_trip {
    my $args = shift;
    my $want = @_ ? shift : $args;

    my $have = extract_params($mm->_MakeMaker_Parameters_section($args));

    local $Test::Builder::Level = $Test::Builder::Level + 1;
    is_deeply $have, $want or diag explain $have, "\n", $want;
}

is join("", $mm->_MakeMaker_Parameters_section()), <<'EXPECT', "nothing";
#   MakeMaker Parameters:
EXPECT

test_round_trip({ NAME => "Foo" });
test_round_trip({ NAME => "Foo", PREREQ_PM => { "Foo::Bar" => 0 } });
test_round_trip({ NAME => "Foo", PREREQ_PM => { "Foo::Bar" => 1.23 } });

# Test the special case for BUILD_REQUIRES
{
    my $have = {
        NAME                => "Foo",
        PREREQ_PM           => { "Foo::Bar" => 1.23 },
        BUILD_REQUIRES      => { "Baz"      => 0.12 },
    };

    my $want = {
        NAME                => "Foo",
        PREREQ_PM           => {
            "Foo::Bar"  => 1.23,
            "Baz"       => 0.12,
        },
        BUILD_REQUIRES      => { "Baz"      => 0.12 },
    };

    test_round_trip( $have, $want );
}

done_testing();