Skip to content

Commit

Permalink
test and eliminate unicode warning Perl-Toolchain-Gang#22
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab authored and mohawk2 committed Jul 28, 2014
1 parent e4d06c0 commit 8d3b79b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ExtUtils/MakeMaker.pm
Expand Up @@ -1171,7 +1171,7 @@ sub flush {
print "Writing $finalname for $self->{NAME}\n";

unlink($finalname, "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : ());
open(my $fh,">", "MakeMaker.tmp")
open(my $fh,">:utf8", "MakeMaker.tmp")
or die "Unable to open MakeMaker.tmp: $!";

for my $chunk (@{$self->{RESULT}}) {
Expand Down
58 changes: 58 additions & 0 deletions t/lib/MakeMaker/Test/Setup/Unicode.pm
@@ -0,0 +1,58 @@
package MakeMaker::Test::Setup::Unicode;

@ISA = qw(Exporter);
require Exporter;
@EXPORT = qw(setup_recurs teardown_recurs);

use strict;
use File::Path;
use File::Basename;
use MakeMaker::Test::Utils;
use utf8;

my %Files = (
'Problem-Module/Makefile.PL' => <<'END',
use ExtUtils::MakeMaker;
use utf8;
WriteMakefile(
NAME => 'Problem::Module',
AUTHOR => q{Danijel Tašov},
);
END

);


sub setup_recurs {
while(my($file, $text) = each %Files) {
# Convert to a relative, native file path.
$file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file);

my $dir = dirname($file);
mkpath $dir;
open(FILE, ">:utf8", $file) || die "Can't create $file: $!";
print FILE $text;
close FILE;

# ensure file at least 1 second old for makes that assume
# files with the same time are out of date.
my $time = calibrate_mtime();
utime $time, $time - 1, $file;
}

return 1;
}

sub teardown_recurs {
foreach my $file (keys %Files) {
my $dir = dirname($file);
if( -e $dir ) {
rmtree($dir) || return;
}
}
return 1;
}


1;
37 changes: 37 additions & 0 deletions t/unicode.t
@@ -0,0 +1,37 @@
# Test problems in Makefile.PL's and hint files.

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

use strict;
use Test::More tests => 5;
use ExtUtils::MM;
use MakeMaker::Test::Setup::Unicode;
use TieOut;

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

ok( setup_recurs(), 'setup' );
END {
ok( chdir File::Spec->updir );
ok( teardown_recurs(), 'teardown' );
}

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


# 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;
is $warning, '', 'no warning';

untie *STDOUT;
}

0 comments on commit 8d3b79b

Please sign in to comment.