6 use Test::More tests => 29;
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 meta-spec 1.4
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',
224 }, 'MIN_PERL_VERSION meta-spec 1.4';
227 # Test MIN_PERL_VERSION meta-spec 2.0
230 DISTNAME => 'Foo-Bar',
233 "Foo::Bar" => 'lib/Foo/Bar.pm',
235 MIN_PERL_VERSION => 5.006,
242 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
248 abstract => 'unknown',
250 license => 'unknown',
252 distribution_type => 'module',
257 'ExtUtils::MakeMaker' => 0,
262 'ExtUtils::MakeMaker' => 0,
273 directory => [qw(t inc)],
276 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
279 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
282 }, 'MIN_PERL_VERSION meta-spec 2.0';
285 # Test MIN_PERL_VERSION meta-spec 1.4
288 DISTNAME => 'Foo-Bar',
291 "Foo::Bar" => 'lib/Foo/Bar.pm',
293 MIN_PERL_VERSION => 5.006,
299 is_deeply {$mm->metafile_data}, {
302 abstract => 'unknown',
304 license => 'unknown',
306 distribution_type => 'module',
308 configure_requires => {
309 'ExtUtils::MakeMaker' => 0,
312 'ExtUtils::MakeMaker' => 0,
321 directory => [qw(t inc)],
324 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
326 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
329 }, 'MIN_PERL_VERSION and PREREQ_PM meta-spec 1.4';
332 # Test CONFIGURE_REQUIRES meta-spec 1.4
335 DISTNAME => 'Foo-Bar',
337 CONFIGURE_REQUIRES => {
338 "Fake::Module1" => 1.01,
341 "Foo::Bar" => 'lib/Foo/Bar.pm',
345 is_deeply {$mm->metafile_data}, {
348 abstract => 'unknown',
350 license => 'unknown',
352 distribution_type => 'module',
354 configure_requires => {
355 'Fake::Module1' => 1.01,
358 'ExtUtils::MakeMaker' => 0,
362 directory => [qw(t inc)],
365 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
367 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
370 },'CONFIGURE_REQUIRES meta-spec 1.4';
373 # Test CONFIGURE_REQUIRES meta-spec 2.0
376 DISTNAME => 'Foo-Bar',
378 CONFIGURE_REQUIRES => {
379 "Fake::Module1" => 1.01,
382 "Foo::Bar" => 'lib/Foo/Bar.pm',
390 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
396 abstract => 'unknown',
398 license => 'unknown',
400 distribution_type => 'module',
405 'Fake::Module1' => 1.01,
410 'ExtUtils::MakeMaker' => 0,
416 directory => [qw(t inc)],
419 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
421 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
424 },'CONFIGURE_REQUIRES meta-spec 2.0';
428 # Test BUILD_REQUIRES meta-spec 1.4
431 DISTNAME => 'Foo-Bar',
434 "Fake::Module1" => 1.01,
437 "Foo::Bar" => 'lib/Foo/Bar.pm',
441 is_deeply {$mm->metafile_data}, {
444 abstract => 'unknown',
446 license => 'unknown',
448 distribution_type => 'module',
450 configure_requires => {
451 'ExtUtils::MakeMaker' => 0,
454 'Fake::Module1' => 1.01,
458 directory => [qw(t inc)],
461 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
463 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
466 },'BUILD_REQUIRES meta-spec 1.4';
469 # Test BUILD_REQUIRES meta-spec 2.0
472 DISTNAME => 'Foo-Bar',
475 "Fake::Module1" => 1.01,
478 "Foo::Bar" => 'lib/Foo/Bar.pm',
480 META_MERGE => { "meta-spec" => { version => 2 }},
487 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
493 abstract => 'unknown',
495 license => 'unknown',
497 distribution_type => 'module',
502 'ExtUtils::MakeMaker' => 0,
507 'Fake::Module1' => 1.01,
513 directory => [qw(t inc)],
516 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
518 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
521 },'BUILD_REQUIRES meta-spec 2.0';
524 # Test TEST_REQUIRES meta-spec 1.4
527 DISTNAME => 'Foo-Bar',
530 "Fake::Module1" => 1.01,
533 "Foo::Bar" => 'lib/Foo/Bar.pm',
537 is_deeply {$mm->metafile_data}, {
540 abstract => 'unknown',
542 license => 'unknown',
544 distribution_type => 'module',
546 configure_requires => {
547 'ExtUtils::MakeMaker' => 0,
550 'ExtUtils::MakeMaker' => 0,
551 'Fake::Module1' => 1.01,
555 directory => [qw(t inc)],
558 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
560 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
563 },'TEST_REQUIRES meta-spec 1.4';
566 # Test TEST_REQUIRES meta-spec 2.0
569 DISTNAME => 'Foo-Bar',
572 "Fake::Module1" => 1.01,
575 "Foo::Bar" => 'lib/Foo/Bar.pm',
577 META_MERGE => { "meta-spec" => { version => 2 }},
584 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
590 abstract => 'unknown',
592 license => 'unknown',
594 distribution_type => 'module',
599 'ExtUtils::MakeMaker' => 0,
604 'ExtUtils::MakeMaker' => 0,
609 "Fake::Module1" => 1.01,
615 directory => [qw(t inc)],
618 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
620 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
623 },'TEST_REQUIRES meta-spec 2.0';
627 # Test _REQUIRES key priority over META_ADD
631 DISTNAME => 'Foo-Bar',
634 "Fake::Module1" => 1.01,
636 META_ADD => (my $meta_add = { build_requires => {}, configure_requires => {} }),
638 "Foo::Bar" => 'lib/Foo/Bar.pm',
642 is_deeply {$mm->metafile_data($meta_add)}, {
645 abstract => 'unknown',
647 license => 'unknown',
649 distribution_type => 'module',
651 configure_requires => { },
652 build_requires => { },
655 directory => [qw(t inc)],
658 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
660 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
663 },'META.yml data (META_ADD wins)';
666 # Yes, this is all hard coded.
669 name => 'ExtUtils-MakeMaker',
670 version => '6.57_07',
671 abstract => 'Create a module Makefile',
672 author => ['Michael G Schwern <schwern@pobox.com>'],
673 license => ['perl_5'],
680 "File::Basename" => 0,
681 "File::Spec" => "0.8",
688 'ExtUtils::MakeMaker' => 0,
693 'Fake::Module1' => 1.01,
698 release_status => 'testing',
700 license => [ 'http://dev.perl.org/licenses/' ],
701 homepage => 'http://makemaker.org',
702 bugtracker => { web => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=ExtUtils-MakeMaker' },
703 repository => { url => 'http://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker' },
704 x_MailingList => 'makemaker@perl.org',
708 directory => [qw(t inc)],
709 package => ["DynaLoader", "in"],
712 generated_by => "ExtUtils::MakeMaker version 6.5707, CPAN::Meta::Converter version 2.110580",
714 url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
719 mymeta_ok $mm->mymeta("t/META_for_testing.json"),
721 'MYMETA JSON data (BUILD_REQUIRES wins)';
723 mymeta_ok $mm->mymeta("t/META_for_testing.yml"),
725 'MYMETA YAML data (BUILD_REQUIRES wins)';
730 DISTNAME => 'Foo-Bar',
732 CONFIGURE_REQUIRES => { "Fake::Module0" => 0.99 },
733 BUILD_REQUIRES => { "Fake::Module1" => 1.01 },
734 TEST_REQUIRES => { "Fake::Module2" => 1.23 },
737 my $meta = $mm->mymeta('t/META_for_testing.json');
738 is($meta->{configure_requires}, undef, "no configure_requires in v2 META");
739 is($meta->{build_requires}, undef, "no build_requires in v2 META");
741 $meta->{prereqs}{configure}{requires},
742 { "Fake::Module0" => 0.99 },
743 "configure requires are one thing in META v2...",
747 $meta->{prereqs}{build}{requires},
748 { "Fake::Module1" => 1.01 },
749 "build requires are one thing in META v2...",
753 $meta->{prereqs}{test}{requires},
754 { "Fake::Module2" => 1.23 },
755 "...and test requires are another",
759 note "CPAN::Meta bug using the module version instead of the meta spec version"; {
761 NAME => 'GD::Barcode::Code93',
762 AUTHOR => 'Chris DiMartino',
763 ABSTRACT => 'Code 93 implementation of GD::Barcode family',
771 my $meta = $mm->mymeta("t/META_for_testing_tricky_version.yml");
772 is $meta->{'meta-spec'}{version}, 2, "internally, our MYMETA struct is v2";
775 $mm->write_mymeta($meta);
779 my $meta_yml = Parse::CPAN::Meta->load_file("MYMETA.yml");
780 is $meta_yml->{'meta-spec'}{version}, 1.4, "MYMETA.yml correctly downgraded to 1.4";
782 my $meta_json = Parse::CPAN::Meta->load_file("MYMETA.json");
783 cmp_ok $meta_json->{'meta-spec'}{version}, ">=", 2, "MYMETA.json at 2 or better";
788 note "A bad license string"; {
790 DISTNAME => 'Foo::Bar',
792 LICENSE => 'death and retribution',
796 my $meta = $mm->mymeta;
797 $mm->write_mymeta($meta);
799 my $meta_yml = Parse::CPAN::Meta->load_file("MYMETA.yml");
800 is $meta_yml->{license}, "unknown", "in yaml";
802 my $meta_json = Parse::CPAN::Meta->load_file("MYMETA.json");
803 is_deeply $meta_json->{license}, ["unknown"], "in json";