This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update ExtUtils-MakeMaker to CPAN version 6.86
[perl5.git] / cpan / ExtUtils-MakeMaker / t / metafile_data.t
1 BEGIN {
2     unshift @INC, 't/lib';
3 }
4
5 use strict;
6 use Test::More tests => 29;
7
8 use Data::Dumper;
9 use File::Temp;
10 use Cwd;
11 use Parse::CPAN::Meta;
12
13 require ExtUtils::MM_Any;
14
15 sub in_dir(&;$) {
16     my $code = shift;
17     my $dir = shift || File::Temp->newdir;
18
19     # chdir to the new directory
20     my $orig_dir = cwd();
21     chdir $dir or die "Can't chdir to $dir: $!";
22
23     # Run the code, but trap the error so we can chdir back
24     my $return;
25     my $ok = eval { $return = $code->(); 1; };
26     my $err = $@;
27
28     # chdir back
29     chdir $orig_dir or die "Can't chdir to $orig_dir: $!";
30
31     # rethrow if necessary
32     die $err unless $ok;
33
34     return $return;
35 }
36
37 sub mymeta_ok {
38     my($have, $want, $name) = @_;
39
40     local $Test::Builder::Level = $Test::Builder::Level + 1;
41
42     my $have_gen = delete $have->{generated_by};
43     my $want_gen = delete $want->{generated_by};
44
45     is_deeply $have, $want, $name;
46     like $have_gen, qr{CPAN::Meta}, "CPAN::Meta mentioned in the generated_by";
47
48     return;
49 }
50
51 my $new_mm = sub {
52     return bless { ARGS => {@_}, @_ }, 'ExtUtils::MM_Any';
53 };
54
55 {
56     my $mm = $new_mm->(
57         DISTNAME        => 'Foo-Bar',
58         VERSION         => 1.23,
59         PM              => {
60             "Foo::Bar"          => 'lib/Foo/Bar.pm',
61         },
62     );
63
64     is_deeply {$mm->metafile_data}, {
65         name            => 'Foo-Bar',
66         version         => 1.23,
67         abstract        => 'unknown',
68         author          => [],
69         license         => 'unknown',
70         dynamic_config  => 1,
71         distribution_type       => 'module',
72
73         configure_requires      => {
74             'ExtUtils::MakeMaker'       => 0,
75         },
76         build_requires      => {
77             'ExtUtils::MakeMaker'       => 0,
78         },
79
80         no_index        => {
81             directory           => [qw(t inc)],
82         },
83
84         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
85         'meta-spec'  => {
86             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
87             version     => 1.4
88         },
89     };
90
91
92     is_deeply {$mm->metafile_data({}, { no_index => { directory => [qw(foo)] } })}, {
93         name            => 'Foo-Bar',
94         version         => 1.23,
95         abstract        => 'unknown',
96         author          => [],
97         license         => 'unknown',
98         dynamic_config  => 1,
99         distribution_type       => 'module',
100
101         configure_requires      => {
102             'ExtUtils::MakeMaker'       => 0,
103         },
104         build_requires      => {
105             'ExtUtils::MakeMaker'       => 0,
106         },
107
108         no_index        => {
109             directory           => [qw(t inc foo)],
110         },
111
112         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
113         'meta-spec'  => {
114             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
115             version     => 1.4
116         },
117     }, 'rt.cpan.org 39348';
118 }
119
120
121 {
122     my $mm = $new_mm->(
123         DISTNAME        => 'Foo-Bar',
124         VERSION         => 1.23,
125         AUTHOR          => ['Some Guy'],
126         PREREQ_PM       => {
127             Foo                 => 2.34,
128             Bar                 => 4.56,
129         },
130     );
131
132     is_deeply {$mm->metafile_data(
133         {
134             configure_requires => {
135                 Stuff   => 2.34
136             },
137             wobble      => 42
138         },
139         {
140             no_index    => {
141                 package => "Thing"
142             },
143             wibble      => 23
144         },
145     )},
146     {
147         name            => 'Foo-Bar',
148         version         => 1.23,
149         abstract        => 'unknown',
150         author          => ['Some Guy'],
151         license         => 'unknown',
152         dynamic_config  => 1,
153         distribution_type       => 'script',
154
155         configure_requires      => {
156             Stuff       => 2.34,
157         },
158         build_requires      => {
159             'ExtUtils::MakeMaker'       => 0,
160         },
161
162         requires       => {
163             Foo                 => 2.34,
164             Bar                 => 4.56,
165         },
166
167         no_index        => {
168             directory           => [qw(t inc)],
169             package             => 'Thing',
170         },
171
172         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
173         'meta-spec'  => {
174             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
175             version     => 1.4
176         },
177
178         wibble  => 23,
179         wobble  => 42,
180     };
181 }
182
183
184 # Test MIN_PERL_VERSION meta-spec 1.4
185 {
186     my $mm = $new_mm->(
187         DISTNAME        => 'Foo-Bar',
188         VERSION         => 1.23,
189         PM              => {
190             "Foo::Bar"          => 'lib/Foo/Bar.pm',
191         },
192         MIN_PERL_VERSION => 5.006,
193     );
194
195     is_deeply {$mm->metafile_data}, {
196         name            => 'Foo-Bar',
197         version         => 1.23,
198         abstract        => 'unknown',
199         author          => [],
200         license         => 'unknown',
201         dynamic_config  => 1,
202         distribution_type       => 'module',
203
204         configure_requires      => {
205             'ExtUtils::MakeMaker'       => 0,
206         },
207         build_requires      => {
208             'ExtUtils::MakeMaker'       => 0,
209         },
210
211         requires        => {
212             perl        => '5.006',
213         },
214
215         no_index        => {
216             directory           => [qw(t inc)],
217         },
218
219         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
220         'meta-spec'  => {
221             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
222             version     => 1.4
223         },
224     }, 'MIN_PERL_VERSION meta-spec 1.4';
225 }
226
227 # Test MIN_PERL_VERSION meta-spec 2.0
228 {
229     my $mm = $new_mm->(
230         DISTNAME        => 'Foo-Bar',
231         VERSION         => 1.23,
232         PM              => {
233             "Foo::Bar"          => 'lib/Foo/Bar.pm',
234         },
235         MIN_PERL_VERSION => 5.006,
236     );
237
238     is_deeply {
239         $mm->metafile_data(
240                 {}, {
241                 'meta-spec' => {
242                 url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
243                 version => 2
244                 } } )
245     }, {
246         name            => 'Foo-Bar',
247         version         => 1.23,
248         abstract        => 'unknown',
249         author          => [],
250         license         => 'unknown',
251         dynamic_config  => 1,
252         distribution_type       => 'module',
253
254         prereqs => {
255             configure       => {
256                 requires    => {
257                     'ExtUtils::MakeMaker'   => 0,
258                 },
259             },
260             build           => {
261                 requires    => {
262                     'ExtUtils::MakeMaker'   => 0,
263                 },
264             },
265             runtime         => {
266                 requires    => {
267                     'perl'  => '5.006',
268                 },
269             },
270         },
271
272         no_index        => {
273             directory           => [qw(t inc)],
274         },
275
276         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
277         'meta-spec'  => {
278
279             url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
280             version => 2
281         },
282     }, 'MIN_PERL_VERSION meta-spec 2.0';
283 }
284
285 # Test MIN_PERL_VERSION meta-spec 1.4
286 {
287     my $mm = $new_mm->(
288         DISTNAME        => 'Foo-Bar',
289         VERSION         => 1.23,
290         PM              => {
291             "Foo::Bar"          => 'lib/Foo/Bar.pm',
292         },
293         MIN_PERL_VERSION => 5.006,
294         PREREQ_PM => {
295             'Foo::Bar'  => 1.23,
296         },
297     );
298
299     is_deeply {$mm->metafile_data}, {
300         name            => 'Foo-Bar',
301         version         => 1.23,
302         abstract        => 'unknown',
303         author          => [],
304         license         => 'unknown',
305         dynamic_config  => 1,
306         distribution_type       => 'module',
307
308         configure_requires      => {
309             'ExtUtils::MakeMaker'       => 0,
310         },
311         build_requires      => {
312             'ExtUtils::MakeMaker'       => 0,
313         },
314
315         requires        => {
316             perl        => '5.006',
317             'Foo::Bar'  => 1.23,
318         },
319
320         no_index        => {
321             directory           => [qw(t inc)],
322         },
323
324         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
325         'meta-spec'  => {
326             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
327             version     => 1.4
328         },
329     }, 'MIN_PERL_VERSION and PREREQ_PM meta-spec 1.4';
330 }
331
332 # Test CONFIGURE_REQUIRES meta-spec 1.4
333 {
334     my $mm = $new_mm->(
335         DISTNAME        => 'Foo-Bar',
336         VERSION         => 1.23,
337         CONFIGURE_REQUIRES => {
338             "Fake::Module1" => 1.01,
339         },
340         PM              => {
341             "Foo::Bar"          => 'lib/Foo/Bar.pm',
342         },
343     );
344
345     is_deeply {$mm->metafile_data}, {
346         name            => 'Foo-Bar',
347         version         => 1.23,
348         abstract        => 'unknown',
349         author          => [],
350         license         => 'unknown',
351         dynamic_config  => 1,
352         distribution_type       => 'module',
353
354         configure_requires      => {
355             'Fake::Module1'     => 1.01,
356         },
357         build_requires      => {
358             'ExtUtils::MakeMaker'   => 0,
359         },
360
361         no_index        => {
362             directory           => [qw(t inc)],
363         },
364
365         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
366         'meta-spec'  => {
367             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
368             version     => 1.4
369         },
370     },'CONFIGURE_REQUIRES meta-spec 1.4';
371 }
372
373 # Test CONFIGURE_REQUIRES meta-spec 2.0
374 {
375     my $mm = $new_mm->(
376         DISTNAME        => 'Foo-Bar',
377         VERSION         => 1.23,
378         CONFIGURE_REQUIRES => {
379             "Fake::Module1" => 1.01,
380         },
381         PM              => {
382             "Foo::Bar"      => 'lib/Foo/Bar.pm',
383         },
384     );
385
386     is_deeply {
387         $mm->metafile_data(
388                 {}, {
389                 'meta-spec' => {
390                 url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
391                 version => 2
392                 } } )
393     }, {
394         name            => 'Foo-Bar',
395         version         => 1.23,
396         abstract        => 'unknown',
397         author          => [],
398         license         => 'unknown',
399         dynamic_config  => 1,
400         distribution_type       => 'module',
401
402         prereqs => {
403             configure       => {
404                 requires    => {
405                     'Fake::Module1'         => 1.01,
406                 },
407             },
408             build           => {
409                 requires    => {
410                     'ExtUtils::MakeMaker'   => 0,
411                 },
412             },
413         },
414
415         no_index        => {
416             directory           => [qw(t inc)],
417         },
418
419         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
420         'meta-spec'  => {
421             url         => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
422             version     => 2
423         },
424     },'CONFIGURE_REQUIRES meta-spec 2.0';
425 }
426
427
428 # Test BUILD_REQUIRES meta-spec 1.4
429 {
430     my $mm = $new_mm->(
431         DISTNAME        => 'Foo-Bar',
432         VERSION         => 1.23,
433         BUILD_REQUIRES => {
434             "Fake::Module1" => 1.01,
435         },
436         PM              => {
437             "Foo::Bar"          => 'lib/Foo/Bar.pm',
438         },
439     );
440
441     is_deeply {$mm->metafile_data}, {
442         name            => 'Foo-Bar',
443         version         => 1.23,
444         abstract        => 'unknown',
445         author          => [],
446         license         => 'unknown',
447         dynamic_config  => 1,
448         distribution_type       => 'module',
449
450         configure_requires      => {
451             'ExtUtils::MakeMaker'   => 0,
452         },
453         build_requires      => {
454             'Fake::Module1'         => 1.01,
455         },
456
457         no_index        => {
458             directory           => [qw(t inc)],
459         },
460
461         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
462         'meta-spec'  => {
463             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
464             version     => 1.4
465         },
466     },'BUILD_REQUIRES meta-spec 1.4';
467 }
468
469 # Test BUILD_REQUIRES meta-spec 2.0
470 {
471     my $mm = $new_mm->(
472         DISTNAME        => 'Foo-Bar',
473         VERSION         => 1.23,
474         BUILD_REQUIRES => {
475             "Fake::Module1" => 1.01,
476         },
477         PM              => {
478             "Foo::Bar"          => 'lib/Foo/Bar.pm',
479         },
480         META_MERGE => { "meta-spec" => { version => 2 }},
481     );
482
483     is_deeply {
484         $mm->metafile_data(
485                 {}, {
486                 'meta-spec' => {
487                 url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
488                 version => 2
489                 } } )
490     }, {
491         name            => 'Foo-Bar',
492         version         => 1.23,
493         abstract        => 'unknown',
494         author          => [],
495         license         => 'unknown',
496         dynamic_config  => 1,
497         distribution_type       => 'module',
498
499         prereqs => {
500             configure       => {
501                 requires    => {
502                     'ExtUtils::MakeMaker'   => 0,
503                 },
504             },
505             build           => {
506                 requires    => {
507                     'Fake::Module1'         => 1.01,
508                 },
509             },
510         },
511
512         no_index        => {
513             directory           => [qw(t inc)],
514         },
515
516         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
517         'meta-spec'  => {
518             url         => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
519             version     => 2
520         },
521     },'BUILD_REQUIRES meta-spec 2.0';
522 }
523
524 # Test TEST_REQUIRES meta-spec 1.4
525 {
526     my $mm = $new_mm->(
527         DISTNAME        => 'Foo-Bar',
528         VERSION         => 1.23,
529         TEST_REQUIRES => {
530             "Fake::Module1"     => 1.01,
531         },
532         PM              => {
533             "Foo::Bar"          => 'lib/Foo/Bar.pm',
534         },
535     );
536
537     is_deeply {$mm->metafile_data}, {
538         name            => 'Foo-Bar',
539         version         => 1.23,
540         abstract        => 'unknown',
541         author          => [],
542         license         => 'unknown',
543         dynamic_config  => 1,
544         distribution_type       => 'module',
545
546         configure_requires      => {
547             'ExtUtils::MakeMaker'       => 0,
548         },
549         build_requires      => {
550             'ExtUtils::MakeMaker'       => 0,
551             'Fake::Module1'             => 1.01,
552         },
553
554         no_index        => {
555             directory           => [qw(t inc)],
556         },
557
558         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
559         'meta-spec'  => {
560             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
561             version     => 1.4
562         },
563     },'TEST_REQUIRES meta-spec 1.4';
564 }
565
566 # Test TEST_REQUIRES meta-spec 2.0
567 {
568     my $mm = $new_mm->(
569         DISTNAME        => 'Foo-Bar',
570         VERSION         => 1.23,
571         TEST_REQUIRES => {
572             "Fake::Module1"     => 1.01,
573         },
574         PM              => {
575             "Foo::Bar"          => 'lib/Foo/Bar.pm',
576         },
577         META_MERGE => { "meta-spec" => { version => 2 }},
578     );
579
580     is_deeply {
581         $mm->metafile_data(
582                 {}, {
583                 'meta-spec' => {
584                 url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
585                 version => 2
586                 } } )
587     }, {
588         name            => 'Foo-Bar',
589         version         => 1.23,
590         abstract        => 'unknown',
591         author          => [],
592         license         => 'unknown',
593         dynamic_config  => 1,
594         distribution_type       => 'module',
595
596         prereqs => {
597             configure       => {
598                 requires    => {
599                     'ExtUtils::MakeMaker'   => 0,
600                 },
601             },
602             build           => {
603                 requires    => {
604                     'ExtUtils::MakeMaker'   => 0,
605                 },
606             },
607             test            => {
608                 requires    => {
609                     "Fake::Module1"         => 1.01,
610                 },
611             },
612         },
613
614         no_index        => {
615             directory           => [qw(t inc)],
616         },
617
618         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
619         'meta-spec'  => {
620             url         => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
621             version     => 2
622         },
623     },'TEST_REQUIRES meta-spec 2.0';
624 }
625
626
627 # Test _REQUIRES key priority over META_ADD
628
629 {
630     my $mm = $new_mm->(
631         DISTNAME        => 'Foo-Bar',
632         VERSION         => 1.23,
633         BUILD_REQUIRES => {
634             "Fake::Module1" => 1.01,
635         },
636         META_ADD => (my $meta_add = { build_requires => {}, configure_requires => {} }),
637         PM              => {
638             "Foo::Bar"          => 'lib/Foo/Bar.pm',
639         },
640     );
641
642     is_deeply {$mm->metafile_data($meta_add)}, {
643         name            => 'Foo-Bar',
644         version         => 1.23,
645         abstract        => 'unknown',
646         author          => [],
647         license         => 'unknown',
648         dynamic_config  => 1,
649         distribution_type       => 'module',
650
651         configure_requires      => { },
652         build_requires          => { },
653
654         no_index        => {
655             directory           => [qw(t inc)],
656         },
657
658         generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
659         'meta-spec'  => {
660             url         => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
661             version     => 1.4
662         },
663     },'META.yml data (META_ADD wins)';
664
665
666     # Yes, this is all hard coded.
667     require CPAN::Meta;
668     my $want_mymeta = {
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'],
674         dynamic_config  => 0,
675
676         prereqs => {
677             runtime => {
678                 requires => {
679                     "DirHandle"         => 0,
680                     "File::Basename"    => 0,
681                     "File::Spec"        => "0.8",
682                     "Pod::Man"          => 0,
683                     "perl"              => "5.006",
684                 },
685             },
686             configure => {
687                 requires => {
688                     'ExtUtils::MakeMaker'   => 0,
689                 },
690             },
691             build    => {
692                 requires => {
693                     'Fake::Module1'       => 1.01,
694                 },
695             },
696         },
697
698         release_status => 'testing',
699         resources => {
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',
705         },
706
707         no_index        => {
708             directory           => [qw(t inc)],
709             package             => ["DynaLoader", "in"],
710         },
711
712         generated_by => "ExtUtils::MakeMaker version 6.5707, CPAN::Meta::Converter version 2.110580",
713         'meta-spec'  => {
714             url         => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
715             version     => 2,
716         },
717     };
718
719     mymeta_ok $mm->mymeta("t/META_for_testing.json"),
720               $want_mymeta,
721               'MYMETA JSON data (BUILD_REQUIRES wins)';
722
723     mymeta_ok $mm->mymeta("t/META_for_testing.yml"),
724               $want_mymeta,
725               'MYMETA YAML data (BUILD_REQUIRES wins)';
726 }
727
728 {
729     my $mm = $new_mm->(
730         DISTNAME            => 'Foo-Bar',
731         VERSION             => 1.23,
732         CONFIGURE_REQUIRES  => { "Fake::Module0" => 0.99 },
733         BUILD_REQUIRES      => { "Fake::Module1" => 1.01 },
734         TEST_REQUIRES       => { "Fake::Module2" => 1.23 },
735     );
736
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");
740     is_deeply(
741         $meta->{prereqs}{configure}{requires},
742         { "Fake::Module0" => 0.99 },
743         "configure requires are one thing in META v2...",
744     );
745
746     is_deeply(
747         $meta->{prereqs}{build}{requires},
748         { "Fake::Module1" => 1.01 },
749         "build requires are one thing in META v2...",
750     );
751
752     is_deeply(
753         $meta->{prereqs}{test}{requires},
754         { "Fake::Module2" => 1.23 },
755         "...and test requires are another",
756     );
757 }
758
759 note "CPAN::Meta bug using the module version instead of the meta spec version"; {
760     my $mm = $new_mm->(
761         NAME      => 'GD::Barcode::Code93',
762         AUTHOR    => 'Chris DiMartino',
763         ABSTRACT  => 'Code 93 implementation of GD::Barcode family',
764         PREREQ_PM => {
765             'GD::Barcode' => 0,
766             'GD'          => 0
767         },
768         VERSION   => '1.4',
769     );
770
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";
773
774     in_dir {
775         $mm->write_mymeta($meta);
776         ok -e "MYMETA.yml";
777         ok -e "MYMETA.json";
778
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";
781
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";
784     };
785 }
786
787
788 note "A bad license string"; {
789     my $mm = $new_mm->(
790         DISTNAME  => 'Foo::Bar',
791         VERSION   => '1.4',
792         LICENSE   => 'death and retribution',
793     );
794
795     in_dir {
796         my $meta = $mm->mymeta;
797         $mm->write_mymeta($meta);
798
799         my $meta_yml = Parse::CPAN::Meta->load_file("MYMETA.yml");
800         is $meta_yml->{license}, "unknown", "in yaml";
801
802         my $meta_json = Parse::CPAN::Meta->load_file("MYMETA.json");
803         is_deeply $meta_json->{license}, ["unknown"], "in json";
804     };
805 }