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