This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update ExtUtils-MakeMaker to CPAN version 6.70
[perl5.git] / cpan / ExtUtils-MakeMaker / t / prereq.t
1 #!/usr/bin/perl -w
2
3 # This is a test of the verification of the arguments to
4 # WriteMakefile.
5
6 BEGIN {
7     unshift @INC, 't/lib';
8 }
9
10 use strict;
11 use Test::More tests => 16;
12
13 use TieOut;
14 use MakeMaker::Test::Utils;
15 use MakeMaker::Test::Setup::BFD;
16
17 use ExtUtils::MakeMaker;
18
19 chdir 't';
20
21 perl_lib();
22
23 ok( setup_recurs(), 'setup' );
24 END {
25     ok( chdir File::Spec->updir );
26     ok( teardown_recurs(), 'teardown' );
27 }
28
29 ok( 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";
112 MakeMaker FATAL: prerequisites not found.
113     I::Do::Not::Exist not installed
114     Nor::Do::I not installed
115     strict 99999
116
117 Please install these modules first and rerun 'perl Makefile.PL'.
118 END
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";
137 MakeMaker FATAL: prerequisites not found.
138     I::Do::Not::Exist not installed
139
140 Please install these modules first and rerun 'perl Makefile.PL'.
141 END
142
143 }