82dee7de92a0bd35 failed to add ext/lib/Makefile.PL. Oops.
[p5sagit/p5-mst-13.2.git] / ext / ExtUtils-MakeMaker / t / metafile_file.t
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
6 BEGIN {
7     unshift @INC, 't/lib';
8 }
9
10 use strict;
11 use Test::More tests => 16;
12
13 require ExtUtils::MM_Any;
14
15 my $mm = bless {}, 'ExtUtils::MM_Any';
16
17 {
18     my @meta = ( a => 1, b => 2 );
19     my $expected = <<YAML;
20 --- #YAML:1.0
21 a:  1
22 b:  2
23 YAML
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
32 k1:  some key and value
33 k2:  ~
34 k3:  1
35 YAML
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
44 a:  1
45 b:  2
46 h:
47     hh:  1
48 YAML
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
57 a:  1
58 b:  2
59 h:
60     h1:  x
61     h2:  z
62 YAML
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
73 a:  1
74 b:  2
75 h:
76     hh:
77         hhh:  1
78 YAML
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
87 a:  1
88 k:
89     - w
90     - y
91     - z
92 YAML
93
94     is($mm->metafile_file(@meta), $expected, "array of strings are handled ok");
95 }
96
97 is($mm->metafile_file( a => {}, b => [], c => undef ), <<'YAML', 'empty hashes and arrays');
98 --- #YAML:1.0
99 a:  {}
100 b:  []
101 c:  ~
102 YAML
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
127 name:               My-Module
128 version:            0.1
129 version_from:       lib/My/Module.pm
130 installdirs:        site
131 abstract:           A does-it-all module
132 license:            perl
133 generated_by:       myself
134 author:             John Doe <doe@doeland.org>
135 distribution_type:  module
136 requires:
137     My::Module::Helper:  0
138     Your::Module:        1.5
139 meta-spec:
140     url:      http://module-build.sourceforge.net/META-spec-new.html
141     version:  1.1
142 YAML
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
174 name:               My-Module
175 version:            0.1
176 version_from:       lib/My/Module.pm
177 installdirs:        site
178 abstract:           A does-it-all module
179 license:            perl
180 generated_by:       myself
181 author:             John Doe <doe@doeland.org>
182 distribution_type:  module
183 requires:
184     My::Module::Helper:  0
185     Your::Module:        1.5
186 recommends:
187     Test::More:           0
188     Test::Pod:            1.18
189     Test::Pod::Coverage:  1
190 meta-spec:
191     url:      http://module-build.sourceforge.net/META-spec-new.html
192     version:  1.1
193 YAML
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
229 name:               My-Module
230 version:            0.1
231 version_from:       lib/My/Module.pm
232 installdirs:        site
233 abstract:           A does-it-all module
234 license:            perl
235 generated_by:       myself
236 author:             John Doe <doe@doeland.org>
237 distribution_type:  module
238 requires:
239     My::Module::Helper:  0
240     Your::Module:        1.5
241 recommends:
242     Test::More:           0
243     Test::Pod:            1.18
244     Test::Pod::Coverage:  1
245 no_index:
246     dir:
247         - inc
248     file:
249         - TODO
250         - NOTES
251 meta-spec:
252     url:      http://module-build.sourceforge.net/META-spec-new.html
253     version:  1.1
254 YAML
255
256     is($mm->metafile_file(@meta), $expected, "META.yml with extra 'no_index' works");
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     }
277 }
278
279
280 {
281     my @meta = ( k => 'a : b', 'x : y' => 1 );
282     my $expected = <<YAML;
283 --- #YAML:1.0
284 k:      a : b
285 x : y:  1
286 YAML
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