xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/prereq.t (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1#!/usr/bin/perl -w
2
3# This is a test of the verification of the arguments to
4# WriteMakefile.
5
6BEGIN {
7    unshift @INC, 't/lib';
8}
9
10use strict;
11use Test::More tests => 16;
12
13use TieOut;
14use MakeMaker::Test::Utils;
15use MakeMaker::Test::Setup::BFD;
16
17use ExtUtils::MakeMaker;
18
19chdir 't';
20
21perl_lib();
22
23ok( setup_recurs(), 'setup' );
24END {
25    ok( chdir File::Spec->updir );
26    ok( teardown_recurs(), 'teardown' );
27}
28
29ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
30  diag("chdir failed: $!");
31
32{
33    ok( my $stdout = tie *STDOUT, 'TieOut' );
34    my $warnings = '';
35    local $SIG{__WARN__} = sub {
36        $warnings .= join '', @_;
37    };
38    # prerequisite warnings are disabled while building the perl core:
39    local $ENV{PERL_CORE} = 0;
40
41    WriteMakefile(
42        NAME            => 'Big::Dummy',
43        PREREQ_PM       => {
44            strict  => 0
45        }
46    );
47    is $warnings, '';
48
49    $warnings = '';
50    WriteMakefile(
51        NAME            => 'Big::Dummy',
52        PREREQ_PM       => {
53            strict  => 99999
54        }
55    );
56    is $warnings,
57    sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n",
58            $strict::VERSION);
59
60    $warnings = '';
61    WriteMakefile(
62        NAME            => 'Big::Dummy',
63        PREREQ_PM       => {
64            "I::Do::Not::Exist" => 0,
65        }
66    );
67    is $warnings,
68    "Warning: prerequisite I::Do::Not::Exist 0 not found.\n";
69
70
71    $warnings = '';
72    WriteMakefile(
73        NAME            => 'Big::Dummy',
74        PREREQ_PM       => {
75            "I::Do::Not::Exist" => "",
76        }
77    );
78    my @warnings = split /\n/, $warnings;
79    is @warnings, 2;
80    like $warnings[0], qr{^Unparsable version '' for prerequisite I::Do::Not::Exist\b};
81    is $warnings[1], "Warning: prerequisite I::Do::Not::Exist 0 not found.";
82
83
84    $warnings = '';
85    WriteMakefile(
86        NAME            => 'Big::Dummy',
87        PREREQ_PM       => {
88            "I::Do::Not::Exist" => 0,
89            "strict"            => 99999,
90        }
91    );
92    is $warnings,
93    "Warning: prerequisite I::Do::Not::Exist 0 not found.\n".
94    sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n",
95            $strict::VERSION);
96
97    $warnings = '';
98    eval {
99        WriteMakefile(
100            NAME            => 'Big::Dummy',
101            PREREQ_PM       => {
102                "I::Do::Not::Exist" => 0,
103                "Nor::Do::I"        => 0,
104                "strict"            => 99999,
105            },
106            PREREQ_FATAL    => 1,
107        );
108    };
109
110    is $warnings, '';
111    is $@, <<'END', "PREREQ_FATAL";
112MakeMaker FATAL: prerequisites not found.
113    I::Do::Not::Exist not installed
114    Nor::Do::I not installed
115    strict 99999
116
117Please install these modules first and rerun 'perl Makefile.PL'.
118END
119
120
121    $warnings = '';
122    eval {
123        WriteMakefile(
124            NAME            => 'Big::Dummy',
125            PREREQ_PM       => {
126                "I::Do::Not::Exist" => 0,
127            },
128            CONFIGURE => sub {
129                require I::Do::Not::Exist;
130            },
131            PREREQ_FATAL    => 1,
132        );
133    };
134
135    is $warnings, '';
136    is $@, <<'END', "PREREQ_FATAL happens before CONFIGURE";
137MakeMaker FATAL: prerequisites not found.
138    I::Do::Not::Exist not installed
139
140Please install these modules first and rerun 'perl Makefile.PL'.
141END
142
143}
144