1# Test problems in Makefile.PL's and hint files. 2 3BEGIN { 4 unshift @INC, 't/lib'; 5} 6chdir 't'; 7 8use strict; 9use warnings; 10use ExtUtils::MM; 11use MakeMaker::Test::Utils qw(makefile_name make make_run run hash2files); 12use Test::More; 13use Config; 14use File::Path; 15use utf8; 16BEGIN { 17 plan skip_all => 'Need perlio and perl 5.8+.' 18 if "$]" < 5.008 or !$Config{useperlio}; 19 plan skip_all => 'cross-compiling and make not available' 20 if !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'}; 21 22 plan tests => 8; 23} 24use TieOut; 25 26my $MM = bless { DIR => ['.'] }, 'MM'; 27 28my $DIRNAME = 'Problem-Module'; 29my %FILES = ( 30 'Makefile.PL' => <<'PL_END', 31use ExtUtils::MakeMaker; 32use utf8; 33WriteMakefile( 34 NAME => 'Problem::Module', 35 ABSTRACT_FROM => 'lib/Problem/Module.pm', 36 AUTHOR => q{Danijel Tašov}, 37 EXE_FILES => [ qw(bin/probscript) ], 38 INSTALLMAN1DIR => "some", # even if disabled in $Config{man1dir} 39 MAN1EXT => 1, # set to 0 if man pages disabled 40); 41PL_END 42 43 'lib/Problem/Module.pm' => <<'pm_END', 44use utf8; 45 46=pod 47 48=encoding utf8 49 50=head1 NAME 51 52Problem::Module - Danijel Tašov's great new module 53 54=cut 55 561; 57pm_END 58 59 'bin/probscript' => <<'pl_END', 60#!/usr/bin/perl 61use utf8; 62 63=encoding utf8 64 65=head1 NAME 66 67文档 - Problem script 68pl_END 69); 70 71hash2files($DIRNAME, \%FILES); 72END { 73 ok( chdir File::Spec->updir, 'chdir updir' ); 74 ok( rmtree($DIRNAME), 'teardown' ); 75} 76 77ok( chdir $DIRNAME, "chdir'd to $DIRNAME" ) || 78 diag("chdir failed: $!"); 79 80if ("$]" >= 5.008) { 81 eval { require ExtUtils::MakeMaker::Locale; }; 82 note "ExtUtils::MakeMaker::Locale vars: $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE;$ExtUtils::MakeMaker::Locale::ENCODING_LOCALE_FS;$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_IN;$ExtUtils::MakeMaker::Locale::ENCODING_CONSOLE_OUT\n" unless $@; 83 note "Locale env vars: " . join(';', map { 84 "$_=$ENV{$_}" 85 } grep { /LANG|LC/ } keys %ENV) . "\n"; 86} 87 88# Make sure when Makefile.PL's break, they issue a warning. 89# Also make sure Makefile.PL's in subdirs still have '.' in @INC. 90{ 91 my $stdout = tie *STDOUT, 'TieOut' or die; 92 93 my $warning = ''; 94 local $SIG{__WARN__} = sub { $warning .= join '', @_ }; 95 $MM->eval_in_subdirs; 96 my $warnlines = grep { !/does not map to/ } split "\n", $warning; 97 is $warnlines, 0, 'no warning' or diag $warning; 98 99 open my $json_fh, '<:utf8', 'MYMETA.json' or die $!; 100 my $json = do { local $/; <$json_fh> }; 101 close $json_fh; 102 103 no utf8; # leave the data below as bytes and let Encode sort it out 104 require Encode; 105 my $str = Encode::decode( 'utf8', "Danijel Tašov's" ); 106 like( $json, qr/$str/, 'utf8 abstract' ); 107 108 untie *STDOUT; 109} 110 111my $make = make_run(); 112my $make_out = run($make); 113diag $make_out unless is $? >> 8, 0, 'Exit code of make == 0'; 114 115my $manfile = File::Spec->catfile(qw(blib man1 probscript.1)); 116SKIP: { 117 skip 'Manpage not generated', 1 unless -f $manfile; 118 skip 'Pod::Man >= 2.17 needed', 1 unless do { 119 require Pod::Man; $Pod::Man::VERSION >= 2.17; 120 }; 121 open my $man_fh, '<:utf8', $manfile or die "open $manfile: $!"; 122 my $man = do { local $/; <$man_fh> }; 123 close $man_fh; 124 125 no utf8; # leave the data below as bytes and let Encode sort it out 126 require Encode; 127 my $str = Encode::decode( 'utf8', "文档" ); 128 like( $man, qr/$str/, 'utf8 man-snippet' ); 129} 130 131$make_out = run("$make realclean"); 132diag $make_out unless is $? >> 8, 0, 'Exit code of make == 0'; 133 134sub makefile_content { 135 open my $fh, '<', makefile_name or die; 136 return <$fh>; 137} 138