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