In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/5c7da53cc0fa3db2a0adc93851fae037de310655?hp=bc4c40f2eb948644a92225726b3cab20f98488f7>
- Log ----------------------------------------------------------------- commit 5c7da53cc0fa3db2a0adc93851fae037de310655 Author: Nicholas Clark <[email protected]> Date: Fri Oct 9 11:03:41 2009 +0200 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. M t/comp/utf.t commit 912292233dcfb4a5bc3775a4a9900b2fd8246607 Author: Nicholas Clark <[email protected]> Date: Fri Oct 9 10:52:43 2009 +0200 Print the encoding name as part of the test, rather than on a separate line. M t/comp/require.t commit b6357110eade0edcc5ab86b05942421c02c9b897 Author: Nicholas Clark <[email protected]> Date: Fri Oct 9 10:48:57 2009 +0200 Refactor bytes_to_utf16() into a more generic routine that also handles UTF-8 Remove the direct code for testing UTF-8, calling bytes_to_utf() from a loop for all 3 tested encodings. M t/comp/require.t commit 386ac4df40d7d0f9109485405028e505ec8f11d7 Author: Nicholas Clark <[email protected]> Date: Fri Oct 9 10:18:37 2009 +0200 Replace longhand invocations of test() with 3 nested loops. M t/comp/utf.t commit 9ef34c7a630343a264334ea417c9831f03721082 Author: Nicholas Clark <[email protected]> Date: Fri Oct 9 10:16:15 2009 +0200 Test utf8 with BOMs, like we already test utf16be and utf16le. M t/comp/utf.t commit f2a3bb21a1100f37023e2a89faccca76359cd969 Author: Nicholas Clark <[email protected]> Date: Thu Oct 8 21:58:17 2009 +0200 Move tests for use for "new style version numbers" to use.t from require.t M t/comp/require.t M t/comp/use.t ----------------------------------------------------------------------- Summary of changes: t/comp/require.t | 33 ++++++++++++--------------- t/comp/use.t | 10 +++++++- t/comp/utf.t | 65 ++++++++++++++++++++---------------------------------- 3 files changed, 48 insertions(+), 60 deletions(-) diff --git a/t/comp/require.t b/t/comp/require.t index 0a2293b..e7d0da6 100644 --- a/t/comp/require.t +++ b/t/comp/require.t @@ -22,7 +22,7 @@ krunch.pm krunch.pmc whap.pm whap.pmc); my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0; my $Is_UTF8 = (${^OPEN} || "") =~ /:utf8/; -my $total_tests = 49; +my $total_tests = 47; if ($Is_EBCDIC || $Is_UTF8) { $total_tests -= 3; } print "1..$total_tests\n"; @@ -62,14 +62,6 @@ eval { require 10.0.2; }; print "# $...@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/; print "ok ",$i++,"\n"; -eval q{ use v5.5.630; }; -print "# $...@\nnot " if $@; -print "ok ",$i++,"\n"; - -eval q{ use 10.0.2; }; -print "# $...@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/; -print "ok ",$i++,"\n"; - my $ver = 5.005_63; eval { require $ver; }; print "# $...@\nnot " if $@; @@ -266,17 +258,22 @@ EOT if ($Is_EBCDIC || $Is_UTF8) { exit; } -my $utf8 = pack "C0U", 0xFEFF; - -$i++; do_require(qq(${utf8}print "ok $i\n"; 1;\n)); - -sub bytes_to_utf16 { - my $utf16 = pack("$_[0]*", unpack("C*", $_[1])); - return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16; +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; } -$i++; do_require(bytes_to_utf16('n', qq(print "ok $i\\n"; 1;\n), 1)); # BE -$i++; do_require(bytes_to_utf16('v', qq(print "ok $i\\n"; 1;\n), 1)); # LE +foreach (sort keys %templates) { + $i++; do_require(bytes_to_utf($_, qq(print "ok $i # $_\\n"; 1;\n), 1)); +} END { foreach my $file (@fjles_to_delete) { diff --git a/t/comp/use.t b/t/comp/use.t index a7ecda8..ba7d587 100755 --- a/t/comp/use.t +++ b/t/comp/use.t @@ -6,7 +6,7 @@ BEGIN { $INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm } -print "1..68\n"; +print "1..70\n"; # Can't require test.pl, as we're testing the use/require mechanism here. @@ -62,6 +62,14 @@ sub isnt ($$;$) { _ok ('isnt', @_); } +# new style version numbers + +eval q{ use v5.5.630; }; +is ($@, ''); + +eval q{ use 10.0.2; }; +like ($@, qr/^Perl v10\.0\.2 required/); + eval "use 5.000"; # implicit semicolon is ($@, ''); diff --git a/t/comp/utf.t b/t/comp/utf.t index 6421f93..0d340f6 100644 --- a/t/comp/utf.t +++ b/t/comp/utf.t @@ -1,56 +1,39 @@ #!./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 => 15); +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); } -test("utf16le", 123, 1); -test("utf16le", 1234, 1); -test("utf16le", 12345, 1); -test("utf16be", 123, 1); -test("utf16be", 1234, 1); -test("utf16be", 12345, 1); -test("utf8", 123, 1); -test("utf8", 1234, 1); -test("utf8", 12345, 1); - -test("utf16le", 123, 0); -test("utf16le", 1234, 0); -test("utf16le", 12345, 0); -test("utf16be", 123, 0); -test("utf16be", 1234, 0); -test("utf16be", 12345, 0); +for my $bom (0, 1) { + for my $enc (qw(utf16le utf16be utf8)) { + for my $value (123, 1234, 12345) { + test($enc, $value, $bom); + } + } +} END { 1 while unlink "utf$$.pl"; -- Perl5 Master Repository
