Commit | Line | Data |
bf87a6a1 |
1 | #!/usr/bin/perl -w |
2 | |
3 | # This is a test checking various aspects of the optional argument |
4 | # MIN_PERL_VERSION to WriteMakefile. |
5 | |
6 | BEGIN { |
7 | if( $ENV{PERL_CORE} ) { |
8 | chdir 't' if -d 't'; |
9 | @INC = ('../lib', 'lib'); |
10 | } |
11 | else { |
12 | unshift @INC, 't/lib'; |
13 | } |
14 | } |
15 | |
16 | use strict; |
17 | use Test::More tests => 33; |
18 | |
19 | use TieOut; |
20 | use MakeMaker::Test::Utils; |
21 | use MakeMaker::Test::Setup::MPV; |
22 | use File::Path; |
23 | |
24 | use ExtUtils::MakeMaker; |
25 | |
26 | # avoid environment variables interfering with our make runs |
27 | delete @ENV{qw(LIB MAKEFLAGS)}; |
28 | |
29 | my $perl = which_perl(); |
30 | my $make = make_run(); |
31 | my $makefile = makefile_name(); |
32 | |
33 | chdir 't'; |
34 | |
35 | perl_lib(); |
36 | |
37 | ok( setup_recurs(), 'setup' ); |
38 | END { |
39 | ok( chdir(File::Spec->updir), 'leaving dir' ); |
40 | ok( teardown_recurs(), 'teardown' ); |
41 | } |
42 | |
43 | ok( chdir 'Min-PerlVers', 'entering dir Min-PerlVers' ) || |
44 | diag("chdir failed: $!"); |
45 | |
46 | { |
47 | # ----- argument verification ----- |
48 | |
49 | my $stdout = tie *STDOUT, 'TieOut'; |
50 | ok( $stdout, 'capturing stdout' ); |
51 | my $warnings = ''; |
52 | local $SIG{__WARN__} = sub { |
53 | $warnings .= join '', @_; |
54 | }; |
55 | |
56 | eval { |
57 | WriteMakefile( |
58 | NAME => 'Min::PerlVers', |
59 | MIN_PERL_VERSION => '5', |
60 | ); |
61 | }; |
62 | is( $warnings, '', 'MIN_PERL_VERSION=5 does not trigger a warning' ); |
63 | is( $@, '', ' nor a hard failure' ); |
64 | |
65 | |
66 | $warnings = ''; |
67 | eval { |
68 | WriteMakefile( |
69 | NAME => 'Min::PerlVers', |
70 | MIN_PERL_VERSION => '5.4.4', |
71 | ); |
72 | }; |
73 | is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' ); |
74 | is( $@, '', ' nor a hard failure' ); |
75 | |
76 | |
77 | $warnings = ''; |
78 | eval { |
79 | WriteMakefile( |
80 | NAME => 'Min::PerlVers', |
81 | MIN_PERL_VERSION => '999999', |
82 | ); |
83 | }; |
84 | ok( '' ne $warnings, 'MIN_PERL_VERSION=999999 triggers a warning' ); |
85 | is( $warnings, |
86 | "Warning: Perl version 999999 or higher required. We run $].\n", |
87 | ' with expected message text' ); |
88 | is( $@, '', ' and without a hard failure' ); |
89 | |
90 | $warnings = ''; |
91 | eval { |
92 | WriteMakefile( |
93 | NAME => 'Min::PerlVers', |
94 | MIN_PERL_VERSION => '999999', |
95 | PREREQ_FATAL => 1, |
96 | ); |
97 | }; |
98 | is( $warnings, '', 'MIN_PERL_VERSION=999999 and PREREQ_FATAL: no warning' ); |
99 | is( $@, <<"END", ' correct exception' ); |
100 | MakeMaker FATAL: perl version too low for this distribution. |
101 | Required is 999999. We run $]. |
102 | END |
103 | |
104 | $warnings = ''; |
105 | eval { |
106 | WriteMakefile( |
107 | NAME => 'Min::PerlVers', |
108 | MIN_PERL_VERSION => 'foobar', |
109 | ); |
110 | }; |
111 | ok( '' ne $warnings, 'MIN_PERL_VERSION=foobar triggers a warning' ); |
112 | is( $warnings, <<'END', ' with expected message text' ); |
113 | Warning: MIN_PERL_VERSION is not in a recognized format. |
114 | Recommended is a quoted numerical value like '5.005' or '5.008001'. |
115 | END |
116 | |
117 | is( $@, '', ' and without a hard failure' ); |
118 | } |
119 | |
120 | |
121 | # ----- PREREQ_PRINT output ----- |
122 | { |
123 | my $prereq_out = run(qq{$perl Makefile.PL "PREREQ_PRINT=1"}); |
124 | is( $?, 0, 'PREREQ_PRINT exiting normally' ); |
125 | my $prereq_out_sane = $prereq_out =~ /^\s*\$PREREQ_PM\s*=/; |
126 | ok( $prereq_out_sane, ' and talking like we expect' ) || |
127 | diag($prereq_out); |
128 | |
129 | SKIP: { |
130 | skip 'not going to evaluate rubbish', 3 if !$prereq_out_sane; |
131 | |
132 | package _Prereq::Print::WithMPV; ## no critic |
133 | use vars qw($PREREQ_PM $MIN_PERL_VERSION $ERR); |
134 | $ERR = ''; |
135 | eval { |
136 | eval $prereq_out; ## no critic |
137 | $ERR = $@; |
138 | }; |
139 | ::is( $@ . $ERR, '', 'prereqs evaluable' ); |
140 | ::is_deeply( $PREREQ_PM, { strict => 0 }, ' and looking correct' ); |
141 | ::is( $MIN_PERL_VERSION, '5.005', 'min version also correct' ); |
142 | } |
143 | } |
144 | |
145 | |
146 | # ----- PRINT_PREREQ output ----- |
147 | { |
148 | my $prereq_out = run(qq{$perl Makefile.PL "PRINT_PREREQ=1"}); |
149 | is( $?, 0, 'PRINT_PREREQ exiting normally' ); |
150 | ok( $prereq_out !~ /^warning/i, ' and not complaining loudly' ); |
151 | like( $prereq_out, |
152 | qr/^perl\(perl\) \s* >= 5\.005 \s+ perl\(strict\) \s* >= \s* 0 \s*$/x, |
153 | 'dump has prereqs and perl version' ); |
154 | } |
155 | |
156 | |
157 | # ----- generated files verification ----- |
158 | { |
159 | unlink $makefile; |
160 | my @mpl_out = run(qq{$perl Makefile.PL}); |
161 | END { unlink $makefile, makefile_backup() } |
162 | |
163 | cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out); |
164 | ok( -e $makefile, 'Makefile present' ); |
165 | } |
166 | |
167 | |
168 | # ----- ppd output ----- |
169 | { |
170 | my $ppd_file = 'Min-PerlVers.ppd'; |
171 | my @make_out = run(qq{$make ppd}); |
172 | END { unlink $ppd_file } |
173 | |
174 | cmp_ok( $?, '==', 0, 'Make ppd exiting normally' ) || diag(@make_out); |
175 | |
176 | my $ppd_html = slurp($ppd_file); |
177 | ok( defined($ppd_html), ' .ppd file present' ); |
178 | |
179 | like( $ppd_html, qr{^\s*<PERLCORE VERSION="5,005,0,0" />}m, |
180 | ' .ppd file content good' ); |
181 | } |
182 | |
183 | |
184 | # ----- META.yml output ----- |
185 | { |
186 | my $distdir = 'Min-PerlVers-0.05'; |
187 | my $meta_yml = "$distdir/META.yml"; |
188 | my @make_out = run(qq{$make metafile}); |
189 | END { rmtree $distdir } |
190 | |
191 | cmp_ok( $?, '==', 0, 'Make metafile exiting normally' ) || diag(@make_out); |
192 | my $meta = slurp($meta_yml); |
193 | ok( defined($meta), ' META.yml present' ); |
194 | |
195 | like( $meta, qr{\nrequires:[^\S\n]*\n\s+perl:\s+5\.005\n\s+strict:\s+0\n}, |
196 | ' META.yml content good'); |
197 | } |
198 | |
199 | __END__ |