xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/writemakefile_args.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 => 39;
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
39    my $mm;
40
41    eval {
42        $mm = WriteMakefile(
43            NAME            => 'Big::Dummy',
44            VERSION_FROM    => 'lib/Big/Dummy.pm',
45            MAN3PODS        => ' ', # common mistake
46        );
47    };
48
49    is( $warnings, <<VERIFY );
50WARNING: MAN3PODS takes a HASH reference not a string/number.
51         Please inform the author.
52VERIFY
53
54    $warnings = '';
55    eval {
56        $mm = WriteMakefile(
57            NAME            => 'Big::Dummy',
58            VERSION_FROM    => 'lib/Big/Dummy.pm',
59            AUTHOR          => sub {},
60        );
61    };
62
63    is( $warnings, <<VERIFY );
64WARNING: AUTHOR takes a ARRAY reference not a CODE reference.
65         Please inform the author.
66VERIFY
67
68    # LIBS accepts *both* a string or an array ref.  The first cut of
69    # our verification did not take this into account.
70    $warnings = '';
71    $mm = WriteMakefile(
72        NAME            => 'Big::Dummy',
73        VERSION_FROM    => 'lib/Big/Dummy.pm',
74        LIBS            => '-lwibble -lwobble',
75    );
76
77    # We'll get warnings about the bogus libs, that's ok.
78    unlike( $warnings, qr/WARNING: .* takes/ );
79    is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'] );
80
81    $warnings = '';
82    $mm = WriteMakefile(
83        NAME            => 'Big::Dummy',
84        VERSION_FROM    => 'lib/Big/Dummy.pm',
85        LIBS            => ['-lwibble', '-lwobble'],
86    );
87
88    # We'll get warnings about the bogus libs, that's ok.
89    unlike( $warnings, qr/WARNING: .* takes/ );
90    is_deeply( $mm->{LIBS}, ['-lwibble', '-lwobble'] );
91
92    $warnings = '';
93    eval {
94        $mm = WriteMakefile(
95            NAME            => 'Big::Dummy',
96            VERSION_FROM    => 'lib/Big/Dummy.pm',
97            LIBS            => { wibble => "wobble" },
98        );
99    };
100
101    # We'll get warnings about the bogus libs, that's ok.
102    like( $warnings, qr{^WARNING: LIBS takes a ARRAY reference or string/number not a HASH reference}m );
103
104
105    $warnings = '';
106    $mm = WriteMakefile(
107        NAME            => 'Big::Dummy',
108        WIBBLE          => 'something',
109        wump            => { foo => 42 },
110    );
111
112    like( $warnings, qr{^WARNING: WIBBLE is not a known parameter.\n}m );
113    like( $warnings, qr{^WARNING: wump is not a known parameter.\n}m );
114
115    is( $mm->{WIBBLE}, 'something' );
116    is_deeply( $mm->{wump}, { foo => 42 } );
117
118
119    # Test VERSION
120    $warnings = '';
121    eval {
122        $mm = WriteMakefile(
123            NAME       => 'Big::Dummy',
124            VERSION    => [1,2,3],
125        );
126    };
127    like( $warnings, qr{^WARNING: VERSION takes a version object or string/number} );
128
129    $warnings = '';
130    eval {
131        $mm = WriteMakefile(
132            NAME       => 'Big::Dummy',
133            VERSION    => 1.002_003,
134        );
135    };
136    is( $warnings, '' );
137    is( $mm->{VERSION}, '1.002003' );
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.002_003' );
148
149
150    $warnings = '';
151    eval {
152        $mm = WriteMakefile(
153            NAME       => 'Big::Dummy',
154            VERSION    => bless {}, "Some::Class",
155        );
156    };
157    like( $warnings, '/^WARNING: VERSION takes a version object or string/number not a Some::Class object/' );
158
159
160    SKIP: {
161        skip("Can't test version objects", 8) unless eval { require version };
162        version->import;
163
164        my $version = version->new("1.2.3");
165        $warnings = '';
166        ok eval {
167            $mm = WriteMakefile(
168                NAME       => 'Big::Dummy',
169                VERSION    => $version,
170            );
171        } || diag $@;
172        is( $warnings, '' );
173        isa_ok( $mm->{VERSION}, 'version' );
174        is( $mm->{VERSION}, $version );
175
176        $warnings = '';
177        $version = qv('1.2.3');
178        ok eval {
179            $mm = WriteMakefile(
180                NAME       => 'Big::Dummy',
181                VERSION    => $version,
182            );
183        } || diag $@;
184        is( $warnings, '' );
185        isa_ok( $mm->{VERSION}, 'version' );
186        is( $mm->{VERSION}, $version );
187    }
188
189
190    # DISTNAME
191    $warnings = '';
192    eval {
193        $mm = WriteMakefile(
194            NAME       => 'Big::Dummy',
195            VERSION    => '1.00',
196            DISTNAME   => "Hooballa",
197        );
198    };
199    is( $warnings, '' );
200    is( $mm->{DISTNAME},  "Hooballa" );
201    is( $mm->{DISTVNAME}, $Is_VMS ? "Hooballa-1_00" : "Hooballa-1.00" );
202
203
204    # DISTVNAME (rt.cpan.org 43217)
205    $warnings = '';
206    eval {
207        $mm = WriteMakefile(
208            NAME       => 'Big::Dummy',
209            VERSION    => 1.00,
210            DISTVNAME  => "Hooballoo",
211        );
212    };
213    is( $warnings, '' );
214    is( $mm->{DISTVNAME}, 'Hooballoo' );
215
216
217    # AUTHOR / scalar
218    $warnings = '';
219    eval {
220        $mm = WriteMakefile(
221            NAME       => 'Big::Dummy',
222            VERSION    => '1.00',
223            AUTHOR     => "test",
224        );
225    };
226    is( $warnings, '' );
227    is_deeply( $mm->{AUTHOR},  ["test"] );
228
229
230    # AUTHOR / array
231    $warnings = '';
232    eval {
233        $mm = WriteMakefile(
234            NAME       => 'Big::Dummy',
235            VERSION    => '1.00',
236            AUTHOR     => ["test1", "test2"],
237        );
238    };
239    is( $warnings, '' );
240    is_deeply( $mm->{AUTHOR},  ["test1","test2"] );
241
242}
243