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
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest;
6 use Module::Build;
7 use Module::Build::ConfigData;
8
9 if ( Module::Build::ConfigData->feature('manpage_support') ) {
10   plan tests => 22;
11 } else {
12   plan skip_all => 'manpage_support feature is not enabled';
13 }
14 ensure_blib('Module::Build');
15
16
17 #########################
18
19
20 use Cwd ();
21 my $cwd = Cwd::cwd;
22 my $tmp = MBTest->tmpdir;
23
24 use DistGen;
25 my $dist = DistGen->new( dir => $tmp );
26 $dist->add_file( 'bin/nopod.pl', <<'---' );
27 #!perl -w
28 print "sample script without pod to test manifypods action\n";
29 ---
30 $dist->add_file( 'bin/haspod.pl', <<'---' );
31 #!perl -w
32 print "Hello, world";
33
34 __END__
35
36 =head1 NAME
37
38 haspod.pl - sample script with pod to test manifypods action
39
40 =cut
41 ---
42 $dist->add_file( 'lib/Simple/NoPod.pm', <<'---' );
43 package Simple::NoPod;
44 1;
45 ---
46 $dist->add_file( 'lib/Simple/AllPod.pod', <<'---' );
47 =head1 NAME
48
49 Simple::AllPod - Pure POD
50
51 =head1 AUTHOR
52
53 Simple Man <simple@example.com>
54
55 =cut
56 ---
57 $dist->regen;
58
59
60 $dist->chdir_in;
61
62 use File::Spec::Functions qw( catdir );
63 my $destdir = catdir($cwd, 't', 'install_test' . $$);
64
65
66 my $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
86 is( ref $mb->{properties}->{bindoc_dirs}, 'ARRAY', 'bindoc_dirs' );
87 is( ref $mb->{properties}->{libdoc_dirs}, 'ARRAY', 'libdoc_dirs' );
88
89 my %man = (
90            sep  => $mb->manpage_separator,
91            dir1 => 'man1',
92            dir3 => 'man3',
93            ext1 => $mb->config('man1ext'),
94            ext3 => $mb->config('man3ext'),
95           );
96
97 my %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
107 my $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
112 $mb->dispatch('build');
113
114 eval {$mb->dispatch('docs')};
115 is $@, '';
116
117 while (my ($from, $v) = each %distro) {
118   if (!$v) {
119     ok ! $mb->contains_pod($from), "$from should not contain POD";
120     next;
121   }
122   
123   my $to = File::Spec->catfile('blib', ($from =~ /^[\.\/\[]*lib/ ? 'libdoc' : 'bindoc'), $v);
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
131 while (my ($from, $v) = each %distro) {
132   next unless $v;
133   my $to = File::Spec->catfile
134      ($destdir, 'man', $man{($from =~ /^\Q$lib_path\E/ ? 'dir3' : 'dir1')}, $v);
135   ok -e $to, "Created $to manpage";
136 }
137
138 $mb->dispatch('realclean');
139
140
141 # revert to a pristine state
142 $dist->remove;
143 $dist = DistGen->new( dir => $tmp );
144 $dist->regen;
145 $dist->chdir_in;
146
147
148 my $mb2 = Module::Build->new(
149   module_name => $dist->name,
150   libdoc_dirs => [qw( foo bar baz )],
151 );
152
153 is( $mb2->{properties}->{libdoc_dirs}->[0], 'foo', 'override libdoc_dirs' );
154
155 # Make sure we can find our own action documentation
156 ok  $mb2->get_action_docs('build');
157 ok !eval{$mb2->get_action_docs('foo')};
158
159 # Make sure those docs are the correct ones
160 foreach ('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
168 $dist->remove;