ExtUtils::MakeMaker 6.55_02
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / metafile_file.t
CommitLineData
2e65e370 1#!/usr/bin/perl -w
2
3# This is a test of the fake YAML dumper implemented by EUMM:
4# ExtUtils::MM_Any::metafile_file
5
6BEGIN {
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
16use strict;
bf87a6a1 17use Test::More tests => 16;
2e65e370 18
19require ExtUtils::MM_Any;
20
21my $mm = bless {}, 'ExtUtils::MM_Any';
22
23{
24 my @meta = ( a => 1, b => 2 );
25 my $expected = <<YAML;
26--- #YAML:1.0
27a: 1
28b: 2
29YAML
30
31 is($mm->metafile_file(@meta), $expected, "dump for flat hashes works ok");
32}
33
34{
35 my @meta = ( k1 => 'some key and value', k2 => undef, k3 => 1 );
36 my $expected = <<YAML;
37--- #YAML:1.0
38k1: some key and value
39k2: ~
40k3: 1
41YAML
42
43 is($mm->metafile_file(@meta), $expected, "dumping strings and undefs is ok");
44}
45
46{
47 my @meta = ( a => 1, b => 2, h => { hh => 1 } );
48 my $expected = <<YAML;
49--- #YAML:1.0
50a: 1
51b: 2
52h:
53 hh: 1
54YAML
55
56 is($mm->metafile_file(@meta), $expected, "dump for nested hashes works ok");
57}
58
59{
60 my @meta = ( a => 1, b => 2, h => { h1 => 'x', h2 => 'z' } );
61 my $expected = <<YAML;
62--- #YAML:1.0
63a: 1
64b: 2
65h:
66 h1: x
67 h2: z
68YAML
69
70 is($mm->metafile_file(@meta), $expected, "nested hashes sort ascii-betically");
71 # to tell the truth, they sort case-insensitively
72 # that's hard to test for Perl with unstable sort's
73}
74
75{
76 my @meta = ( a => 1, b => 2, h => { hh => { hhh => 1 } } );
77 my $expected = <<YAML;
78--- #YAML:1.0
79a: 1
80b: 2
81h:
82 hh:
83 hhh: 1
84YAML
85
86 is($mm->metafile_file(@meta), $expected, "dump for hashes (with more nesting) works ok");
87}
88
89{
90 my @meta = ( a => 1, k => [ qw(w y z) ] );
91 my $expected = <<YAML;
92--- #YAML:1.0
93a: 1
94k:
95 - w
96 - y
97 - z
98YAML
99
100 is($mm->metafile_file(@meta), $expected, "array of strings are handled ok");
101}
102
103is($mm->metafile_file( a => {}, b => [], c => undef ), <<'YAML', 'empty hashes and arrays');
104--- #YAML:1.0
105a: {}
106b: []
107c: ~
108YAML
109
110
111{
112 my @meta = (
113 name => 'My-Module',
114 version => '0.1',
115 version_from => 'lib/My/Module.pm',
116 installdirs => 'site',
117 abstract => 'A does-it-all module',
118 license => 'perl',
119 generated_by => 'myself',
120 author => 'John Doe <doe@doeland.org>',
121 distribution_type => 'module',
122 requires => {
123 'My::Module::Helper' => 0,
124 'Your::Module' => '1.5',
125 },
126 'meta-spec' => {
127 version => '1.1',
128 url => 'http://module-build.sourceforge.net/META-spec-new.html',
129 },
130 );
131 my $expected = <<'YAML';
132--- #YAML:1.0
133name: My-Module
134version: 0.1
135version_from: lib/My/Module.pm
136installdirs: site
137abstract: A does-it-all module
138license: perl
139generated_by: myself
140author: John Doe <doe@doeland.org>
141distribution_type: module
142requires:
143 My::Module::Helper: 0
144 Your::Module: 1.5
145meta-spec:
146 url: http://module-build.sourceforge.net/META-spec-new.html
147 version: 1.1
148YAML
149
150 is($mm->metafile_file(@meta), $expected, "dump for something like META.yml works");
151}
152
153{
154 my @meta = (
155 name => 'My-Module',
156 version => '0.1',
157 version_from => 'lib/My/Module.pm',
158 installdirs => 'site',
159 abstract => 'A does-it-all module',
160 license => 'perl',
161 generated_by => 'myself',
162 author => 'John Doe <doe@doeland.org>',
163 distribution_type => 'module',
164 requires => {
165 'My::Module::Helper' => 0,
166 'Your::Module' => '1.5',
167 },
168 recommends => {
169 'Test::More' => 0,
170 'Test::Pod' => 1.18,
171 'Test::Pod::Coverage' => 1
172 },
173 'meta-spec' => {
174 version => '1.1',
175 url => 'http://module-build.sourceforge.net/META-spec-new.html',
176 },
177 );
178 my $expected = <<'YAML';
179--- #YAML:1.0
180name: My-Module
181version: 0.1
182version_from: lib/My/Module.pm
183installdirs: site
184abstract: A does-it-all module
185license: perl
186generated_by: myself
187author: John Doe <doe@doeland.org>
188distribution_type: module
189requires:
190 My::Module::Helper: 0
191 Your::Module: 1.5
192recommends:
193 Test::More: 0
194 Test::Pod: 1.18
195 Test::Pod::Coverage: 1
196meta-spec:
197 url: http://module-build.sourceforge.net/META-spec-new.html
198 version: 1.1
199YAML
200
201 is($mm->metafile_file(@meta), $expected, "META.yml with extra 'recommends' works");
202}
203
204{
205 my @meta = (
206 name => 'My-Module',
207 version => '0.1',
208 version_from => 'lib/My/Module.pm',
209 installdirs => 'site',
210 abstract => 'A does-it-all module',
211 license => 'perl',
212 generated_by => 'myself',
213 author => 'John Doe <doe@doeland.org>',
214 distribution_type => 'module',
215 requires => {
216 'My::Module::Helper' => 0,
217 'Your::Module' => '1.5',
218 },
219 recommends => {
220 'Test::More' => 0,
221 'Test::Pod' => 1.18,
222 'Test::Pod::Coverage' => 1
223 },
224 no_index => {
225 dir => [ qw(inc) ],
226 file => [ qw(TODO NOTES) ],
227 },
228 'meta-spec' => {
229 version => '1.1',
230 url => 'http://module-build.sourceforge.net/META-spec-new.html',
231 },
232 );
233 my $expected = <<'YAML';
234--- #YAML:1.0
235name: My-Module
236version: 0.1
237version_from: lib/My/Module.pm
238installdirs: site
239abstract: A does-it-all module
240license: perl
241generated_by: myself
242author: John Doe <doe@doeland.org>
243distribution_type: module
244requires:
245 My::Module::Helper: 0
246 Your::Module: 1.5
247recommends:
248 Test::More: 0
249 Test::Pod: 1.18
250 Test::Pod::Coverage: 1
251no_index:
252 dir:
253 - inc
254 file:
255 - TODO
256 - NOTES
257meta-spec:
258 url: http://module-build.sourceforge.net/META-spec-new.html
259 version: 1.1
260YAML
261
262 is($mm->metafile_file(@meta), $expected, "META.yml with extra 'no_index' works");
bf87a6a1 263
264
265 # Make sure YAML.pm can ready our output
266 SKIP: {
267 skip "Need YAML.pm to test if it can load META.yml", 1
268 unless eval { require YAML };
269
270 my $yaml_load = YAML::Load($mm->metafile_file(@meta));
271 is_deeply( $yaml_load, {@meta}, "META.yml can be read by YAML.pm" );
272 }
273
274
275 SKIP: {
276 skip "Need YAML::Tiny to test if it can load META.yml", 2
277 unless eval { require YAML::Tiny };
278
279 my @yaml_load = YAML::Tiny::Load($mm->metafile_file(@meta));
280 is @yaml_load, 1, "YAML::Tiny saw one document in META.yml";
281 is_deeply( $yaml_load[0], {@meta}, "META.yml can be read by YAML::Tiny" );
282 }
2e65e370 283}
284
bf87a6a1 285
2e65e370 286{
287 my @meta = ( k => 'a : b', 'x : y' => 1 );
288 my $expected = <<YAML;
289--- #YAML:1.0
290k: a : b
291x : y: 1
292YAML
293 # NOTE: the output is not YAML-equivalent to the input
294
295 is($mm->metafile_file(@meta), $expected, "no quoting is done");
296}
297
298{
299 my @meta = ( k => \*STDOUT );
300 eval { $mm->metafile_file(@meta) };
301
302 like($@, qr/^only nested hashes, arrays and objects are supported/,
303 "we don't like but hash/array refs");
304}
305
306{
307 my @meta = ( k => [ [] ] );
308 eval { $mm->metafile_file(@meta) };
309
310 like($@, qr/^only nested arrays of non-refs are supported/,
311 "we also don't like but array of strings");
312}
313
314# recursive data structures: don't even think about it - endless recursion