6 use Test::More tests => 22;
11 use Parse::CPAN::Meta;
13 require ExtUtils::MM_Any;
17 my $dir = shift || File::Temp->newdir;
19 # chdir to the new directory
21 chdir $dir or die "Can't chdir to $dir: $!";
23 # Run the code, but trap the error so we can chdir back
25 my $ok = eval { $return = $code->(); 1; };
29 chdir $orig_dir or die "Can't chdir to $orig_dir: $!";
31 # rethrow if necessary
38 my($have, $want, $name) = @_;
40 local $Test::Builder::Level = $Test::Builder::Level + 1;
42 my $have_gen = delete $have->{generated_by};
43 my $want_gen = delete $want->{generated_by};
45 is_deeply $have, $want, $name;
46 like $have_gen, qr{CPAN::Meta}, "CPAN::Meta mentioned in the generated_by";
52 return bless { ARGS => {@_}, @_ }, 'ExtUtils::MM_Any';
57 DISTNAME => 'Foo-Bar',
60 "Foo::Bar" => 'lib/Foo/Bar.pm',
64 is_deeply {$mm->metafile_data}, {
67 abstract => 'unknown',
71 distribution_type => 'module',
73 configure_requires => {
74 'ExtUtils::MakeMaker' => 0,
77 'ExtUtils::MakeMaker' => 0,
81 directory => [qw(t inc)],
84 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
86 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
92 is_deeply {$mm->metafile_data({}, { no_index => { directory => [qw(foo)] } })}, {
95 abstract => 'unknown',
99 distribution_type => 'module',
101 configure_requires => {
102 'ExtUtils::MakeMaker' => 0,
105 'ExtUtils::MakeMaker' => 0,
109 directory => [qw(t inc foo)],
112 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
114 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
117 }, 'rt.cpan.org 39348';
123 DISTNAME => 'Foo-Bar',
125 AUTHOR => ['Some Guy'],
132 is_deeply {$mm->metafile_data(
134 configure_requires => {
149 abstract => 'unknown',
150 author => ['Some Guy'],
151 license => 'unknown',
153 distribution_type => 'script',
155 configure_requires => {
159 'ExtUtils::MakeMaker' => 0,
168 directory => [qw(t inc)],
172 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
174 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
184 # Test MIN_PERL_VERSION
187 DISTNAME => 'Foo-Bar',
190 "Foo::Bar" => 'lib/Foo/Bar.pm',
192 MIN_PERL_VERSION => 5.006,
195 is_deeply {$mm->metafile_data}, {
198 abstract => 'unknown',
200 license => 'unknown',
202 distribution_type => 'module',
204 configure_requires => {
205 'ExtUtils::MakeMaker' => 0,
208 'ExtUtils::MakeMaker' => 0,
216 directory => [qw(t inc)],
219 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
221 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
228 # Test MIN_PERL_VERSION
231 DISTNAME => 'Foo-Bar',
234 "Foo::Bar" => 'lib/Foo/Bar.pm',
236 MIN_PERL_VERSION => 5.006,
242 is_deeply {$mm->metafile_data}, {
245 abstract => 'unknown',
247 license => 'unknown',
249 distribution_type => 'module',
251 configure_requires => {
252 'ExtUtils::MakeMaker' => 0,
255 'ExtUtils::MakeMaker' => 0,
264 directory => [qw(t inc)],
267 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
269 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
275 # Test CONFIGURE_REQUIRES
278 DISTNAME => 'Foo-Bar',
280 CONFIGURE_REQUIRES => {
281 "Fake::Module1" => 1.01,
284 "Foo::Bar" => 'lib/Foo/Bar.pm',
288 is_deeply {$mm->metafile_data}, {
291 abstract => 'unknown',
293 license => 'unknown',
295 distribution_type => 'module',
297 configure_requires => {
298 'Fake::Module1' => 1.01,
301 'ExtUtils::MakeMaker' => 0,
305 directory => [qw(t inc)],
308 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
310 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
313 },'CONFIGURE_REQUIRES';
316 # Test BUILD_REQUIRES
319 DISTNAME => 'Foo-Bar',
322 "Fake::Module1" => 1.01,
325 "Foo::Bar" => 'lib/Foo/Bar.pm',
329 is_deeply {$mm->metafile_data}, {
332 abstract => 'unknown',
334 license => 'unknown',
336 distribution_type => 'module',
338 configure_requires => {
339 'ExtUtils::MakeMaker' => 0,
342 'Fake::Module1' => 1.01,
346 directory => [qw(t inc)],
349 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
351 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
354 },'CONFIGURE_REQUIRES';
357 # Test _REQUIRES key priority over META_ADD
361 DISTNAME => 'Foo-Bar',
364 "Fake::Module1" => 1.01,
366 META_ADD => (my $meta_add = { build_requires => {} }),
368 "Foo::Bar" => 'lib/Foo/Bar.pm',
372 is_deeply {$mm->metafile_data($meta_add)}, {
375 abstract => 'unknown',
377 license => 'unknown',
379 distribution_type => 'module',
381 configure_requires => {
382 'ExtUtils::MakeMaker' => 0,
384 build_requires => { },
387 directory => [qw(t inc)],
390 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
392 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
395 },'META.yml data (META_ADD wins)';
398 # Yes, this is all hard coded.
401 name => 'ExtUtils-MakeMaker',
402 version => '6.57_07',
403 abstract => 'Create a module Makefile',
404 author => ['Michael G Schwern <schwern@pobox.com>'],
405 license => ['perl_5'],
412 "File::Basename" => 0,
413 "File::Spec" => "0.8",
424 'Fake::Module1' => 1.01,
429 release_status => 'testing',
431 license => [ 'http://dev.perl.org/licenses/' ],
432 homepage => 'http://makemaker.org',
433 bugtracker => { web => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=ExtUtils-MakeMaker' },
434 repository => { url => 'http://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker' },
435 x_MailingList => 'makemaker@perl.org',
439 directory => [qw(t inc)],
440 package => ["DynaLoader", "in"],
443 generated_by => "ExtUtils::MakeMaker version 6.5707, CPAN::Meta::Converter version 2.110580",
445 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
450 mymeta_ok $mm->mymeta("t/META_for_testing.json"),
452 'MYMETA JSON data (BUILD_REQUIRES wins)';
454 mymeta_ok $mm->mymeta("t/META_for_testing.yml"),
456 'MYMETA YAML data (BUILD_REQUIRES wins)';
461 DISTNAME => 'Foo-Bar',
463 BUILD_REQUIRES => { "Fake::Module1" => 1.01 },
464 TEST_REQUIRES => { "Fake::Module2" => 1.23 },
467 my $meta = $mm->mymeta('t/META_for_testing.json');
468 is($meta->{build_requires}, undef, "no build_requires in v2 META");
470 $meta->{prereqs}{build}{requires},
471 { "Fake::Module1" => 1.01 },
472 "build requires are one thing in META v2...",
476 $meta->{prereqs}{test}{requires},
477 { "Fake::Module2" => 1.23 },
478 "...and test requires are another",
482 note "CPAN::Meta bug using the module version instead of the meta spec version"; {
484 NAME => 'GD::Barcode::Code93',
485 AUTHOR => 'Chris DiMartino',
486 ABSTRACT => 'Code 93 implementation of GD::Barcode family',
494 my $meta = $mm->mymeta("t/META_for_testing_tricky_version.yml");
495 is $meta->{'meta-spec'}{version}, 2, "internally, our MYMETA struct is v2";
498 $mm->write_mymeta($meta);
502 my $meta_yml = Parse::CPAN::Meta->load_file("MYMETA.yml");
503 is $meta_yml->{'meta-spec'}{version}, 1.4, "MYMETA.yml correctly downgraded to 1.4";
505 my $meta_json = Parse::CPAN::Meta->load_file("MYMETA.json");
506 cmp_ok $meta_json->{'meta-spec'}{version}, ">=", 2, "MYMETA.json at 2 or better";
511 note "A bad license string"; {
513 DISTNAME => 'Foo::Bar',
515 LICENSE => 'death and retribution',
519 my $meta = $mm->mymeta;
520 $mm->write_mymeta($meta);
522 my $meta_yml = Parse::CPAN::Meta->load_file("MYMETA.yml");
523 is $meta_yml->{license}, "unknown", "in yaml";
525 my $meta_json = Parse::CPAN::Meta->load_file("MYMETA.json");
526 is_deeply $meta_json->{license}, ["unknown"], "in json";