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