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 => 50; 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; 48 { 49 # suppress noisy & unnecessary "WARNING: Older versions of ExtUtils::MakeMaker may errantly install README.pod..." 50 my @warnings = (); 51 local $SIG{__WARN__} = sub { push @warnings, shift; }; 52 $mm = WriteMakefile( 53 NAME => 'Big::Dummy', 54 VERSION_FROM => 'lib/Big/Dummy.pm', 55 ); 56 # verify that suppressed warnings are present 57 isnt (scalar(@warnings), 0); 58 if (scalar(@warnings)) { 59 note (sprintf('suppressed warnings: [ "%s" ]', do { my $s = join(q/" , "/, @warnings); $s =~ s/([^[:print:]])/sprintf('\x{%x}', ord($1))/egmsx; $s; })); 60 } 61 } 62 my %got = %{ $mm->{MAN3PODS} }; 63 # because value too OS-specific 64 my $delete_key = $^O eq 'VMS' ? '[.lib.Big]Dummy.pm' : 'lib/Big/Dummy.pm'; 65 ok delete($got{$delete_key}), 'normal man3pod'; 66 is_deeply \%got, {}, 'no extra man3pod'; 67} 68 69{ 70 my $mm; 71 { 72 # suppress noisy & unnecessary "WARNING: Older versions of ExtUtils::MakeMaker may errantly install README.pod..." 73 my @warnings = (); 74 local $SIG{__WARN__} = sub { push @warnings, shift; }; 75 $mm = WriteMakefile( 76 NAME => 'Big::Dummy', 77 VERSION_FROM => 'lib/Big/Dummy.pm', 78 INSTALLMAN3DIR => 'none' 79 ); 80 # verify that suppressed warnings are present 81 isnt (scalar(@warnings), 0); 82 if (scalar(@warnings)) { 83 note (sprintf('suppressed warnings: [ "%s" ]', do { my $s = join(q/" , "/, @warnings); $s =~ s/([^[:print:]])/sprintf('\x{%x}', ord($1))/egmsx; $s; })); 84 } 85 } 86 is_deeply $mm->{MAN3PODS}, {}, 'suppress man3pod with "none"'; 87} 88 89{ 90 my $mm; 91 { 92 # suppress noisy & unnecessary "WARNING: Older versions of ExtUtils::MakeMaker may errantly install README.pod..." 93 my @warnings = (); 94 local $SIG{__WARN__} = sub { push @warnings, shift; }; 95 $mm = WriteMakefile( 96 NAME => 'Big::Dummy', 97 VERSION_FROM => 'lib/Big/Dummy.pm', 98 MAN3PODS => {} 99 ); 100 # verify that suppressed warnings are present 101 isnt (scalar(@warnings), 0); 102 if (scalar(@warnings)) { 103 note (sprintf('suppressed warnings: [ "%s" ]', do { my $s = join(q/" , "/, @warnings); $s =~ s/([^[:print:]])/sprintf('\x{%x}', ord($1))/egmsx; $s; })); 104 } 105 } 106 is_deeply $mm->{MAN3PODS}, {}, 'suppress man3pod with {}'; 107} 108 109{ 110 my $mm; 111 { 112 # suppress noisy & unnecessary "WARNING: Older versions of ExtUtils::MakeMaker may errantly install README.pod..." 113 my @warnings = (); 114 local $SIG{__WARN__} = sub { push @warnings, shift; }; 115 $mm = WriteMakefile( 116 NAME => 'Big::Dummy', 117 VERSION_FROM => 'lib/Big/Dummy.pm', 118 MAN3PODS => { "Foo.pm" => "Foo.1" } 119 ); 120 # verify that suppressed warnings are present 121 isnt (scalar(@warnings), 0); 122 if (scalar(@warnings)) { 123 note (sprintf('suppressed warnings: [ "%s" ]', do { my $s = join(q/" , "/, @warnings); $s =~ s/([^[:print:]])/sprintf('\x{%x}', ord($1))/egmsx; $s; })); 124 } 125 } 126 is_deeply $mm->{MAN3PODS}, { "Foo.pm" => "Foo.1" }, 'override man3pod'; 127} 128 129unlink $README; 130 131# Check that we find the manage section from the directory 132{ 133 local $Config{installman1dir} = ''; 134 local $Config{installman3dir} = ''; 135 local $Config{installsiteman1dir} = ''; 136 local $Config{installsiteman3dir} = ''; 137 local $Config{installvendorman1dir} = ''; 138 local $Config{installvendorman3dir} = ''; 139 local $Config{usevendorprefix} = ''; 140 local $Config{vendorprefixexp} = ''; 141 142 my $INSTALLDIRS = 'site'; 143 144 my $sections_ok = sub { 145 my ( $man1section, $man3section, $m ) = @_; 146 local $Test::Builder::Level = $Test::Builder::Level + 1; 147 148 my $stdout = tie *STDOUT, 'TieOut' or die; 149 my $mm = WriteMakefile( 150 NAME => 'Big::Dummy', 151 VERSION_FROM => 'lib/Big/Dummy.pm', 152 INSTALLDIRS => $INSTALLDIRS, 153 ); 154 155 is( $mm->{MAN1SECTION}, $man1section, 156 "$m man1section is $man1section" ); 157 is( $mm->{MAN3SECTION}, $man3section, 158 "$m man3section is $man3section" ); 159 }; 160 161 # Correctly detect known man sections 162 foreach my $s ( '{num}', '{num}p', '{num}pm', qw< l n o C L >, "L{num}", ) 163 { 164 ( my $man1section = $s ) =~ s/\{num\}/1/; 165 ( my $man3section = $s ) =~ s/\{num\}/3/; 166 167 $Config{installman1dir} 168 = File::Spec->catdir( 'foo', "man$man1section" ); 169 $Config{installman3dir} 170 = File::Spec->catdir( 'foo', "man$man3section" ); 171 172 $sections_ok->( $man1section, $man3section, "From main [$s]" ); 173 } 174 175 # Ignore unknown man sections 176 foreach my $s ( '', qw< 2 2p 33 >, "C{num}" ) { 177 ( my $man1section = $s ) =~ s/\{num\}/1/; 178 ( my $man3section = $s ) =~ s/\{num\}/3/; 179 180 $Config{installman1dir} 181 = File::Spec->catdir( 'foo', "man$man1section" ); 182 $Config{installman3dir} 183 = File::Spec->catdir( 'foo', "man$man3section" ); 184 185 $sections_ok->( 1, 3, "Ignore unrecognized [$s]" ); 186 } 187 188 # Look in the right installman?dir based on INSTALLDIRS 189 { 190 $Config{installman1dir} = File::Spec->catdir( 'foo', 'cat1p' ); 191 $Config{installman3dir} = File::Spec->catdir( 'foo', 'cat3p' ); 192 $Config{installsiteman1dir} = File::Spec->catdir( 'foo', 'catL' ); 193 $Config{installsiteman3dir} = File::Spec->catdir( 'foo', 'catL3' ); 194 195 $sections_ok->( 'L', 'L3', "From site" ); 196 197 my $installwas = $INSTALLDIRS; 198 $INSTALLDIRS = 'perl'; 199 $sections_ok->( '1p', '3p', "From main" ); 200 $INSTALLDIRS = $installwas; 201 202 } 203 204 # Set MAN?SECTION in Makefile 205 { 206 $Config{installman1dir} = File::Spec->catdir( 'foo', 'man1pm' ); 207 $Config{installman3dir} = File::Spec->catdir( 'foo', 'man3pm' ); 208 $Config{installsiteman1dir} = ''; 209 $Config{installsiteman3dir} = ''; 210 211 my $stdout = tie *STDOUT, 'TieOut' or die; 212 my $mm = WriteMakefile( 213 NAME => 'Big::Dummy', 214 VERSION_FROM => 'lib/Big/Dummy.pm', 215 MAN1PODS => { foo => 'foo.1' }, 216 INSTALLDIRS => $INSTALLDIRS, 217 ); 218 219 my $makefile = slurp($mm->{MAKEFILE}); 220 221 like $makefile, qr/\QMAN1SECTION = 1pm\E/xms, "Set MAN1SECTION"; 222 like $makefile, qr/\QMAN3SECTION = 3pm\E/xms, "Set MAN3SECTION"; 223 224 like $makefile, qr/\Q$(POD2MAN) --section=$(MAN1SECTION) \E/, 225 "Set POD2MAN section to \$(MAN1SECTION)"; 226 like $makefile, qr/\Q$(POD2MAN) --section=$(MAN3SECTION) \E/, 227 "Set POD2MAN section to \$(MAN3SECTION)"; 228 } 229} 230