3 # This is a test of the fake YAML dumper implemented by EUMM:
4 # ExtUtils::MM_Any::metafile_file
11 use Test::More tests => 16;
13 require ExtUtils::MM_Any;
15 my $mm = bless {}, 'ExtUtils::MM_Any';
18 my @meta = ( a => 1, b => 2 );
19 my $expected = <<YAML;
25 is($mm->metafile_file(@meta), $expected, "dump for flat hashes works ok");
29 my @meta = ( k1 => 'some key and value', k2 => undef, k3 => 1 );
30 my $expected = <<YAML;
32 k1: some key and value
37 is($mm->metafile_file(@meta), $expected, "dumping strings and undefs is ok");
41 my @meta = ( a => 1, b => 2, h => { hh => 1 } );
42 my $expected = <<YAML;
50 is($mm->metafile_file(@meta), $expected, "dump for nested hashes works ok");
54 my @meta = ( a => 1, b => 2, h => { h1 => 'x', h2 => 'z' } );
55 my $expected = <<YAML;
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
70 my @meta = ( a => 1, b => 2, h => { hh => { hhh => 1 } } );
71 my $expected = <<YAML;
80 is($mm->metafile_file(@meta), $expected, "dump for hashes (with more nesting) works ok");
84 my @meta = ( a => 1, k => [ qw(w y z) ] );
85 my $expected = <<YAML;
94 is($mm->metafile_file(@meta), $expected, "array of strings are handled ok");
97 is($mm->metafile_file( a => {}, b => [], c => undef ), <<'YAML', 'empty hashes and arrays');
109 version_from => 'lib/My/Module.pm',
110 installdirs => 'site',
111 abstract => 'A does-it-all module',
113 generated_by => 'myself',
114 author => 'John Doe <doe@doeland.org>',
115 distribution_type => 'module',
117 'My::Module::Helper' => 0,
118 'Your::Module' => '1.5',
122 url => 'http://module-build.sourceforge.net/META-spec-new.html',
125 my $expected = <<'YAML';
129 version_from: lib/My/Module.pm
131 abstract: A does-it-all module
134 author: John Doe <doe@doeland.org>
135 distribution_type: module
137 My::Module::Helper: 0
140 url: http://module-build.sourceforge.net/META-spec-new.html
144 is($mm->metafile_file(@meta), $expected, "dump for something like META.yml works");
151 version_from => 'lib/My/Module.pm',
152 installdirs => 'site',
153 abstract => 'A does-it-all module',
155 generated_by => 'myself',
156 author => 'John Doe <doe@doeland.org>',
157 distribution_type => 'module',
159 'My::Module::Helper' => 0,
160 'Your::Module' => '1.5',
165 'Test::Pod::Coverage' => 1
169 url => 'http://module-build.sourceforge.net/META-spec-new.html',
172 my $expected = <<'YAML';
176 version_from: lib/My/Module.pm
178 abstract: A does-it-all module
181 author: John Doe <doe@doeland.org>
182 distribution_type: module
184 My::Module::Helper: 0
189 Test::Pod::Coverage: 1
191 url: http://module-build.sourceforge.net/META-spec-new.html
195 is($mm->metafile_file(@meta), $expected, "META.yml with extra 'recommends' works");
202 version_from => 'lib/My/Module.pm',
203 installdirs => 'site',
204 abstract => 'A does-it-all module',
206 generated_by => 'myself',
207 author => 'John Doe <doe@doeland.org>',
208 distribution_type => 'module',
210 'My::Module::Helper' => 0,
211 'Your::Module' => '1.5',
216 'Test::Pod::Coverage' => 1
220 file => [ qw(TODO NOTES) ],
224 url => 'http://module-build.sourceforge.net/META-spec-new.html',
227 my $expected = <<'YAML';
231 version_from: lib/My/Module.pm
233 abstract: A does-it-all module
236 author: John Doe <doe@doeland.org>
237 distribution_type: module
239 My::Module::Helper: 0
244 Test::Pod::Coverage: 1
252 url: http://module-build.sourceforge.net/META-spec-new.html
256 is($mm->metafile_file(@meta), $expected, "META.yml with extra 'no_index' works");
259 # Make sure YAML.pm can ready our output
261 skip "Need YAML.pm to test if it can load META.yml", 1
262 unless eval { require YAML };
264 my $yaml_load = YAML::Load($mm->metafile_file(@meta));
265 is_deeply( $yaml_load, {@meta}, "META.yml can be read by YAML.pm" );
270 skip "Need YAML::Tiny to test if it can load META.yml", 2
271 unless eval { require YAML::Tiny };
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" );
281 my @meta = ( k => 'a : b', 'x : y' => 1 );
282 my $expected = <<YAML;
287 # NOTE: the output is not YAML-equivalent to the input
289 is($mm->metafile_file(@meta), $expected, "no quoting is done");
293 my @meta = ( k => \*STDOUT );
294 eval { $mm->metafile_file(@meta) };
296 like($@, qr/^only nested hashes, arrays and objects are supported/,
297 "we don't like but hash/array refs");
301 my @meta = ( k => [ [] ] );
302 eval { $mm->metafile_file(@meta) };
304 like($@, qr/^only nested arrays of non-refs are supported/,
305 "we also don't like but array of strings");
308 # recursive data structures: don't even think about it - endless recursion