xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/build_man.t (revision c020cf82e0cc147236f01a8dca7052034cf9d30d)
1#!/usr/bin/perl -w
2
3# Test if MakeMaker declines to build man pages under the right conditions.
4
5BEGIN {
6    unshift @INC, 't/lib';
7}
8
9use strict;
10use Test::More tests => 46;
11
12use File::Spec;
13use File::Temp qw[tempdir];
14use TieOut;
15use MakeMaker::Test::Utils;
16use MakeMaker::Test::Setup::BFD;
17
18use ExtUtils::MakeMaker;
19use ExtUtils::MakeMaker::Config;
20
21# Simulate an installation which has man page generation turned off to
22# ensure these tests will still work.
23$Config{installman3dir} = 'none';
24
25chdir 't';
26perl_lib; # sets $ENV{PERL5LIB} relative to t/
27
28my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
29use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
30chdir $tmpdir;
31
32ok( setup_recurs(), 'setup' );
33END {
34    ok chdir File::Spec->updir, 'chdir updir';
35    ok teardown_recurs(), 'teardown';
36}
37
38ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
39  diag("chdir failed: $!");
40my $README = 'README.pod';
41{ open my $fh, '>', $README or die "$README: $!"; }
42
43ok((my $stdout = tie *STDOUT, 'TieOut'), 'tie stdout');
44
45{
46    local $Config{installman3dir} = File::Spec->catdir(qw(t lib));
47    my $mm = WriteMakefile(
48        NAME            => 'Big::Dummy',
49        VERSION_FROM    => 'lib/Big/Dummy.pm',
50    );
51    my %got = %{ $mm->{MAN3PODS} };
52    # because value too OS-specific
53    my $delete_key = $^O eq 'VMS' ? '[.lib.Big]Dummy.pm' : 'lib/Big/Dummy.pm';
54    ok delete($got{$delete_key}), 'normal man3pod';
55    is_deeply \%got, {}, 'no extra man3pod';
56}
57
58{
59    my $mm = WriteMakefile(
60        NAME            => 'Big::Dummy',
61        VERSION_FROM    => 'lib/Big/Dummy.pm',
62        INSTALLMAN3DIR  => 'none'
63    );
64    is_deeply $mm->{MAN3PODS}, {}, 'suppress man3pod with "none"';
65}
66
67{
68    my $mm = WriteMakefile(
69        NAME            => 'Big::Dummy',
70        VERSION_FROM    => 'lib/Big/Dummy.pm',
71        MAN3PODS        => {}
72    );
73    is_deeply $mm->{MAN3PODS}, {}, 'suppress man3pod with {}';
74}
75
76{
77    my $mm = WriteMakefile(
78        NAME            => 'Big::Dummy',
79        VERSION_FROM    => 'lib/Big/Dummy.pm',
80        MAN3PODS        => { "Foo.pm" => "Foo.1" }
81    );
82    is_deeply $mm->{MAN3PODS}, { "Foo.pm" => "Foo.1" }, 'override man3pod';
83}
84
85unlink $README;
86
87# Check that we find the manage section from the directory
88{
89    local $Config{installman1dir}       = '';
90    local $Config{installman3dir}       = '';
91    local $Config{installsiteman1dir}   = '';
92    local $Config{installsiteman3dir}   = '';
93    local $Config{installvendorman1dir} = '';
94    local $Config{installvendorman3dir} = '';
95    local $Config{usevendorprefix}      = '';
96    local $Config{vendorprefixexp}      = '';
97
98    my $INSTALLDIRS = 'site';
99
100    my $sections_ok = sub {
101        my ( $man1section, $man3section, $m ) = @_;
102        local $Test::Builder::Level = $Test::Builder::Level + 1;
103
104        my $stdout = tie *STDOUT, 'TieOut' or die;
105        my $mm     = WriteMakefile(
106            NAME         => 'Big::Dummy',
107            VERSION_FROM => 'lib/Big/Dummy.pm',
108            INSTALLDIRS  => $INSTALLDIRS,
109        );
110
111        is( $mm->{MAN1SECTION}, $man1section,
112            "$m man1section is $man1section" );
113        is( $mm->{MAN3SECTION}, $man3section,
114            "$m man3section is $man3section" );
115    };
116
117    # Correctly detect known man sections
118    foreach my $s ( '{num}', '{num}p', '{num}pm', qw< l n o C L >, "L{num}", )
119    {
120        ( my $man1section = $s ) =~ s/\{num\}/1/;
121        ( my $man3section = $s ) =~ s/\{num\}/3/;
122
123        $Config{installman1dir}
124            = File::Spec->catdir( 'foo', "man$man1section" );
125        $Config{installman3dir}
126            = File::Spec->catdir( 'foo', "man$man3section" );
127
128        $sections_ok->( $man1section, $man3section, "From main [$s]" );
129    }
130
131    # Ignore unknown man sections
132    foreach my $s ( '', qw< 2 2p 33 >, "C{num}" ) {
133        ( my $man1section = $s ) =~ s/\{num\}/1/;
134        ( my $man3section = $s ) =~ s/\{num\}/3/;
135
136        $Config{installman1dir}
137            = File::Spec->catdir( 'foo', "man$man1section" );
138        $Config{installman3dir}
139            = File::Spec->catdir( 'foo', "man$man3section" );
140
141        $sections_ok->( 1, 3, "Ignore unrecognized [$s]" );
142    }
143
144    # Look in the right installman?dir based on INSTALLDIRS
145    {
146        $Config{installman1dir}     = File::Spec->catdir( 'foo', 'cat1p' );
147        $Config{installman3dir}     = File::Spec->catdir( 'foo', 'cat3p' );
148        $Config{installsiteman1dir} = File::Spec->catdir( 'foo', 'catL' );
149        $Config{installsiteman3dir} = File::Spec->catdir( 'foo', 'catL3' );
150
151        $sections_ok->( 'L', 'L3', "From site" );
152
153        my $installwas = $INSTALLDIRS;
154        $INSTALLDIRS = 'perl';
155        $sections_ok->( '1p', '3p', "From main" );
156        $INSTALLDIRS = $installwas;
157
158    }
159
160    # Set MAN?SECTION in Makefile
161    {
162        $Config{installman1dir} = File::Spec->catdir( 'foo', 'man1pm' );
163        $Config{installman3dir} = File::Spec->catdir( 'foo', 'man3pm' );
164        $Config{installsiteman1dir} = '';
165        $Config{installsiteman3dir} = '';
166
167        my $stdout = tie *STDOUT, 'TieOut' or die;
168        my $mm     = WriteMakefile(
169            NAME         => 'Big::Dummy',
170            VERSION_FROM => 'lib/Big/Dummy.pm',
171            MAN1PODS     => { foo => 'foo.1' },
172            INSTALLDIRS  => $INSTALLDIRS,
173        );
174
175        my $makefile = slurp('Makefile');
176
177        like $makefile, qr/^\QMAN1SECTION = 1pm\E$/xms, "Set MAN1SECTION";
178        like $makefile, qr/^\QMAN3SECTION = 3pm\E$/xms, "Set MAN3SECTION";
179
180        like $makefile, qr/\Q$(POD2MAN) --section=$(MAN1SECTION) \E/,
181            "Set POD2MAN section to \$(MAN1SECTION)";
182        like $makefile, qr/\Q$(POD2MAN) --section=$(MAN3SECTION) \E/,
183            "Set POD2MAN section to \$(MAN3SECTION)";
184    }
185}
186
187