xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/prereq.t (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
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 warnings;
12use Config;
13use Test::More tests => 21;
14use File::Temp qw[tempdir];
15
16use TieOut;
17use MakeMaker::Test::Utils;
18use MakeMaker::Test::Setup::BFD;
19
20use ExtUtils::MakeMaker;
21
22chdir 't';
23perl_lib; # sets $ENV{PERL5LIB} relative to t/
24
25my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
26use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
27chdir $tmpdir;
28
29ok( setup_recurs(), 'setup' );
30END {
31    ok( chdir File::Spec->updir, 'chdir updir' );
32    ok( teardown_recurs(), 'teardown' );
33}
34
35ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
36  diag("chdir failed: $!");
37
38{
39    ok my $stdout = tie(*STDOUT, 'TieOut'), 'tie STDOUT';
40    my $warnings = '';
41    local $SIG{__WARN__} = sub {
42        if ( $Config{usecrosscompile} ) {
43            # libraries might not be present on the target system
44            # when cross-compiling
45            return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/
46        }
47        $warnings .= join '', @_;
48    };
49    # prerequisite warnings are disabled while building the perl core:
50    local $ExtUtils::MakeMaker::UNDER_CORE = 0;
51
52    WriteMakefile(
53        NAME            => 'Big::Dummy',
54        PREREQ_PM       => {
55            strict  => 0
56        }
57    );
58    is $warnings, '', 'basic prereq';
59
60    SKIP: {
61	skip 'No CMR, no version ranges', 1
62	    unless ExtUtils::MakeMaker::_has_cpan_meta_requirements;
63	$warnings = '';
64	WriteMakefile(
65	    NAME            => 'Big::Dummy',
66	    PREREQ_PM       => {
67		strict  =>  '>= 0, <= 99999',
68	    }
69	);
70	is $warnings, '', 'version range';
71    }
72
73    $warnings = '';
74    WriteMakefile(
75        NAME            => 'Big::Dummy',
76        PREREQ_PM       => {
77            strict  => 99999
78        }
79    );
80    is $warnings,
81    sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n",
82            $strict::VERSION), 'strict 99999';
83
84    $warnings = '';
85    WriteMakefile(
86        NAME            => 'Big::Dummy',
87        PREREQ_PM       => {
88            "I::Do::Not::Exist" => 0,
89        }
90    );
91    is $warnings,
92    "Warning: prerequisite I::Do::Not::Exist 0 not found.\n", 'non-exist prereq';
93
94    $warnings = '';
95    WriteMakefile(
96        NAME            => 'Big::Dummy',
97        CONFIGURE_REQUIRES => {
98            "I::Do::Not::Configure" => 0,
99        }
100    );
101    is $warnings,
102    "Warning: prerequisite I::Do::Not::Configure 0 not found.\n", 'non-exist prereq';
103
104    $warnings = '';
105    WriteMakefile(
106        NAME            => 'Big::Dummy',
107        TEST_REQUIRES => {
108            "I::Do::Not::Test" => 0,
109        }
110    );
111    is $warnings,
112    "Warning: prerequisite I::Do::Not::Test 0 not found.\n", 'non-exist prereq';
113
114
115    $warnings = '';
116    WriteMakefile(
117        NAME            => 'Big::Dummy',
118        PREREQ_PM       => {
119            "I::Do::Not::Exist" => "",
120        }
121    );
122    my @warnings = split /\n/, $warnings;
123    is @warnings, 2, '2 warnings';
124    like $warnings[0], qr{^Undefined requirement for I::Do::Not::Exist\b}, 'undef version warning';
125    is $warnings[1], "Warning: prerequisite I::Do::Not::Exist 0 not found.", 'not found warning';
126
127
128    $warnings = '';
129    WriteMakefile(
130        NAME            => 'Big::Dummy',
131        PREREQ_PM       => {
132            "I::Do::Not::Exist" => 0,
133            "strict"            => 99999,
134        }
135    );
136
137    my $strict_warn
138        = sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n",
139                                                            $strict::VERSION);
140    # Done this way because EBCDIC sorts in a different order
141    ok(   $warnings =~ s/Warning: prerequisite I::Do::Not::Exist 0 not found\.\n//
142       && $warnings =~ s/\Q$strict_warn//
143       && $warnings eq "", '2 bad prereq warnings');
144
145    $warnings = '';
146    eval {
147        WriteMakefile(
148            NAME            => 'Big::Dummy',
149            PREREQ_PM       => {
150                "I::Do::Not::Exist" => 0,
151                "Nor::Do::I"        => 0,
152                "strict"            => 99999,
153            },
154            PREREQ_FATAL    => 1,
155        );
156    };
157
158    is $warnings, '', 'no warnings on PREREQ_FATAL';
159    is $@, <<'END', "PREREQ_FATAL";
160MakeMaker FATAL: prerequisites not found.
161    I::Do::Not::Exist not installed
162    Nor::Do::I not installed
163    strict 99999
164
165Please install these modules first and rerun 'perl Makefile.PL'.
166END
167
168
169    $warnings = '';
170    eval {
171        WriteMakefile(
172            NAME            => 'Big::Dummy',
173            PREREQ_PM       => {
174                "I::Do::Not::Exist" => 0,
175            },
176            CONFIGURE => sub {
177                require I::Do::Not::Exist;
178            },
179            PREREQ_FATAL    => 1,
180        );
181    };
182
183    is $warnings, '', 'CONFIGURE sub non-exist req no warn';
184    is $@, <<'END', "PREREQ_FATAL happens before CONFIGURE";
185MakeMaker FATAL: prerequisites not found.
186    I::Do::Not::Exist not installed
187
188Please install these modules first and rerun 'perl Makefile.PL'.
189END
190
191
192    $warnings = '';
193    @ARGV = 'PREREQ_FATAL=1';
194    eval {
195        WriteMakefile(
196            NAME => 'Big::Dummy',
197            PREREQ_PM => { "I::Do::Not::Exist" => 0, },
198        );
199    };
200    is $warnings, "Warning: prerequisite I::Do::Not::Exist 0 not found.\n",
201      'CLI PREREQ_FATAL warns';
202    isnt $@, '', "CLI PREREQ_FATAL works";
203
204}
205