Add ExtUtils::Miniperl to the list of core modules for all versions >= 5.00504
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / manifypods.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;
6use Module::Build;
7use Module::Build::ConfigData;
8
9if ( Module::Build::ConfigData->feature('manpage_support') ) {
738349a8 10 plan tests => 22;
bb4e9162 11} else {
12 plan skip_all => 'manpage_support feature is not enabled';
13}
738349a8 14ensure_blib('Module::Build');
15
bb4e9162 16
17#########################
18
19
20use Cwd ();
21my $cwd = Cwd::cwd;
7a827510 22my $tmp = MBTest->tmpdir;
bb4e9162 23
24use DistGen;
25my $dist = DistGen->new( dir => $tmp );
26$dist->add_file( 'bin/nopod.pl', <<'---' );
27#!perl -w
28print "sample script without pod to test manifypods action\n";
29---
30$dist->add_file( 'bin/haspod.pl', <<'---' );
31#!perl -w
32print "Hello, world";
33
34__END__
35
36=head1 NAME
37
38haspod.pl - sample script with pod to test manifypods action
39
40=cut
41---
42$dist->add_file( 'lib/Simple/NoPod.pm', <<'---' );
43package Simple::NoPod;
441;
45---
46$dist->add_file( 'lib/Simple/AllPod.pod', <<'---' );
47=head1 NAME
48
49Simple::AllPod - Pure POD
50
51=head1 AUTHOR
52
53Simple Man <simple@example.com>
54
55=cut
56---
57$dist->regen;
58
59
738349a8 60$dist->chdir_in;
bb4e9162 61
62use File::Spec::Functions qw( catdir );
3143ec60 63my $destdir = catdir($cwd, 't', 'install_test' . $$);
bb4e9162 64
65
66my $mb = Module::Build->new(
67 module_name => $dist->name,
68 install_base => $destdir,
69 scripts => [ File::Spec->catfile( 'bin', 'nopod.pl' ),
70 File::Spec->catfile( 'bin', 'haspod.pl' ) ],
71
72 # need default install paths to ensure manpages & HTML get generated
73 installdirs => 'site',
74 config => {
75 installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'),
76 installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'),
77 installsitehtml1dir => catdir($tmp, 'site', 'html'),
78 installsitehtml3dir => catdir($tmp, 'site', 'html'),
79 }
80
81);
82
83$mb->add_to_cleanup($destdir);
84
85
86is( ref $mb->{properties}->{bindoc_dirs}, 'ARRAY', 'bindoc_dirs' );
87is( ref $mb->{properties}->{libdoc_dirs}, 'ARRAY', 'libdoc_dirs' );
88
89my %man = (
90 sep => $mb->manpage_separator,
91 dir1 => 'man1',
92 dir3 => 'man3',
93 ext1 => $mb->config('man1ext'),
94 ext3 => $mb->config('man3ext'),
95 );
96
97my %distro = (
98 'bin/nopod.pl' => '',
99 'bin/haspod.pl' => "haspod.pl.$man{ext1}",
100 'lib/Simple.pm' => "Simple.$man{ext3}",
101 'lib/Simple/NoPod.pm' => '',
102 'lib/Simple/AllPod.pod' => "Simple$man{sep}AllPod.$man{ext3}",
103 );
104
105%distro = map {$mb->localize_file_path($_), $distro{$_}} keys %distro;
106
d1bd4ef0 107my $lib_path = $mb->localize_dir_path('lib');
108
109# Remove trailing directory delimiter on VMS for compares
110$lib_path =~ s/\]// if $^O eq 'VMS';
111
bb4e9162 112$mb->dispatch('build');
113
114eval {$mb->dispatch('docs')};
115is $@, '';
116
117while (my ($from, $v) = each %distro) {
118 if (!$v) {
119 ok ! $mb->contains_pod($from), "$from should not contain POD";
120 next;
121 }
122
3143ec60 123 my $to = File::Spec->catfile('blib', ($from =~ /^[\.\/\[]*lib/ ? 'libdoc' : 'bindoc'), $v);
bb4e9162 124 ok $mb->contains_pod($from), "$from should contain POD";
125 ok -e $to, "Created $to manpage";
126}
127
128
129$mb->dispatch('install');
130
131while (my ($from, $v) = each %distro) {
132 next unless $v;
d1bd4ef0 133 my $to = File::Spec->catfile
134 ($destdir, 'man', $man{($from =~ /^\Q$lib_path\E/ ? 'dir3' : 'dir1')}, $v);
bb4e9162 135 ok -e $to, "Created $to manpage";
136}
137
138$mb->dispatch('realclean');
139
140
141# revert to a pristine state
bb4e9162 142$dist->remove;
143$dist = DistGen->new( dir => $tmp );
144$dist->regen;
738349a8 145$dist->chdir_in;
bb4e9162 146
147
148my $mb2 = Module::Build->new(
149 module_name => $dist->name,
150 libdoc_dirs => [qw( foo bar baz )],
151);
152
153is( $mb2->{properties}->{libdoc_dirs}->[0], 'foo', 'override libdoc_dirs' );
154
155# Make sure we can find our own action documentation
156ok $mb2->get_action_docs('build');
7253302f 157ok !eval{$mb2->get_action_docs('foo')};
bb4e9162 158
159# Make sure those docs are the correct ones
160foreach ('testcover', 'disttest') {
161 my $docs = $mb2->get_action_docs($_);
162 like $docs, qr/=item $_/;
163 unlike $docs, qr/\n=/, $docs;
164}
165
166
167# cleanup
bb4e9162 168$dist->remove;