Sync up with Digest-MD5-2.37 from CPAN
[p5sagit/p5-mst-13.2.git] / ext / Digest / MD5 / t / files.t
index 5fcb035..4c41b32 100644 (file)
@@ -10,25 +10,37 @@ print "1..5\n";
 use strict;
 use Digest::MD5 qw(md5 md5_hex md5_base64);
 
-#
-# This is the output of: 'md5sum Changes README MD5.pm MD5.xs rfc1321.txt'
-#
-my $EXPECT;
+# To update the EBCDIC section even on a Latin 1 platform,
+# run this script with $ENV{EBCDIC_MD5SUM} set to a true value.
+# (You'll need to have Perl 5.7.3 or later, to have the Encode installed.)
+# (And remember that under the Perl core distribution you should
+#  also have the $ENV{PERL_CORE} set to a true value.)
+# Similarly, to update MacOS section, run with $ENV{MAC_MD5SUM} set.
 
+my $EXPECT;
 if (ord "A" == 193) { # EBCDIC
     $EXPECT = <<EOT;
-23cafa2de11474f0df8f808cc588bcc9  Changes
-3519f3d02c7c91158f732f0f00064657  README
-0268931475ae2a2e843ff58504cfa3f0  MD5.pm
-1be293491bba726810f8e87671ee0328  MD5.xs
+f383935aa6f80a5eada3a365e0240db5  Changes
+11e8028ee426273db6b6db270a8bb38c  README
+4c1cbf9fd2ca3611f8f76c0bc559bb91  MD5.pm
+a6763f297e6346a0c541de105819b01c  MD5.xs
+276da0aa4e9a08b7fe09430c9c5690aa  rfc1321.txt
+EOT
+} elsif ("\n" eq "\015") { # MacOS
+    $EXPECT = <<EOT;
+531c4466c0d2e510628584f47fc5a589  Changes
+c95549c6c5e1e1c078b27042f1dc850f  README
+58437b1015d43f47d78c37a2e06bc70c  MD5.pm
+dd630942214a791a56d18f477f8e423e  MD5.xs
 754b9db19f79dbc4992f7166eb0f37ce  rfc1321.txt
 EOT
 } else {
+    # This is the output of: 'md5sum Changes README MD5.pm MD5.xs rfc1321.txt'
     $EXPECT = <<EOT;
-23cafa2de11474f0df8f808cc588bcc9  Changes
-3519f3d02c7c91158f732f0f00064657  README
-0268931475ae2a2e843ff58504cfa3f0  MD5.pm
-1be293491bba726810f8e87671ee0328  MD5.xs
+b3fdcedb2f50b051c2a9a9009b36ae57  Changes
+c95549c6c5e1e1c078b27042f1dc850f  README
+58437b1015d43f47d78c37a2e06bc70c  MD5.pm
+dd630942214a791a56d18f477f8e423e  MD5.xs
 754b9db19f79dbc4992f7166eb0f37ce  rfc1321.txt
 EOT
 }
@@ -48,6 +60,8 @@ if ($@) {
 
 for (split /^/, $EXPECT) {
      my($md5hex, $file) = split ' ';
+     my $base = $file;
+#     print "# $base\n";
      if ($ENV{PERL_CORE}) {
          if ($file eq 'rfc1321.txt') { # Don't have it in core.
             print "ok ", ++$testno, " # Skip: PERL_CORE\n";
@@ -62,6 +76,24 @@ for (split /^/, $EXPECT) {
         $file = File::Spec->catfile($path, $file);
      }
 #     print "# file = $file\n";
+     unless (-f $file) {
+       warn "No such file: $file\n";
+       next;
+     }
+     if ($ENV{EBCDIC_MD5SUM}) {
+         require Encode;
+        my $data = cat_file($file);    
+        Encode::from_to($data, 'latin1', 'cp1047');
+        print md5_hex($data), "  $base\n";
+        next;
+     }
+     if ($ENV{MAC_MD5SUM}) {
+         require Encode;
+        my $data = cat_file($file);    
+        Encode::from_to($data, 'latin1', 'MacRoman');
+        print md5_hex($data), "  $base\n";
+        next;
+     }
      my $md5bin = pack("H*", $md5hex);
      my $md5b64;
      if ($B64) {
@@ -143,7 +175,6 @@ sub digest_file
     #print "$file $method\n";
 
     open(FILE, $file) or die "Can't open $file: $!";
-    binmode(FILE);
     my $digest = Digest::MD5->new->addfile(*FILE)->$method();
     close(FILE);
 
@@ -155,7 +186,10 @@ sub cat_file
     my($file) = @_;
     local $/;  # slurp
     open(FILE, $file) or die "Can't open $file: $!";
-    binmode(FILE);
+
+    # For PerlIO in case of UTF-8 locales.
+    eval 'binmode(FILE, ":bytes")' if $] >= 5.008;
+
     my $tmp = <FILE>;
     close(FILE);
     $tmp;