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 Config;
12use Test::More tests => 43;
13
14use TieOut;
15use MakeMaker::Test::Utils;
16use MakeMaker::Test::Setup::BFD;
17
18use ExtUtils::MakeMaker;
19
20chdir 't';
21perl_lib; # sets $ENV{PERL5LIB} relative to t/
22
23use File::Temp qw[tempdir];
24my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
25use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
26chdir $tmpdir;
27
28ok( setup_recurs(), 'setup' );
29END {
30    ok( chdir File::Spec->updir );
31    ok( teardown_recurs(), 'teardown' );
32}
33
34ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
35  diag("chdir failed: $!");
36
37{
38    ok( my $stdout = tie *STDOUT, 'TieOut' );
39    my $warnings = '';
40    local $SIG{__WARN__} = sub {
41        if ( $Config{usecrosscompile} ) {
42            # libraries might not be present on the target system
43            # when cross-compiling
44            return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/
45        }
46        $warnings .= join '', @_;
47    };
48
49    my $mm;
50
51    eval {
52        $mm = WriteMakefile(
53            NAME            => 'Big::Dummy',
54            VERSION_FROM    => 'lib/Big/Dummy.pm',
55            MAN3PODS        => ' ', # common mistake
56        );
57    };
58
59    is( $warnings, <<VERIFY );
60WARNING: MAN3PODS takes a HASH reference not a string/number.
61         Please inform the author.
62VERIFY
63
64    $warnings = '';
65    eval {
66        $mm = WriteMakefile(
67            NAME            => 'Big::Dummy',
68            VERSION_FROM    => 'lib/Big/Dummy.pm',
69            AUTHOR          => sub {},
70        );
71    };
72
73    is( $warnings, <<VERIFY );
74WARNING: AUTHOR takes a ARRAY reference not a CODE reference.
75         Please inform the author.
76VERIFY
77
78    # LIBS accepts *both* a string or an array ref.  The first cut of
79    # our verification did not take this into account.
80    $warnings = '';
81    $mm = WriteMakefile(
82        NAME            => 'Big::Dummy',
83        VERSION_FROM    => 'lib/Big/Dummy.pm',
84        LIBS            => '-lwibble -lwobble',
85    );
86
87    # We'll get warnings about the bogus libs, that's ok.
88    unlike( $warnings, qr/WARNING: .* takes/ );
89    is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'] );
90
91    $warnings = '';
92    $mm = WriteMakefile(
93        NAME            => 'Big::Dummy',
94        VERSION_FROM    => 'lib/Big/Dummy.pm',
95        LIBS            => ['-lwibble', '-lwobble'],
96    );
97
98    # We'll get warnings about the bogus libs, that's ok.
99    unlike( $warnings, qr/WARNING: .* takes/ );
100    is_deeply( $mm->{LIBS}, ['-lwibble', '-lwobble'] );
101
102    $warnings = '';
103    eval {
104        $mm = WriteMakefile(
105            NAME            => 'Big::Dummy',
106            VERSION_FROM    => 'lib/Big/Dummy.pm',
107            LIBS            => { wibble => "wobble" },
108        );
109    };
110
111    # We'll get warnings about the bogus libs, that's ok.
112    like( $warnings, qr{^WARNING: LIBS takes a ARRAY reference or string/number not a HASH reference}m );
113
114
115    $warnings = '';
116    $mm = WriteMakefile(
117        NAME            => 'Big::Dummy',
118        WIBBLE          => 'something',
119        wump            => { foo => 42 },
120    );
121
122    like( $warnings, qr{^WARNING: WIBBLE is not a known parameter.\n}m );
123    like( $warnings, qr{^WARNING: wump is not a known parameter.\n}m );
124
125    is( $mm->{WIBBLE}, 'something' );
126    is_deeply( $mm->{wump}, { foo => 42 } );
127
128
129    # Test VERSION
130    $warnings = '';
131    eval {
132        $mm = WriteMakefile(
133            NAME       => 'Big::Dummy',
134            VERSION    => [1,2,3],
135        );
136    };
137    like( $warnings, qr{^WARNING: VERSION takes a version object or string/number} );
138
139    $warnings = '';
140    eval {
141        $mm = WriteMakefile(
142            NAME       => 'Big::Dummy',
143            VERSION    => 1.002_003,
144        );
145    };
146    is( $warnings, '' );
147    is( $mm->{VERSION}, '1.002003' );
148
149    $warnings = '';
150    eval {
151        $mm = WriteMakefile(
152            NAME       => 'Big::Dummy',
153            VERSION    => '1.002_003',
154        );
155    };
156    is( $warnings, '' );
157    is( $mm->{VERSION}, '1.002_003' );
158
159
160    $warnings = '';
161    eval {
162        $mm = WriteMakefile(
163            NAME       => 'Big::Dummy',
164            VERSION    => bless {}, "Some::Class",
165        );
166    };
167    like( $warnings, '/^WARNING: VERSION takes a version object or string/number not a Some::Class object/' );
168
169
170    SKIP: {
171        skip("Can't test version objects", 8) unless eval { require version };
172        version->import;
173
174        my $version = version->new("1.2.3");
175        $warnings = '';
176        ok eval {
177            $mm = WriteMakefile(
178                NAME       => 'Big::Dummy',
179                VERSION    => $version,
180            );
181        } || diag $@;
182        is( $warnings, '' );
183        isa_ok( $mm->{VERSION}, 'version' );
184        is( $mm->{VERSION}, $version );
185
186        $warnings = '';
187        $version = qv('1.2.3');
188        ok eval {
189            $mm = WriteMakefile(
190                NAME       => 'Big::Dummy',
191                VERSION    => $version,
192            );
193        } || diag $@;
194        is( $warnings, '' );
195        isa_ok( $mm->{VERSION}, 'version' );
196        is( $mm->{VERSION}, $version );
197    }
198
199
200    # DISTNAME
201    $warnings = '';
202    eval {
203        $mm = WriteMakefile(
204            NAME       => 'Big::Dummy',
205            VERSION    => '1.00',
206            DISTNAME   => "Hooballa",
207        );
208    };
209    is( $warnings, '' );
210    is( $mm->{DISTNAME},  "Hooballa" );
211    is( $mm->{DISTVNAME}, $Is_VMS ? "Hooballa-1_00" : "Hooballa-1.00" );
212
213
214    # DISTVNAME (rt.cpan.org 43217)
215    $warnings = '';
216    eval {
217        $mm = WriteMakefile(
218            NAME       => 'Big::Dummy',
219            VERSION    => 1.00,
220            DISTVNAME  => "Hooballoo",
221        );
222    };
223    is( $warnings, '' );
224    is( $mm->{DISTVNAME}, 'Hooballoo' );
225
226
227    # AUTHOR / scalar
228    $warnings = '';
229    eval {
230        $mm = WriteMakefile(
231            NAME       => 'Big::Dummy',
232            VERSION    => '1.00',
233            AUTHOR     => "test",
234        );
235    };
236    is( $warnings, '' );
237    is_deeply( $mm->{AUTHOR},  ["test"] );
238
239
240    # AUTHOR / array
241    $warnings = '';
242    eval {
243        $mm = WriteMakefile(
244            NAME       => 'Big::Dummy',
245            VERSION    => '1.00',
246            AUTHOR     => ["test1", "test2"],
247        );
248    };
249    is( $warnings, '' );
250    is_deeply( $mm->{AUTHOR},  ["test1","test2"] );
251
252    # PERL_MM_OPT
253    {
254      local $ENV{PERL_MM_OPT} = 'CCFLAGS="-Wl,-rpath -Wl,/foo/bar/lib" LIBS="-lwibble -lwobble"';
255      $mm = WriteMakefile(
256          NAME            => 'Big::Dummy',
257          VERSION    => '1.00',
258      );
259
260      like( $mm->{CCFLAGS}, qr{-Wl,-rpath -Wl,/foo/bar/lib}, 'parse_args() splits like shell' );
261      is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'], 'parse_args() splits like shell' );
262    }
263
264    # PERL_MM_OPT
265    {
266      local $ENV{PERL_MM_OPT} = 'INSTALL_BASE=/how/we/have/not/broken/local/lib';
267      $mm = WriteMakefile(
268          NAME            => 'Big::Dummy',
269          VERSION    => '1.00',
270      );
271
272      is( $mm->{INSTALL_BASE}, "/how/we/have/not/broken/local/lib", 'parse_args() splits like shell' );
273    }
274
275    # PERL_MM_OPT
276    {
277      local $ENV{PERL_MM_OPT} = 'INSTALL_BASE="/Users/miyagawa/tmp/car1  foo/foo bar"';
278      $mm = WriteMakefile(
279          NAME            => 'Big::Dummy',
280          VERSION    => '1.00',
281      );
282
283      is( $mm->{INSTALL_BASE}, "/Users/miyagawa/tmp/car1  foo/foo bar", 'parse_args() splits like shell' );
284    }
285
286}
287