This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Encode: sync with CPAN version 3.18
[perl5.git] / cpan / Encode / t / enc_module.t
CommitLineData
d26b5e1d 1# $Id: enc_module.t,v 2.6 2022/04/07 03:06:40 dankogai Exp $
6be7c101
JH
2# This file is in euc-jp
3BEGIN {
4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
7 exit 0;
8 }
9 unless (find PerlIO::Layer 'perlio') {
d1256cb1
RGS
10 print "1..0 # Skip: PerlIO was not built\n";
11 exit 0;
6be7c101 12 }
05ef2f67 13 if (defined ${^UNICODE} and ${^UNICODE} != 0){
d1256cb1
RGS
14 print "1..0 # Skip: \${^UNICODE} == ${^UNICODE}\n";
15 exit 0;
05ef2f67 16 }
6be7c101 17 if (ord("A") == 193) {
15f5e486 18 print "1..0 # Skip: encoding pragma does not support EBCDIC platforms\n";
d1256cb1 19 exit(0);
6be7c101 20 }
15f5e486 21 if ($] >= 5.025 and !$Config{usecperl}) {
ab5cf2ea 22 print "1..0 # Skip: encoding pragma not supported in Perl 5.25 or later\n";
a15a3d9b
FC
23 exit(0);
24 }
6be7c101 25}
0f29a567 26use lib qw(t ext/Encode/t ../ext/Encode/t); # latter 2 for perl core
6be7c101 27use Mod_EUCJP;
64a9a3c0 28no warnings "deprecated";
6be7c101
JH
29use encoding "euc-jp";
30use Test::More tests => 3;
31use File::Basename;
32use File::Spec;
33use File::Compare qw(compare_text);
34
8676e7d3 35my $DEBUG = shift || 0;
6be7c101
JH
36my $dir = dirname(__FILE__);
37my $file0 = File::Spec->catfile($dir,"enc_module.enc");
38my $file1 = File::Spec->catfile($dir,"$$.enc");
39
40my $obj = Mod_EUCJP->new;
8676e7d3
JH
41local $SIG{__WARN__} = sub{ $DEBUG and print STDERR @_ };
42# to silence reopening STD(IN|OUT) w/o closing unless $DEBUG
6be7c101
JH
43
44open STDOUT, ">", $file1 or die "$file1:$!";
45print $obj->str, "\n";
46$obj->set("¥Æ¥¹¥Èʸ»úÎó");
47print $obj->str, "\n";
6be7c101 48
196fd07f 49# Please do not move this to a point after the comparison -- Craig Berry
bedba681
JH
50# and "unless $^O eq 'freebsd'" is needed for FreeBSD (toy-)?thread
51# -- dankogai
196fd07f
CB
52close STDOUT unless $^O eq 'freebsd';
53
6be7c101
JH
54my $cmp = compare_text($file0, $file1);
55is($cmp, 0, "encoding vs. STDOUT");
6be7c101
JH
56
57my @cmp = qw/½é´üʸ»úÎó ¥Æ¥¹¥Èʸ»úÎó/;
58open STDIN, "<", $file0 or die "$file0:$!";
59$obj = Mod_EUCJP->new;
60my $i = 0;
61while(<STDIN>){
0afd3698 62 s/\r?\n\z//;
6be7c101
JH
63 is ($cmp[$i++], $_, "encoding vs. STDIN - $i");
64}
65
9735c3fc 66unlink $file1 unless $cmp;
6be7c101
JH
67__END__
68