This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Put back the MD5-Base64 tests now that we have MIME::Base64.
[perl5.git] / t / lib / md5-file.t
index a5b726b..b9c51e0 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
 print "1..2\n";
 
 use strict;
-use Digest::MD5 qw(md5 md5_hex);
+use Digest::MD5 qw(md5 md5_hex md5_base64);
 
 #
 # This is the output of: 'md5sum MD5.pm MD5.xs'
@@ -25,6 +25,14 @@ $EXPECT = <<EOT;
 EOT
 }
 
+my $B64 = 1;
+eval { require MIME::Base64; };
+if ($@) {
+    print $@;
+    print "# Will not test base64 methods\n";
+    $B64 = 0;
+}
+
 my $testno = 0;
 
 use File::Spec;
@@ -39,6 +47,11 @@ for (split /^/, $EXPECT) {
      }
      $file = File::Spec->catfile($path, $last);
      my $md5bin = pack("H*", $md5hex);
+     my $md5b64;
+     if ($B64) {
+        $md5b64 = MIME::Base64::encode($md5bin, "");
+        chop($md5b64); chop($md5b64);   # remove padding
+     }
      my $failed;
 
      if (digest_file($file, 'digest') ne $md5bin) {
@@ -51,6 +64,11 @@ for (split /^/, $EXPECT) {
         $failed++;
      }
 
+     if ($B64 && digest_file($file, 'b64digest') ne $md5b64) {
+        print "$file: Bad b64digest\n";
+        $failed++;
+     }
+
      my $data = cat_file($file);
      if (md5($data) ne $md5bin) {
         print "$file: md5() failed\n";
@@ -60,6 +78,10 @@ for (split /^/, $EXPECT) {
         print "$file: md5_hex() failed\n";
         $failed++;
      }
+     if ($B64 && md5_base64($data) ne $md5b64) {
+        print "$file: md5_base64() failed\n";
+        $failed++;
+     }
 
      if (Digest::MD5->new->add($data)->digest ne $md5bin) {
         print "$file: MD5->new->add(...)->digest failed\n";
@@ -69,6 +91,10 @@ for (split /^/, $EXPECT) {
         print "$file: MD5->new->add(...)->hexdigest failed\n";
         $failed++;
      }
+     if ($B64 && Digest::MD5->new->add($data)->b64digest ne $md5b64) {
+        print "$file: MD5->new->add(...)->b64digest failed\n";
+        $failed++;
+     }
 
      my @data = split //, $data;
      if (md5(@data) ne $md5bin) {