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