This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert utf8decode.t to test.pl
authorNicholas Clark <nick@ccl4.org>
Sat, 12 Mar 2011 11:41:19 +0000 (11:41 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 12 Mar 2011 14:30:09 +0000 (14:30 +0000)
t/op/utf8decode.t

index 7befae2..52dbd58 100644 (file)
@@ -3,6 +3,7 @@
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
+    require './test.pl';
 }
 
 {
 }
 
 {
@@ -10,21 +11,15 @@ BEGIN {
     use bytes;
     my $ordwide = ord($wide);
     printf "# under use bytes ord(v256) = 0x%02x\n", $ordwide;
     use bytes;
     my $ordwide = ord($wide);
     printf "# under use bytes ord(v256) = 0x%02x\n", $ordwide;
-    if ($ordwide == 140) {
-       print "1..0 # Skip: UTF-EBCDIC (not UTF-8) used here\n";
-       exit 0;
-    }
-    elsif ($ordwide != 196) {
+    skip_all('UTF-EBCDIC (not UTF-8) used here') if $ordwide == 140;
+
+    if ($ordwide != 196) {
        printf "# v256 starts with 0x%02x\n", $ordwide;
     }
 }
 
 no utf8;
 
        printf "# v256 starts with 0x%02x\n", $ordwide;
     }
 }
 
 no utf8;
 
-print "1..78\n";
-
-my $test = 1;
-
 # This table is based on Markus Kuhn's UTF-8 Decode Stress Tester,
 # http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt,
 # version dated 2000-09-02.
 # This table is based on Markus Kuhn's UTF-8 Decode Stress Tester,
 # http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt,
 # version dated 2000-09-02.
@@ -143,10 +138,6 @@ __EOMK__
        $@ .= "@_";
     };
 
        $@ .= "@_";
     };
 
-    sub moan {
-       print "$id: @_";
-    }
-
     sub warn_unpack_U {
        $@ = '';
        my @null = unpack('C0U*', $_[0]);
     sub warn_unpack_U {
        $@ = '';
        my @null = unpack('C0U*', $_[0]);
@@ -161,33 +152,27 @@ __EOMK__
            my ($okay, $bytes, $Unicode, $byteslen, $hex, $charslen, $experr) =
                ($2, $3, $4, $5, $6, $7, $8);
            my @hex = split(/:/, $hex);
            my ($okay, $bytes, $Unicode, $byteslen, $hex, $charslen, $experr) =
                ($2, $3, $4, $5, $6, $7, $8);
            my @hex = split(/:/, $hex);
-           unless (@hex == $byteslen) {
-               my $nhex = @hex;
-               moan "amount of hex ($nhex) not equal to byteslen ($byteslen)\n";
-           }
+           is(scalar @hex, $byteslen, 'Amount of hex tallies with byteslen');
            {
                use bytes;
                my $bytesbyteslen = length($bytes);
            {
                use bytes;
                my $bytesbyteslen = length($bytes);
-               unless ($bytesbyteslen == $byteslen) {
-                   moan "bytes length() ($bytesbyteslen) not equal to $byteslen\n";
-               }
+               is($bytesbyteslen, $byteslen,
+                  'bytes length() tallies with byteslen');
            }
            my $warn = warn_unpack_U($bytes);
            if ($okay eq 'y') {
            }
            my $warn = warn_unpack_U($bytes);
            if ($okay eq 'y') {
-               if ($warn) {
-                   moan "unpack('C0U*') false negative\n";
-                   print "not ";
-               }
-           } elsif ($okay eq 'n') {
-               if (!$warn || ($experr ne '' && $warn !~ /$experr/)) {
-                   moan "unpack('C0U*') false positive\n";
-                   print "not ";
-               }
+               is($warn, '', "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");
            }
            }
-           print "ok $test # $id $okay\n";
-           $test++;
        } else {
        } else {
-           moan "unknown format\n";
+           fail("unknown format '$_'");
        }
     }
 }
        }
     }
 }
+
+done_testing();