[libpath-tiny-perl] 04/11: Add test for digest method for MD5 and SHA-256
Jonas Smedegaard
js at alioth.debian.org
Wed Aug 7 16:10:30 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libpath-tiny-perl.
commit ded7b1eabf557e8654a4542dd7c5e59643f743d5
Author: Keedi Kim <keedi.k at gmail.com>
Date: Thu Jul 25 18:07:34 2013 +0900
Add test for digest method for MD5 and SHA-256
---
t/digest.t | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/t/digest.t b/t/digest.t
new file mode 100644
index 0000000..0dc530c
--- /dev/null
+++ b/t/digest.t
@@ -0,0 +1,54 @@
+use 5.008001;
+use strict;
+use warnings;
+use Test::More 0.96;
+
+use Path::Tiny;
+use Digest;
+
+my $file = path('foo.bin');
+ok $file;
+
+my $chunk = pack("Z*", "Hello Path::Tiny\nThis is packed binary string\n");
+ok( $file->spew_raw($chunk) );
+
+# Digest::SHA was first released with perl v5.9.3.
+# And Digest::SHA2 is not a core module.
+SKIP: {
+ eval { require Digest::SHA; 1 };
+ if ($@) {
+ eval { require Digest::SHA2; 1 };
+ skip "cannot find neither Digest::SHA nor Digest::SHA2", 1 if $@;
+ }
+
+ is(
+ $file->digest,
+ 'a98e605049836e8adb36d351abb95a09e9e5e200703576ecdaec0e697d17d626',
+ 'digest SHA-256 (hardcoded)',
+ );
+
+ my $sha = Digest->new('SHA-256');
+ $sha->add($chunk);
+ is(
+ $file->digest,
+ $sha->hexdigest,
+ 'digest SHA-256',
+ );
+}
+
+is(
+ $file->digest('MD5'),
+ 'ce05aca61c0e58d7396073b668bcafd0',
+ 'digest MD5 (hardcoded)',
+);
+
+my $md5 = Digest->new('MD5');
+$md5->add($chunk);
+is(
+ $file->digest('MD5'),
+ $md5->hexdigest,
+ 'digest MD5',
+);
+
+done_testing;
+# COPYRIGHT
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libpath-tiny-perl.git
More information about the Pkg-perl-cvs-commits
mailing list