This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Module::Build to 0.39_01
[perl5.git] / cpan / Module-Build / t / mymeta.t
CommitLineData
613f422f
DG
1#!/usr/bin/perl -w
2
3use strict;
4use lib 't/lib';
53fc1c7e 5use MBTest;
a7c7ab1e 6use CPAN::Meta 2.110420;
2df9265e 7use CPAN::Meta::YAML;
a7c7ab1e
DG
8use Parse::CPAN::Meta 1.4401;
9plan tests => 39;
613f422f
DG
10
11blib_load('Module::Build');
12
13my $tmp = MBTest->tmpdir;
14
15use DistGen;
16my $dist = DistGen->new( dir => $tmp );
53fc1c7e
DG
17$dist->change_file('Build.PL', <<"---");
18use strict;
19use Module::Build;
20
21my \$builder = Module::Build->new(
22 module_name => '$dist->{name}',
23 license => 'perl',
24 requires => {
25 'File::Spec' => ( \$ENV{BUMP_PREREQ} ? 0.86 : 0 ),
26 },
27);
28
29\$builder->create_build_script();
30---
613f422f
DG
31$dist->regen;
32$dist->chdir_in;
33
34#########################
35
36# Test MYMETA generation
37{
53fc1c7e 38 ok( ! -e "META.yml", "META.yml doesn't exist before Build.PL runs" );
613f422f 39 ok( ! -e "MYMETA.yml", "MYMETA.yml doesn't exist before Build.PL runs" );
a7c7ab1e
DG
40 ok( ! -e "META.json", "META.json doesn't exist before Build.PL runs" );
41 ok( ! -e "MYMETA.json", "MYMETA.json doesn't exist before Build.PL runs" );
613f422f
DG
42 my $output;
43 $output = stdout_of sub { $dist->run_build_pl };
a7c7ab1e 44 like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
53fc1c7e
DG
45 "Ran Build.PL and saw MYMETA.yml creation message"
46 );
47 ok( -e "MYMETA.yml", "MYMETA.yml exists" );
a7c7ab1e 48 ok( -e "MYMETA.json", "MYMETA.json exists" );
53fc1c7e
DG
49}
50
51#########################
52
53# Test interactions between META/MYMETA
54{
7cf8bfc0 55 my $output = stdout_stderr_of sub { $dist->run_build('distmeta') };
a7c7ab1e 56 like($output, qr/Created META\.yml and META\.json/,
53fc1c7e 57 "Ran Build distmeta to create META.yml");
7cf8bfc0
DG
58 # regenerate MYMETA to pick up from META instead of creating from scratch
59 $output = stdout_of sub { $dist->run_build_pl };
a7c7ab1e 60 like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
7cf8bfc0
DG
61 "Re-ran Build.PL and regenerated MYMETA.yml based on META.yml"
62 );
63
a7c7ab1e
DG
64 for my $suffix ( qw/.yml .json/ ) {
65 my $meta = Parse::CPAN::Meta->load_file("META$suffix");
66 my $mymeta = Parse::CPAN::Meta->load_file("MYMETA$suffix");
67 is( delete $meta->{dynamic_config}, 1,
68 "META$suffix 'dynamic_config' is 1"
69 );
70 is( delete $mymeta->{dynamic_config}, 0,
71 "MYMETA$suffix 'dynamic_config' is 0"
72 );
73 is_deeply( $mymeta, $meta, "Other generated MYMETA$suffix matches generated META$suffix" )
74 or do {
75 require Data::Dumper;
76 diag "MYMETA:\n" . Data::Dumper::Dumper($mymeta)
77 . "META:\n" . Data::Dumper::Dumper($meta);
78 };
79 }
80
53fc1c7e
DG
81 $output = stdout_stderr_of sub { $dist->run_build('realclean') };
82 like( $output, qr/Cleaning up/, "Ran realclean");
83 ok( ! -e 'Build', "Build file removed" );
a7c7ab1e
DG
84 ok( ! -e 'MYMETA.yml', "MYMETA.yml file removed" );
85 ok( ! -e 'MYMETA.json', "MYMETA.json file removed" );
53fc1c7e
DG
86
87 # test that dynamic prereq is picked up
a7c7ab1e
DG
88 my $meta = Parse::CPAN::Meta->load_file("META.yml");
89 my $meta2 = Parse::CPAN::Meta->load_file("META.json");
53fc1c7e
DG
90 local $ENV{BUMP_PREREQ} = 1;
91 $output = stdout_of sub { $dist->run_build_pl };
a7c7ab1e 92 like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
53fc1c7e 93 "Ran Build.PL with dynamic config"
613f422f
DG
94 );
95 ok( -e "MYMETA.yml", "MYMETA.yml exists" );
a7c7ab1e
DG
96 ok( -e "MYMETA.json", "MYMETA.json exists" );
97 my $mymeta = Parse::CPAN::Meta->load_file('MYMETA.yml');
98 my $mymeta2 = Parse::CPAN::Meta->load_file('MYMETA.json');
53fc1c7e
DG
99 isnt( $meta->{requires}{'File::Spec'},
100 $mymeta->{requires}{'File::Spec'},
a7c7ab1e
DG
101 "MYMETA.yml requires differs from META.yml"
102 );
103 isnt( $meta2->{prereqs}{runtime}{requires}{'File::Spec'},
104 $mymeta2->{prereqs}{runtime}{requires}{'File::Spec'},
105 "MYMETA.json requires differs from META.json"
53fc1c7e
DG
106 );
107 $output = stdout_stderr_of sub { $dist->run_build('realclean') };
108 like( $output, qr/Cleaning up/, "Ran realclean");
109 ok( ! -e 'Build', "Build file removed" );
110 ok( ! -e 'MYMETA.yml', "MYMETA file removed" );
a7c7ab1e 111 ok( ! -e 'MYMETA.json', "MYMETA file removed" );
53fc1c7e
DG
112
113 # manually change META and check that changes are preserved
114 $meta->{author} = ['John Gault'];
a7c7ab1e 115 $meta2->{author} = ['John Gault'];
7cf8bfc0 116 ok( CPAN::Meta::YAML->new($meta)->write('META.yml'),
53fc1c7e 117 "Wrote manually modified META.yml" );
a7c7ab1e
DG
118 ok( CPAN::Meta->new( $meta2 )->save('META.json'),
119 "Wrote manually modified META.json" );
53fc1c7e
DG
120
121 $output = stdout_of sub { $dist->run_build_pl };
a7c7ab1e 122 like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
53fc1c7e
DG
123 "Ran Build.PL"
124 );
a7c7ab1e
DG
125 $mymeta = Parse::CPAN::Meta->load_file('MYMETA.yml');
126 $mymeta2 = Parse::CPAN::Meta->load_file('MYMETA.json');
127 is_deeply( $mymeta->{author}, [ 'John Gault' ],
128 "MYMETA.yml preserved META.yml modifications"
129 );
53fc1c7e 130 is_deeply( $mymeta2->{author}, [ 'John Gault' ],
a7c7ab1e 131 "MYMETA.json preserved META.json modifications"
53fc1c7e
DG
132 );
133
613f422f
DG
134}
135
136#########################
137
53fc1c7e
DG
138# Test cleanup
139{
140 my $output = stdout_stderr_of sub { $dist->run_build('distcheck') };
141 like($output, qr/Creating a temporary 'MANIFEST.SKIP'/,
142 "MANIFEST.SKIP created for distcheck"
143 );
144 unlike($output, qr/MYMETA/,
145 "MYMETA not flagged by distcheck"
146 );
147}
148
149
150{
151 my $output = stdout_of sub { $dist->run_build_pl };
a7c7ab1e 152 like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
53fc1c7e
DG
153 "Ran Build.PL and saw MYMETA.yml creation message"
154 );
155 $output = stdout_stderr_of sub { $dist->run_build('distclean') };
156 ok( ! -f 'MYMETA.yml', "No MYMETA.yml after distclean" );
a7c7ab1e 157 ok( ! -f 'MYMETA.json', "No MYMETA.json after distclean" );
53fc1c7e
DG
158 ok( ! -f 'MANIFEST.SKIP', "No MANIFEST.SKIP after distclean" );
159}
160
161