Skip to content

Commit 07cd6fc

Browse files
author
Thomas M. DuBuisson
committed
Fix up test suite to include encoding and show instances.
1 parent 4c87142 commit 07cd6fc

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Test/main.hs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
module Main where
2+
3+
import Test.Framework
4+
import Test.Framework.Providers.QuickCheck2 (testProperty)
15
import Test.MD5
6+
import Data.Digest.Pure.MD5
7+
import Data.Char (isSpace)
8+
import Data.ByteString.Lazy (toStrict, ByteString)
9+
import qualified Data.Binary as B
10+
import qualified Data.Serialize as S
11+
import Hexdump
12+
13+
main :: IO ()
14+
main = defaultMain
15+
[ testGroup "MD5 functional correctness tests" base_tests
16+
, testGroup "Serialization order correctness tests" serialization_tests
17+
]
18+
19+
-- | Use the crypto-api-tests, piddly as they are, to give evidence of
20+
-- functional correctness.
21+
base_tests :: [Test]
22+
base_tests = makeMD5Tests (undefined :: MD5Digest)
223

3-
main = test
24+
-- | Ensure the output of `show`, `Serialize`, `Binary`, and `md5DigestBytes`
25+
-- are all consistent.
26+
serialization_tests :: [Test]
27+
serialization_tests =
28+
[ testProperty "show == simple_hex . Serialize.encode"
29+
(\bs -> let d = hsh bs in show d == filter (not . isSpace) (simpleHex (S.encode d)))
30+
, testProperty "Serialize.encode == toStrict . Binary.encode"
31+
(\bs -> let d = hsh bs in toStrict (B.encode d) == S.encode d)
32+
, testProperty "Serialize.encode == md5DigestBytes"
33+
(\bs -> let d = hsh bs in S.encode d == md5DigestBytes d)
34+
]
35+
where
36+
hsh = hash :: ByteString -> MD5Digest

pureMD5.cabal

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ synopsis: A Haskell-only implementation of the MD5 digest (hash) algorithm.
1010
category: Data, Cryptography
1111
stability: stable
1212
build-type: Simple
13-
cabal-version: >= 1.6
14-
tested-with: GHC == 6.12.1
13+
cabal-version: >= 1.10
14+
tested-with: GHC == 7.10.3
1515
extra-source-files: Test/MD5.hs
1616

1717
flag test
@@ -26,6 +26,21 @@ Library
2626
if arch(i386) || arch(x86_64)
2727
cpp-options: -DFastWordExtract
2828

29+
Test-Suite MD5Tests
30+
type: exitcode-stdio-1.0
31+
default-language: Haskell2010
32+
build-depends: base >=4.6 && < 5,
33+
pureMD5,
34+
crypto-api-tests,
35+
QuickCheck,
36+
test-framework >= 0.8,
37+
test-framework-quickcheck2,
38+
binary, cereal, pretty-hex,
39+
bytestring
40+
ghc-options: -Wall
41+
hs-source-dirs: Test
42+
main-is: main.hs
43+
2944
source-repository head
3045
type: git
3146
location: https://github.com/TomMD/pureMD5

0 commit comments

Comments
 (0)