#!/usr/bin/perl use strict; use warnings; use Test::More(tests => 14); use Encode; binmode STDOUT, ':utf8'; # If you have a UTF-8 terminal my $workdir = "./tt"; mkdir $workdir; # Let it fail if it already exists # This is a byte sequence, not tagged as utf8 to perl # so theoretically perl should consider it to be in the local # encoding, normally latin1 my $place = "M\xc3\xbcnchen"; test_placename($workdir, $place); # Turn on the flag for this scalar. Since we pre-arranged for # the byte sequence of this scalar to contain valid utf8, this # scalar is now a valid perl unicode string. Encode::_utf8_on($place); test_placename($workdir, $place); exit 0; sub test_placename { my $workdir = shift; my $place = shift; my $fname = "$workdir/$place"; my $fh; ok(!-f $fname, "$fname doesn't already exist"); open($fh, ">", $fname) or die "Can't create $fname : $!"; close $fh; ok(1, "can create $fname with 'open'/close"); ok(-f $fname, "can find $fname with -f"); my @files = glob("$workdir/$place"); is(scalar @files, 1, "One file in dir via glob"); is($files[0], $fname, "and it's what we expect"); my $dh; opendir $dh, $workdir or die "Can't open $workdir : $!"; @files = grep { !/^\./ } readdir $dh; closedir $dh; is(scalar @files, 1, "One file in dir via readdir"); is($files[0], $place, "and it's what we expect"); my $num_files_unlinked = unlink($fname); is($num_files_unlinked, 1, "can remove $fname"); }