summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/unicode.t
blob: 14a0c8501b09b255a7c533ae1a451e436ef17c82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Test problems in Makefile.PL's and hint files.

BEGIN {
    unshift @INC, 't/lib';
}
chdir 't';

use strict;
use ExtUtils::MM;
use MakeMaker::Test::Utils qw(makefile_name make make_run run hash2files);
use Test::More;
use Config;
use File::Path;
use utf8;
BEGIN {
  plan skip_all => 'Need perlio and perl 5.8+.'
    if "$]" < 5.008 or !$Config{useperlio};
  plan skip_all => 'cross-compiling and make not available'
    if !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'};

  plan tests => 8;
}
use TieOut;

my $MM = bless { DIR => ['.'] }, 'MM';

my $DIRNAME = 'Problem-Module';
my %FILES = (
    'Makefile.PL'   => <<'PL_END',
use ExtUtils::MakeMaker;
use utf8;
WriteMakefile(
    NAME          => 'Problem::Module',
    ABSTRACT_FROM => 'lib/Problem/Module.pm',
    AUTHOR        => q{Danijel Tašov},
    EXE_FILES     => [ qw(bin/probscript) ],
    INSTALLMAN1DIR => "some", # even if disabled in $Config{man1dir}
    MAN1EXT       => 1, # set to 0 if man pages disabled
);
PL_END

    'lib/Problem/Module.pm'  => <<'pm_END',
use utf8;

=pod

=encoding utf8

=head1 NAME

Problem::Module - Danijel Tašov's great new module

=cut

1;
pm_END

    'bin/probscript'  => <<'pl_END',
#!/usr/bin/perl
use utf8;

=encoding utf8

=head1 NAME

文档 - Problem script
pl_END
);

hash2files($DIRNAME, \%FILES);
END {
    ok( chdir File::Spec->updir, 'chdir updir' );
    ok( rmtree($DIRNAME), 'teardown' );
}

ok( chdir $DIRNAME, "chdir'd to $DIRNAME" ) ||
  diag("chdir failed: $!");

if ("$]" >= 5.008) {
  eval { require ExtUtils::MakeMaker::Locale; };
  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 $@;
  note "Locale env vars: " . join(';', map {
    "$_=$ENV{$_}"
  } grep { /LANG|LC/ } keys %ENV) . "\n";
}

# Make sure when Makefile.PL's break, they issue a warning.
# Also make sure Makefile.PL's in subdirs still have '.' in @INC.
{
    my $stdout = tie *STDOUT, 'TieOut' or die;

    my $warning = '';
    local $SIG{__WARN__} = sub { $warning .= join '', @_ };
    $MM->eval_in_subdirs;
    my $warnlines = grep { !/does not map to/ } split "\n", $warning;
    is $warnlines, 0, 'no warning' or diag $warning;

    open my $json_fh, '<:utf8', 'MYMETA.json' or die $!;
    my $json = do { local $/; <$json_fh> };
    close $json_fh;

    no utf8; # leave the data below as bytes and let Encode sort it out
    require Encode;
    my $str = Encode::decode( 'utf8', "Danijel Tašov's" );
    like( $json, qr/$str/, 'utf8 abstract' );

    untie *STDOUT;
}

my $make = make_run();
my $make_out = run($make);
diag $make_out unless is $? >> 8, 0, 'Exit code of make == 0';

my $manfile = File::Spec->catfile(qw(blib man1 probscript.1));
SKIP: {
  skip 'Manpage not generated', 1 unless -f $manfile;
  skip 'Pod::Man >= 2.17 needed', 1 unless do {
    require Pod::Man; $Pod::Man::VERSION >= 2.17;
  };
  open my $man_fh, '<:utf8', $manfile or die "open $manfile: $!";
  my $man = do { local $/; <$man_fh> };
  close $man_fh;

  no utf8; # leave the data below as bytes and let Encode sort it out
  require Encode;
  my $str = Encode::decode( 'utf8', "文档" );
  like( $man, qr/$str/, 'utf8 man-snippet' );
}

$make_out = run("$make realclean");
diag $make_out unless is $? >> 8, 0, 'Exit code of make == 0';

sub makefile_content {
  open my $fh, '<', makefile_name or die;
  return <$fh>;
}