Move Module::Pluggable into ext/ as the next version has actions in its
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / metadata2.t
CommitLineData
bb4e9162 1#!/usr/bin/perl -w
2
3use strict;
4use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5use MBTest tests => 18;
6
7use Cwd ();
8my $cwd = Cwd::cwd;
7a827510 9my $tmp = MBTest->tmpdir;
bb4e9162 10
11use Module::Build;
12use Module::Build::ConfigData;
13use DistGen;
14
15
16############################## ACTION distmeta works without a MANIFEST file
17
18SKIP: {
19 skip( 'YAML_support feature is not enabled', 4 )
20 unless Module::Build::ConfigData->feature('YAML_support');
21
22 my $dist = DistGen->new( dir => $tmp, skip_manifest => 1 );
23 $dist->regen;
24
25 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
26
27 ok ! -e 'MANIFEST';
28
29 my $mb = Module::Build->new_from_context;
30
31 my $out;
32 $out = eval { stderr_of(sub{$mb->dispatch('distmeta')}) };
33 is $@, '';
34
35 like $out, qr/Nothing to enter for 'provides'/;
36
37 ok -e 'META.yml';
38
39 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
40 $dist->remove;
41}
42
43
44############################## Check generation of README file
45
46# TODO: We need to test faking the absence of Pod::Readme when present
47# so Pod::Text will be used. Also fake the absence of both to
48# test that we fail gracefully.
49
50my $provides; # Used a bunch of times below
51
52my $pod_text = <<'---';
53=pod
54
55=head1 NAME
56
57Simple - A simple module
58
59=head1 AUTHOR
60
61Simple Simon <simon@simple.sim>
62
63=cut
64---
65
66my $dist = DistGen->new( dir => $tmp );
67
7a827510 68$dist->change_build_pl
69({
70 module_name => $dist->name,
bb4e9162 71 dist_version => '3.14159265',
72 license => 'perl',
73 create_readme => 1,
7a827510 74});
bb4e9162 75$dist->regen;
76
77chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
78
79
80# .pm File with pod
81#
82
83$dist->change_file( 'lib/Simple.pm', <<'---' . $pod_text);
84package Simple;
85$VERSION = '1.23';
86---
87$dist->regen( clean => 1 );
88ok( -e "lib/Simple.pm", "Creating Simple.pm" );
89my $mb = Module::Build->new_from_context;
90$mb->do_create_readme;
91like( slurp("README"), qr/NAME/,
92 "Generating README from .pm");
93is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>',
94 "Extracting AUTHOR from .pm");
95is( $mb->dist_abstract, "A simple module",
96 "Extracting abstract from .pm");
97
98# .pm File with pod in separate file
99#
100
101$dist->change_file( 'lib/Simple.pm', <<'---');
102package Simple;
103$VERSION = '1.23';
104---
105$dist->change_file( 'lib/Simple.pod', $pod_text );
106$dist->regen( clean => 1 );
107
108ok( -e "lib/Simple.pm", "Creating Simple.pm" );
109ok( -e "lib/Simple.pod", "Creating Simple.pod" );
110$mb = Module::Build->new_from_context;
111$mb->do_create_readme;
112like( slurp("README"), qr/NAME/, "Generating README from .pod");
113is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>',
114 "Extracting AUTHOR from .pod");
115is( $mb->dist_abstract, "A simple module",
116 "Extracting abstract from .pod");
117
118# .pm File with pod and separate pod file
119#
120
121$dist->change_file( 'lib/Simple.pm', <<'---' );
122package Simple;
123$VERSION = '1.23';
124
125=pod
126
127=head1 DONT USE THIS FILE FOR POD
128
129=cut
130---
131$dist->change_file( 'lib/Simple.pod', $pod_text );
132$dist->regen( clean => 1 );
133ok( -e "lib/Simple.pm", "Creating Simple.pm" );
134ok( -e "lib/Simple.pod", "Creating Simple.pod" );
135$mb = Module::Build->new_from_context;
136$mb->do_create_readme;
137like( slurp("README"), qr/NAME/, "Generating README from .pod over .pm");
138is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>',
139 "Extracting AUTHOR from .pod over .pm");
140is( $mb->dist_abstract, "A simple module",
141 "Extracting abstract from .pod over .pm");
142
143
144############################################################
145# cleanup
146chdir( $cwd ) or die "Can't chdir to '$cwd': $!";
147$dist->remove;
148
149use File::Path;
150rmtree( $tmp );