3 # This is a test of the fake YAML dumper implemented by EUMM:
4 # ExtUtils::MM_Any::metafile_file
7 if( $ENV{PERL_CORE} ) {
9 @INC = ('../lib', 'lib');
12 unshift @INC, 't/lib';
17 use Test::More tests => 16;
19 require ExtUtils::MM_Any;
21 my $mm = bless {}, 'ExtUtils::MM_Any';
24 my @meta = ( a => 1, b => 2 );
25 my $expected = <<YAML;
31 is($mm->metafile_file(@meta), $expected, "dump for flat hashes works ok");
35 my @meta = ( k1 => 'some key and value', k2 => undef, k3 => 1 );
36 my $expected = <<YAML;
38 k1: some key and value
43 is($mm->metafile_file(@meta), $expected, "dumping strings and undefs is ok");
47 my @meta = ( a => 1, b => 2, h => { hh => 1 } );
48 my $expected = <<YAML;
56 is($mm->metafile_file(@meta), $expected, "dump for nested hashes works ok");
60 my @meta = ( a => 1, b => 2, h => { h1 => 'x', h2 => 'z' } );
61 my $expected = <<YAML;
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
76 my @meta = ( a => 1, b => 2, h => { hh => { hhh => 1 } } );
77 my $expected = <<YAML;
86 is($mm->metafile_file(@meta), $expected, "dump for hashes (with more nesting) works ok");
90 my @meta = ( a => 1, k => [ qw(w y z) ] );
91 my $expected = <<YAML;
100 is($mm->metafile_file(@meta), $expected, "array of strings are handled ok");
103 is($mm->metafile_file( a => {}, b => [], c => undef ), <<'YAML', 'empty hashes and arrays');
115 version_from => 'lib/My/Module.pm',
116 installdirs => 'site',
117 abstract => 'A does-it-all module',
119 generated_by => 'myself',
120 author => 'John Doe <doe@doeland.org>',
121 distribution_type => 'module',
123 'My::Module::Helper' => 0,
124 'Your::Module' => '1.5',
128 url => 'http://module-build.sourceforge.net/META-spec-new.html',
131 my $expected = <<'YAML';
135 version_from: lib/My/Module.pm
137 abstract: A does-it-all module
140 author: John Doe <doe@doeland.org>
141 distribution_type: module
143 My::Module::Helper: 0
146 url: http://module-build.sourceforge.net/META-spec-new.html
150 is($mm->metafile_file(@meta), $expected, "dump for something like META.yml works");
157 version_from => 'lib/My/Module.pm',
158 installdirs => 'site',
159 abstract => 'A does-it-all module',
161 generated_by => 'myself',
162 author => 'John Doe <doe@doeland.org>',
163 distribution_type => 'module',
165 'My::Module::Helper' => 0,
166 'Your::Module' => '1.5',
171 'Test::Pod::Coverage' => 1
175 url => 'http://module-build.sourceforge.net/META-spec-new.html',
178 my $expected = <<'YAML';
182 version_from: lib/My/Module.pm
184 abstract: A does-it-all module
187 author: John Doe <doe@doeland.org>
188 distribution_type: module
190 My::Module::Helper: 0
195 Test::Pod::Coverage: 1
197 url: http://module-build.sourceforge.net/META-spec-new.html
201 is($mm->metafile_file(@meta), $expected, "META.yml with extra 'recommends' works");
208 version_from => 'lib/My/Module.pm',
209 installdirs => 'site',
210 abstract => 'A does-it-all module',
212 generated_by => 'myself',
213 author => 'John Doe <doe@doeland.org>',
214 distribution_type => 'module',
216 'My::Module::Helper' => 0,
217 'Your::Module' => '1.5',
222 'Test::Pod::Coverage' => 1
226 file => [ qw(TODO NOTES) ],
230 url => 'http://module-build.sourceforge.net/META-spec-new.html',
233 my $expected = <<'YAML';
237 version_from: lib/My/Module.pm
239 abstract: A does-it-all module
242 author: John Doe <doe@doeland.org>
243 distribution_type: module
245 My::Module::Helper: 0
250 Test::Pod::Coverage: 1
258 url: http://module-build.sourceforge.net/META-spec-new.html
262 is($mm->metafile_file(@meta), $expected, "META.yml with extra 'no_index' works");
265 # Make sure YAML.pm can ready our output
267 skip "Need YAML.pm to test if it can load META.yml", 1
268 unless eval { require YAML };
270 my $yaml_load = YAML::Load($mm->metafile_file(@meta));
271 is_deeply( $yaml_load, {@meta}, "META.yml can be read by YAML.pm" );
276 skip "Need YAML::Tiny to test if it can load META.yml", 2
277 unless eval { require YAML::Tiny };
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" );
287 my @meta = ( k => 'a : b', 'x : y' => 1 );
288 my $expected = <<YAML;
293 # NOTE: the output is not YAML-equivalent to the input
295 is($mm->metafile_file(@meta), $expected, "no quoting is done");
299 my @meta = ( k => \*STDOUT );
300 eval { $mm->metafile_file(@meta) };
302 like($@, qr/^only nested hashes, arrays and objects are supported/,
303 "we don't like but hash/array refs");
307 my @meta = ( k => [ [] ] );
308 eval { $mm->metafile_file(@meta) };
310 like($@, qr/^only nested arrays of non-refs are supported/,
311 "we also don't like but array of strings");
314 # recursive data structures: don't even think about it - endless recursion