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