@@ -9,8 +9,12 @@ import qualified Data.UUID as U
9import qualified Data.UUID.V1 as U
9import qualified Data.UUID.V1 as U
10import qualified Data.UUID.V3 as U3
10import qualified Data.UUID.V3 as U3
11import qualified Data.UUID.V5 as U5
11import qualified Data.UUID.V5 as U5
12+import qualified Test.HUnit as H
12−import Test.HUnit
13+import Test.HUnit hiding (Test)
13import Test.QuickCheck hiding ((.&.))
14import Test.QuickCheck hiding ((.&.))
15+import Test.Framework (defaultMain, Test(..))
16+import Test.Framework.Providers.HUnit (hUnitTestToTests)
17+import Test.Framework.Providers.QuickCheck2 (testProperty)
14import System.IO
18import System.IO
@@ -27,20 +31,20 @@ instance Arbitrary U.UUID where
27 arbitrary = choose (U.nil, U.nil)
31 arbitrary = choose (U.nil, U.nil)
30−test_null :: Test
34+test_null :: H.Test
31−test_null = TestList [
35+test_null = H.TestList [
32 "nil is null" ~: assertBool "" (U.null U.nil),
36 "nil is null" ~: assertBool "" (U.null U.nil),
33 "namespaceDNS is not null" ~: assertBool "" (not $ U.null U3.namespaceDNS)
37 "namespaceDNS is not null" ~: assertBool "" (not $ U.null U3.namespaceDNS)
36−test_nil :: Test
40+test_nil :: H.Test
37−test_nil = TestList [
41+test_nil = H.TestList [
38 "nil string" ~: U.toString U.nil @?= "00000000-0000-0000-0000-000000000000",
42 "nil string" ~: U.toString U.nil @?= "00000000-0000-0000-0000-000000000000",
39 "nil bytes" ~: U.toByteString U.nil @?= B.pack (replicate 16 0)
43 "nil bytes" ~: U.toByteString U.nil @?= B.pack (replicate 16 0)
42−test_conv :: Test
46+test_conv :: H.Test
43−test_conv = TestList [
47+test_conv = H.TestList [
44 "conv bytes to string" ~:
48 "conv bytes to string" ~:
45 maybe "" (U.toString) (U.fromByteString b16) @?= s16,
49 maybe "" (U.toString) (U.fromByteString b16) @?= s16,
46 "conv string to bytes" ~:
50 "conv string to bytes" ~:
@@ -49,89 +53,89 @@ test_conv = TestList [
49 where b16 = B.pack [1..16]
53 where b16 = B.pack [1..16]
50 s16 = "01020304-0506-0708-090a-0b0c0d0e0f10"
54 s16 = "01020304-0506-0708-090a-0b0c0d0e0f10"
52−test_v1 :: [Maybe U.UUID] -> Test
56+test_v1 :: [Maybe U.UUID] -> H.Test
53−test_v1 v1s = TestList [
57+test_v1 v1s = H.TestList [
54 "V1 unique" ~: nub (v1s \\ nub v1s) @?= [],
58 "V1 unique" ~: nub (v1s \\ nub v1s) @?= [],
55− "V1 not null" ~: TestList $ map (testUUID (not . U.null)) v1s,
59+ "V1 not null" ~: H.TestList $ map (testUUID (not . U.null)) v1s,
56− "V1 valid" ~: TestList $ map (testUUID (isValidVersion 1)) v1s
60+ "V1 valid" ~: H.TestList $ map (testUUID (isValidVersion 1)) v1s
58− where testUUID :: (U.UUID -> Bool) -> Maybe U.UUID -> Test
62+ where testUUID :: (U.UUID -> Bool) -> Maybe U.UUID -> H.Test
59 testUUID p u = maybe False p u ~? show u
63 testUUID p u = maybe False p u ~? show u
61−test_v3 :: Test
65+test_v3 :: H.Test
62−test_v3 = TestList [
66+test_v3 = H.TestList [
63 "V3 computation" ~:
67 "V3 computation" ~:
64 U3.generateNamed U3.namespaceDNS name @?= uV3
68 U3.generateNamed U3.namespaceDNS name @?= uV3
66 where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
70 where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
67 uV3 = fromJust $ U.fromString "3d813cbb-47fb-32ba-91df-831e1593ac29"
71 uV3 = fromJust $ U.fromString "3d813cbb-47fb-32ba-91df-831e1593ac29"
69−test_v5 :: Test
73+test_v5 :: H.Test
70−test_v5 = TestList [
74+test_v5 = H.TestList [
71 "V5 computation" ~:
75 "V5 computation" ~:
72 U5.generateNamed U5.namespaceDNS name @?= uV5
76 U5.generateNamed U5.namespaceDNS name @?= uV5
74 where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
78 where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
75 uV5 = fromJust $ U.fromString "21f7f8de-8051-5b89-8680-0195ef798b6a"
79 uV5 = fromJust $ U.fromString "21f7f8de-8051-5b89-8680-0195ef798b6a"
77−prop_stringRoundTrip :: Property
81+prop_stringRoundTrip :: Test
78−prop_stringRoundTrip = label "String round trip" stringRoundTrip
82+prop_stringRoundTrip = testProperty "String round trip" stringRoundTrip
79 where stringRoundTrip :: U.UUID -> Bool
83 where stringRoundTrip :: U.UUID -> Bool
80 stringRoundTrip u = maybe False (== u) $ U.fromString (U.toString u)
84 stringRoundTrip u = maybe False (== u) $ U.fromString (U.toString u)
82−prop_byteStringRoundTrip :: Property
86+prop_byteStringRoundTrip :: Test
83−prop_byteStringRoundTrip = label "ByteString round trip" byteStringRoundTrip
87+prop_byteStringRoundTrip = testProperty "ByteString round trip" byteStringRoundTrip
84 where byteStringRoundTrip :: U.UUID -> Bool
88 where byteStringRoundTrip :: U.UUID -> Bool
85 byteStringRoundTrip u = maybe False (== u)
89 byteStringRoundTrip u = maybe False (== u)
86 $ U.fromByteString (U.toByteString u)
90 $ U.fromByteString (U.toByteString u)
88−prop_stringLength :: Property
92+prop_stringLength :: Test
89−prop_stringLength = label "String length" stringLength
93+prop_stringLength = testProperty "String length" stringLength
90 where stringLength :: U.UUID -> Bool
94 where stringLength :: U.UUID -> Bool
91 stringLength u = length (U.toString u) == 36
95 stringLength u = length (U.toString u) == 36
93−prop_byteStringLength :: Property
97+prop_byteStringLength :: Test
94−prop_byteStringLength = label "ByteString length" byteStringLength
98+prop_byteStringLength = testProperty "ByteString length" byteStringLength
95 where byteStringLength :: U.UUID -> Bool
99 where byteStringLength :: U.UUID -> Bool
96 byteStringLength u = B.length (U.toByteString u) == 16
100 byteStringLength u = B.length (U.toByteString u) == 16
98−prop_randomsDiffer :: Property
102+prop_randomsDiffer :: Test
99−prop_randomsDiffer = label "Randoms differ" randomsDiffer
103+prop_randomsDiffer = testProperty "Randoms differ" randomsDiffer
100 where randomsDiffer :: (U.UUID, U.UUID) -> Bool
104 where randomsDiffer :: (U.UUID, U.UUID) -> Bool
101 randomsDiffer (u1, u2) = u1 /= u2
105 randomsDiffer (u1, u2) = u1 /= u2
103−prop_randomNotNull :: Property
107+prop_randomNotNull :: Test
104−prop_randomNotNull = label "Random not null" randomNotNull
108+prop_randomNotNull = testProperty "Random not null" randomNotNull
105 where randomNotNull :: U.UUID -> Bool
109 where randomNotNull :: U.UUID -> Bool
106 randomNotNull = not. U.null
110 randomNotNull = not. U.null
108−prop_randomsValid :: Property
112+prop_randomsValid :: Test
109−prop_randomsValid = label "Random valid" randomsValid
113+prop_randomsValid = testProperty "Random valid" randomsValid
110 where randomsValid :: U.UUID -> Bool
114 where randomsValid :: U.UUID -> Bool
111 randomsValid = isValidVersion 4
115 randomsValid = isValidVersion 4
113−prop_v3NotNull :: Property
117+prop_v3NotNull :: Test
114−prop_v3NotNull = label "V3 not null" v3NotNull
118+prop_v3NotNull = testProperty "V3 not null" v3NotNull
115 where v3NotNull :: [Word8] -> Bool
119 where v3NotNull :: [Word8] -> Bool
116 v3NotNull = not . U.null . U3.generateNamed U3.namespaceDNS
120 v3NotNull = not . U.null . U3.generateNamed U3.namespaceDNS
118−prop_v3Valid :: Property
122+prop_v3Valid :: Test
119−prop_v3Valid = label "V3 valid" v3Valid
123+prop_v3Valid = testProperty "V3 valid" v3Valid
120 where v3Valid :: [Word8] -> Bool
124 where v3Valid :: [Word8] -> Bool
121 v3Valid = isValidVersion 3 . U3.generateNamed U3.namespaceDNS
125 v3Valid = isValidVersion 3 . U3.generateNamed U3.namespaceDNS
123−prop_v5NotNull :: Property
127+prop_v5NotNull :: Test
124−prop_v5NotNull = label "V5 not null" v5NotNull
128+prop_v5NotNull = testProperty "V5 not null" v5NotNull
125 where v5NotNull :: [Word8] -> Bool
129 where v5NotNull :: [Word8] -> Bool
126 v5NotNull = not . U.null . U5.generateNamed U5.namespaceDNS
130 v5NotNull = not . U.null . U5.generateNamed U5.namespaceDNS
128−prop_v5Valid :: Property
132+prop_v5Valid :: Test
129−prop_v5Valid = label "V5 valid" v5Valid
133+prop_v5Valid = testProperty "V5 valid" v5Valid
130 where v5Valid :: [Word8] -> Bool
134 where v5Valid :: [Word8] -> Bool
131 v5Valid = isValidVersion 5 . U5.generateNamed U5.namespaceDNS
135 v5Valid = isValidVersion 5 . U5.generateNamed U5.namespaceDNS
133−prop_readShowRoundTrip :: Property
137+prop_readShowRoundTrip :: Test
134−prop_readShowRoundTrip = label "Read/Show round-trip" prop
138+prop_readShowRoundTrip = testProperty "Read/Show round-trip" prop
135 where -- we're using 'Maybe UUID' to add a bit of
139 where -- we're using 'Maybe UUID' to add a bit of
136 -- real-world complexity.
140 -- real-world complexity.
137 prop :: U.UUID -> Bool
141 prop :: U.UUID -> Bool
@@ -140,25 +144,27 @@ prop_readShowRoundTrip = label "Read/Show round-trip" prop
140main :: IO ()
144main :: IO ()
142 v1s <- replicateM 100 U.nextUUID
146 v1s <- replicateM 100 U.nextUUID
143− _ <- runTestText (putTextToHandle stderr False) (TestList [
147+ defaultMain $
149+ [ hUnitTestToTests $ H.TestList [
144 test_null,
150 test_null,
145 test_nil,
151 test_nil,
146 test_conv,
152 test_conv,
147 test_v1 v1s,
153 test_v1 v1s,
151− mapM_ quickCheck $ [
152− prop_stringRoundTrip,
157+ , [ prop_stringRoundTrip,
153− prop_readShowRoundTrip,
158+ prop_readShowRoundTrip,
154− prop_byteStringRoundTrip,
159+ prop_byteStringRoundTrip,
155− prop_stringLength,
160+ prop_stringLength,
156− prop_byteStringLength,
161+ prop_byteStringLength,
157− prop_randomsDiffer,
162+ prop_randomsDiffer,
158− prop_randomNotNull,
163+ prop_randomNotNull,
159− prop_randomsValid,
164+ prop_randomsValid,
160− prop_v3NotNull,
165+ prop_v3NotNull,
161− prop_v3Valid,
166+ prop_v3Valid,
162− prop_v5NotNull,
167+ prop_v5NotNull,
163− prop_v5Valid
168+ prop_v5Valid