summaryrefslogtreecommitdiff
path: root/t/comp/utf.t
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-10-09 11:03:41 +0200
committerNicholas Clark <nick@ccl4.org>2009-10-09 11:03:41 +0200
commit5c7da53cc0fa3db2a0adc93851fae037de310655 (patch)
tree3de908643b197f7194da9cc1d7f510bb94c95489 /t/comp/utf.t
parent912292233dcfb4a5bc3775a4a9900b2fd8246607 (diff)
downloadperl-5c7da53cc0fa3db2a0adc93851fae037de310655.tar.gz
Use require.t's bytes_to_utf() in place of PerlIO layers in utf.t
This avoids it needing to load Config, and means it can by run with miniperl, and PerlIO-disabled perls.
Diffstat (limited to 't/comp/utf.t')
-rw-r--r--t/comp/utf.t40
1 files changed, 16 insertions, 24 deletions
diff --git a/t/comp/utf.t b/t/comp/utf.t
index 904c8a3787..0d340f6f98 100644
--- a/t/comp/utf.t
+++ b/t/comp/utf.t
@@ -1,36 +1,28 @@
#!./perl
-BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
- unless (find PerlIO::Layer 'perlio') {
- print "1..0 # Skip: not perlio\n";
- exit 0;
- }
- if ($ENV{PERL_CORE_MINITEST}) {
- print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
- exit 0;
- }
- require Config; import Config;
- if ($Config{'extensions'} !~ /\bEncode\b/) {
- print "1..0 # Skip: Encode was not built\n";
- exit 0;
- }
-}
-
BEGIN { require "./test.pl"; }
plan(tests => 18);
-my $BOM = chr(0xFEFF);
+my %templates = (
+ utf8 => 'C0U',
+ utf16be => 'n',
+ utf16le => 'v',
+ );
+
+sub bytes_to_utf {
+ my ($enc, $content, $do_bom) = @_;
+ my $template = $templates{$enc};
+ die "Unsupported encoding $enc" unless $template;
+ return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "C*", $content;
+}
sub test {
my ($enc, $tag, $bom) = @_;
- open(UTF_PL, ">:raw:encoding($enc)", "utf$$.pl")
- or die "utf.pl($enc,$tag,$bom): $!";
- print UTF_PL $BOM if $bom;
- print UTF_PL "$tag\n";
- close(UTF_PL);
+ open my $fh, ">", "utf$$.pl" or die "utf.pl: $!";
+ binmode $fh;
+ print $fh bytes_to_utf($enc, "$tag\n", $bom);
+ close $fh or die $!;
my $got = do "./utf$$.pl";
is($got, $tag);
}