6 no warnings; # Need global -w flag for later tests, but don't want this
8 push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: not perlio\n";
21 my $russki = "koi8r$$";
23 if (open(GRK, ">$grk")) {
24 binmode(GRK, ":bytes");
25 # alpha beta gamma in ISO 8859-7
26 print GRK "\xe1\xe2\xe3";
27 close GRK or die "Could not close: $!";
32 open(my $i,'<:encoding(iso-8859-7)',$grk);
34 open(my $o,'>:utf8',$utf);
36 print $o readline($i);
38 close($o) or die "Could not close: $!";
42 if (open(UTF, "<$utf")) {
43 binmode(UTF, ":bytes");
44 if (ord('A') == 193) { # EBCDIC
45 # alpha beta gamma in UTF-EBCDIC Unicode (0x3b1 0x3b2 0x3b3)
46 print "not " unless <UTF> eq "\xb4\x58\xb4\x59\xb4\x62";
48 # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
49 print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
57 open(my $i,'<:utf8',$utf);
59 open(my $o,'>:encoding(iso-8859-7)',$grk);
61 print $o readline($i);
63 close($o) or die "Could not close: $!";
67 if (open(GRK, "<$grk")) {
68 binmode(GRK, ":bytes");
69 print "not " unless <GRK> eq "\xe1\xe2\xe3";
74 $SIG{__WARN__} = sub {$warn .= $_[0]};
76 if (open(FAIL, ">:encoding(NoneSuch)", $fail1)) {
77 print "not ok 9 # Open should fail\n";
82 print "not ok 10 # warning is undef\n";
83 } elsif ($warn =~ /^Cannot find encoding "NoneSuch" at/) {
86 print "not ok 10 # warning is '$warn'";
89 if (open(RUSSKI, ">$russki")) {
90 print RUSSKI "\x3c\x3f\x78";
91 close RUSSKI or die "Could not close: $!";
92 open(RUSSKI, "$russki");
93 binmode(RUSSKI, ":raw");
95 read(RUSSKI, $buf1, 1);
97 binmode(RUSSKI, ":encoding(koi8-r)");
99 read(RUSSKI, $buf2, 1);
100 my $offset = tell(RUSSKI);
101 if (ord($buf1) == 0x3c &&
102 ord($buf2) == (ord('A') == 193) ? 0x6f : 0x3f &&
106 printf "not ok 11 # [%s] [%s] %d\n",
107 join(" ", unpack("H*", $buf1)),
108 join(" ", unpack("H*", $buf2)), $offset;
112 print "not ok 11 # open failed: $!\n";
117 # Check there is no Use of uninitialized value in concatenation (.) warning
118 # due to the way @latin2iso_num was used to make aliases.
119 if (open(FAIL, ">:encoding(latin42)", $fail2)) {
120 print "not ok 12 # Open should fail\n";
124 if (!defined $warn) {
125 print "not ok 13 # warning is undef\n";
126 } elsif ($warn =~ /^Cannot find encoding "latin42" at.*line \d+\.$/) {
129 print "not ok 13 # warning is: \n";
135 unlink($grk, $utf, $fail1, $fail2, $russki);