summaryrefslogtreecommitdiff
path: root/t/op/utf8decode.t
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-03-12 12:26:06 +0000
committerNicholas Clark <nick@ccl4.org>2011-03-12 15:18:15 +0000
commitc03ceae63f8f7a143e71b8f14156e70222a3c47b (patch)
tree555ce73046bb9b053f498b27713407971e938be6 /t/op/utf8decode.t
parente1a6746056fd4573691b7765b9fd94a7996d1320 (diff)
downloadperl-c03ceae63f8f7a143e71b8f14156e70222a3c47b.tar.gz
In utf8decode.t, use warning_is() for the should-not-warn cases.
Move the localised $SIG{__WARN__} handler into the block for the should-warn case, and avoid using $@ as the warnings accumulator. As an expected warning is always provided, eliminate the code for dealing with an unspecified expected warning. The re-ordering allows $id to be a lexical with the same scope as all others derived from the test table lines.
Diffstat (limited to 't/op/utf8decode.t')
-rw-r--r--t/op/utf8decode.t39
1 files changed, 17 insertions, 22 deletions
diff --git a/t/op/utf8decode.t b/t/op/utf8decode.t
index 1e07ca6e9d..a947e96276 100644
--- a/t/op/utf8decode.t
+++ b/t/op/utf8decode.t
@@ -20,39 +20,34 @@ BEGIN {
no utf8;
-my $id;
-
-local $SIG{__WARN__} = sub {
- print "# $id: @_";
- $@ .= "@_";
-};
-
-sub warn_unpack_U {
- $@ = '';
- my @null = unpack('C0U*', $_[0]);
- return $@;
-}
-
foreach (<DATA>) {
if (/^(?:\d+(?:\.\d+)?)\s/ || /^#/) {
# print "# $_\n";
- } elsif (/^(\d+\.\d+\.\d+[bu]?)\s+([yn])\s+([0-9a-f]{1,8}|-)\s+(\d+)\s+([0-9a-f]{2}(?::[0-9a-f]{2})*)(?:\s+((?:\d+|-)(?:\s+(.+))?))?$/) {
- $id = $1;
- my ($okay, $Unicode, $byteslen, $hex, $charslen, $experr) =
- ($2, $3, $4, $5, $6, $7);
+ } elsif (/^(\d+\.\d+\.\d+[bu]?)\s+(y|n)\s+([0-9a-f]{1,8}|-)\s+(\d+)\s+([0-9a-f]{2}(?::[0-9a-f]{2})*)\s+(\d+|-)(?:\s+(.+))?$/) {
+ my ($id, $okay, $Unicode, $byteslen, $hex, $charslen, $experr) =
+ ($1, $2, $3, $4, $5, $6, $7);
my @hex = split(/:/, $hex);
is(scalar @hex, $byteslen, 'Amount of hex tallies with byteslen');
my $octets = join '', map {chr hex $_} @hex;
is(length $octets, $byteslen, 'Number of octets tallies with byteslen');
- my $warn = warn_unpack_U($octets);
if ($okay eq 'y') {
- is($warn, '', "No warnings expected for $id");
+ warning_is(sub {unpack 'C0U*', $octets}, undef,
+ "No warnings expected for $id");
} elsif ($okay ne 'n') {
is($okay, 'n', "Confused test description for $id");
- } elsif($experr) {
- like($warn, qr/$experr/, "Expected warning for $id");
} else {
- isnt($warn, '', "Expect a warning for $id");
+ my $warnings;
+
+ {
+ local $SIG{__WARN__} = sub {
+ print "# $id: @_";
+ $warnings .= "@_";
+ };
+ unpack 'C0U*', $octets;
+ }
+
+ isnt($experr, '', "Expected warning for $id provided");
+ like($warnings, qr/$experr/, "Expected warning for $id seen");
}
} else {
fail("unknown format '$_'");