Commit | Line | Data |
69ff8adf |
1 | #!/usr/bin/perl -w |
2 | |
3 | # This is a test of the verification of the arguments to |
4 | # 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; |
2e65e370 |
17 | use Test::More tests => 30; |
69ff8adf |
18 | |
19 | use TieOut; |
20 | use MakeMaker::Test::Utils; |
a7d1454b |
21 | use MakeMaker::Test::Setup::BFD; |
69ff8adf |
22 | |
23 | use ExtUtils::MakeMaker; |
24 | |
25 | chdir 't'; |
26 | |
27 | perl_lib(); |
28 | |
a7d1454b |
29 | ok( setup_recurs(), 'setup' ); |
30 | END { |
31 | ok( chdir File::Spec->updir ); |
32 | ok( teardown_recurs(), 'teardown' ); |
33 | } |
34 | |
69ff8adf |
35 | ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || |
36 | diag("chdir failed: $!"); |
37 | |
38 | { |
39 | ok( my $stdout = tie *STDOUT, 'TieOut' ); |
40 | my $warnings = ''; |
41 | local $SIG{__WARN__} = sub { |
42 | $warnings .= join '', @_; |
43 | }; |
44 | |
a884ca7c |
45 | my $mm; |
46 | |
47 | eval { |
48 | $mm = WriteMakefile( |
49 | NAME => 'Big::Dummy', |
50 | VERSION_FROM => 'lib/Big/Dummy.pm', |
51 | MAN3PODS => ' ', # common mistake |
52 | ); |
53 | }; |
69ff8adf |
54 | |
55 | is( $warnings, <<VERIFY ); |
277189c8 |
56 | WARNING: MAN3PODS takes a HASH reference not a string/number. |
69ff8adf |
57 | Please inform the author. |
58 | VERIFY |
69ff8adf |
59 | |
60 | $warnings = ''; |
a884ca7c |
61 | eval { |
62 | $mm = WriteMakefile( |
63 | NAME => 'Big::Dummy', |
64 | VERSION_FROM => 'lib/Big/Dummy.pm', |
65 | AUTHOR => sub {}, |
66 | ); |
67 | }; |
d5d4ec93 |
68 | |
69ff8adf |
69 | is( $warnings, <<VERIFY ); |
277189c8 |
70 | WARNING: AUTHOR takes a string/number not a CODE reference. |
69ff8adf |
71 | Please inform the author. |
72 | VERIFY |
73 | |
69ff8adf |
74 | # LIBS accepts *both* a string or an array ref. The first cut of |
75 | # our verification did not take this into account. |
76 | $warnings = ''; |
77 | $mm = WriteMakefile( |
78 | NAME => 'Big::Dummy', |
79 | VERSION_FROM => 'lib/Big/Dummy.pm', |
80 | LIBS => '-lwibble -lwobble', |
81 | ); |
d5d4ec93 |
82 | |
69ff8adf |
83 | # We'll get warnings about the bogus libs, that's ok. |
84 | unlike( $warnings, qr/WARNING: .* takes/ ); |
85 | is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'] ); |
86 | |
87 | $warnings = ''; |
88 | $mm = WriteMakefile( |
89 | NAME => 'Big::Dummy', |
90 | VERSION_FROM => 'lib/Big/Dummy.pm', |
91 | LIBS => ['-lwibble', '-lwobble'], |
92 | ); |
d5d4ec93 |
93 | |
69ff8adf |
94 | # We'll get warnings about the bogus libs, that's ok. |
95 | unlike( $warnings, qr/WARNING: .* takes/ ); |
96 | is_deeply( $mm->{LIBS}, ['-lwibble', '-lwobble'] ); |
97 | |
98 | $warnings = ''; |
a884ca7c |
99 | eval { |
100 | $mm = WriteMakefile( |
101 | NAME => 'Big::Dummy', |
102 | VERSION_FROM => 'lib/Big/Dummy.pm', |
103 | LIBS => { wibble => "wobble" }, |
104 | ); |
105 | }; |
d5d4ec93 |
106 | |
69ff8adf |
107 | # We'll get warnings about the bogus libs, that's ok. |
277189c8 |
108 | like( $warnings, qr{^WARNING: LIBS takes a ARRAY reference or string/number not a HASH reference}m ); |
69ff8adf |
109 | |
d5d4ec93 |
110 | |
111 | $warnings = ''; |
112 | $mm = WriteMakefile( |
113 | NAME => 'Big::Dummy', |
114 | WIBBLE => 'something', |
115 | wump => { foo => 42 }, |
116 | ); |
117 | |
118 | like( $warnings, qr{^WARNING: WIBBLE is not a known parameter.\n}m ); |
119 | like( $warnings, qr{^WARNING: wump is not a known parameter.\n}m ); |
120 | |
121 | is( $mm->{WIBBLE}, 'something' ); |
122 | is_deeply( $mm->{wump}, { foo => 42 } ); |
277189c8 |
123 | |
124 | |
125 | # Test VERSION |
126 | $warnings = ''; |
127 | eval { |
128 | $mm = WriteMakefile( |
2e65e370 |
129 | NAME => 'Big::Dummy', |
130 | VERSION => [1,2,3], |
277189c8 |
131 | ); |
132 | }; |
133 | like( $warnings, qr{^WARNING: VERSION takes a version object or string/number} ); |
134 | |
135 | $warnings = ''; |
136 | eval { |
137 | $mm = WriteMakefile( |
2e65e370 |
138 | NAME => 'Big::Dummy', |
139 | VERSION => 1.002_003, |
277189c8 |
140 | ); |
141 | }; |
142 | is( $warnings, '' ); |
143 | is( $mm->{VERSION}, '1.002003' ); |
144 | |
145 | $warnings = ''; |
146 | eval { |
147 | $mm = WriteMakefile( |
2e65e370 |
148 | NAME => 'Big::Dummy', |
149 | VERSION => '1.002_003', |
277189c8 |
150 | ); |
151 | }; |
152 | is( $warnings, '' ); |
153 | is( $mm->{VERSION}, '1.002_003' ); |
154 | |
155 | |
156 | $warnings = ''; |
157 | eval { |
158 | $mm = WriteMakefile( |
2e65e370 |
159 | NAME => 'Big::Dummy', |
160 | VERSION => bless {}, "Some::Class", |
277189c8 |
161 | ); |
162 | }; |
163 | like( $warnings, '/^WARNING: VERSION takes a version object or string/number not a Some::Class object/' ); |
164 | |
165 | |
166 | SKIP: { |
2e65e370 |
167 | skip("Can't test version objects", 8) unless eval { require version }; |
277189c8 |
168 | version->import; |
169 | |
170 | my $version = version->new("1.2.3"); |
171 | $warnings = ''; |
2e65e370 |
172 | ok eval { |
277189c8 |
173 | $mm = WriteMakefile( |
2e65e370 |
174 | NAME => 'Big::Dummy', |
175 | VERSION => $version, |
277189c8 |
176 | ); |
2e65e370 |
177 | } || diag $@; |
277189c8 |
178 | is( $warnings, '' ); |
179 | isa_ok( $mm->{VERSION}, 'version' ); |
180 | is( $mm->{VERSION}, $version ); |
181 | |
182 | $warnings = ''; |
183 | $version = qv('1.2.3'); |
2e65e370 |
184 | ok eval { |
277189c8 |
185 | $mm = WriteMakefile( |
2e65e370 |
186 | NAME => 'Big::Dummy', |
187 | VERSION => $version, |
277189c8 |
188 | ); |
2e65e370 |
189 | } || diag $@; |
277189c8 |
190 | is( $warnings, '' ); |
191 | isa_ok( $mm->{VERSION}, 'version' ); |
192 | is( $mm->{VERSION}, $version ); |
193 | } |
2e65e370 |
194 | } |