Commit | Line | Data |
bb4e9162 |
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 = File::Spec->catdir( $cwd, 't', '_tmp' ); |
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 | $mb->dispatch('build'); |
106 | |
107 | eval {$mb->dispatch('docs')}; |
108 | is $@, ''; |
109 | |
110 | while (my ($from, $v) = each %distro) { |
111 | if (!$v) { |
112 | ok ! $mb->contains_pod($from), "$from should not contain POD"; |
113 | next; |
114 | } |
115 | |
116 | my $to = File::Spec->catfile('blib', ($from =~ /^lib/ ? 'libdoc' : 'bindoc'), $v); |
117 | ok $mb->contains_pod($from), "$from should contain POD"; |
118 | ok -e $to, "Created $to manpage"; |
119 | } |
120 | |
121 | |
122 | $mb->dispatch('install'); |
123 | |
124 | while (my ($from, $v) = each %distro) { |
125 | next unless $v; |
126 | my $to = File::Spec->catfile($destdir, 'man', $man{($from =~ /^lib/ ? 'dir3' : 'dir1')}, $v); |
127 | ok -e $to, "Created $to manpage"; |
128 | } |
129 | |
130 | $mb->dispatch('realclean'); |
131 | |
132 | |
133 | # revert to a pristine state |
134 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
135 | $dist->remove; |
136 | $dist = DistGen->new( dir => $tmp ); |
137 | $dist->regen; |
138 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
139 | |
140 | |
141 | my $mb2 = Module::Build->new( |
142 | module_name => $dist->name, |
143 | libdoc_dirs => [qw( foo bar baz )], |
144 | ); |
145 | |
146 | is( $mb2->{properties}->{libdoc_dirs}->[0], 'foo', 'override libdoc_dirs' ); |
147 | |
148 | # Make sure we can find our own action documentation |
149 | ok $mb2->get_action_docs('build'); |
7253302f |
150 | ok !eval{$mb2->get_action_docs('foo')}; |
bb4e9162 |
151 | |
152 | # Make sure those docs are the correct ones |
153 | foreach ('testcover', 'disttest') { |
154 | my $docs = $mb2->get_action_docs($_); |
155 | like $docs, qr/=item $_/; |
156 | unlike $docs, qr/\n=/, $docs; |
157 | } |
158 | |
159 | |
160 | # cleanup |
161 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
162 | $dist->remove; |
163 | |
164 | use File::Path; |
165 | rmtree( $tmp ); |