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