on master help sign in
Run tests with test-framework

Output formatting still needs work, but I feel better using one runner for all of the tests.

commit5d304d28706eccb2a9b43d719b0faffc0eceb9fc authorAntoine Latter <aslatter@gmail.com> dateSun 1 Sep 2013, 14:14 (13 years ago) parent56ac7d5
2 files changed+65−56
tests/TestUUID.hs+61−55 uuid.cabal+4−1
tests/TestUUID.hs+61−55
@@ -9,8 +9,12 @@ import qualified Data.UUID as U
99import qualified Data.UUID.V1 as U
1010import qualified Data.UUID.V3 as U3
1111import qualified Data.UUID.V5 as U5
12−import Test.HUnit
12+import qualified Test.HUnit as H
13+import Test.HUnit hiding (Test)
1314import Test.QuickCheck hiding ((.&.))
15+import Test.Framework (defaultMain, Test(..))
16+import Test.Framework.Providers.HUnit (hUnitTestToTests)
17+import Test.Framework.Providers.QuickCheck2 (testProperty)
1418import System.IO
1519
1620
@@ -27,20 +31,20 @@ instance Arbitrary U.UUID where
2731 arbitrary = choose (U.nil, U.nil)
2832
2933
30−test_null :: Test
31−test_null = TestList [
34+test_null :: H.Test
35+test_null = H.TestList [
3236 "nil is null" ~: assertBool "" (U.null U.nil),
3337 "namespaceDNS is not null" ~: assertBool "" (not $ U.null U3.namespaceDNS)
3438 ]
3539
36−test_nil :: Test
37−test_nil = TestList [
40+test_nil :: H.Test
41+test_nil = H.TestList [
3842 "nil string" ~: U.toString U.nil @?= "00000000-0000-0000-0000-000000000000",
3943 "nil bytes" ~: U.toByteString U.nil @?= B.pack (replicate 16 0)
4044 ]
4145
42−test_conv :: Test
43−test_conv = TestList [
46+test_conv :: H.Test
47+test_conv = H.TestList [
4448 "conv bytes to string" ~:
4549 maybe "" (U.toString) (U.fromByteString b16) @?= s16,
4650 "conv string to bytes" ~:
@@ -49,89 +53,89 @@ test_conv = TestList [
4953 where b16 = B.pack [1..16]
5054 s16 = "01020304-0506-0708-090a-0b0c0d0e0f10"
5155
52−test_v1 :: [Maybe U.UUID] -> Test
53−test_v1 v1s = TestList [
56+test_v1 :: [Maybe U.UUID] -> H.Test
57+test_v1 v1s = H.TestList [
5458 "V1 unique" ~: nub (v1s \\ nub v1s) @?= [],
55− "V1 not null" ~: TestList $ map (testUUID (not . U.null)) v1s,
56− "V1 valid" ~: TestList $ map (testUUID (isValidVersion 1)) v1s
59+ "V1 not null" ~: H.TestList $ map (testUUID (not . U.null)) v1s,
60+ "V1 valid" ~: H.TestList $ map (testUUID (isValidVersion 1)) v1s
5761 ]
58− where testUUID :: (U.UUID -> Bool) -> Maybe U.UUID -> Test
62+ where testUUID :: (U.UUID -> Bool) -> Maybe U.UUID -> H.Test
5963 testUUID p u = maybe False p u ~? show u
6064
61−test_v3 :: Test
62−test_v3 = TestList [
65+test_v3 :: H.Test
66+test_v3 = H.TestList [
6367 "V3 computation" ~:
6468 U3.generateNamed U3.namespaceDNS name @?= uV3
6569 ]
6670 where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
6771 uV3 = fromJust $ U.fromString "3d813cbb-47fb-32ba-91df-831e1593ac29"
6872
69−test_v5 :: Test
70−test_v5 = TestList [
73+test_v5 :: H.Test
74+test_v5 = H.TestList [
7175 "V5 computation" ~:
7276 U5.generateNamed U5.namespaceDNS name @?= uV5
7377 ]
7478 where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
7579 uV5 = fromJust $ U.fromString "21f7f8de-8051-5b89-8680-0195ef798b6a"
7680
77−prop_stringRoundTrip :: Property
78−prop_stringRoundTrip = label "String round trip" stringRoundTrip
81+prop_stringRoundTrip :: Test
82+prop_stringRoundTrip = testProperty "String round trip" stringRoundTrip
7983 where stringRoundTrip :: U.UUID -> Bool
8084 stringRoundTrip u = maybe False (== u) $ U.fromString (U.toString u)
8185
82−prop_byteStringRoundTrip :: Property
83−prop_byteStringRoundTrip = label "ByteString round trip" byteStringRoundTrip
86+prop_byteStringRoundTrip :: Test
87+prop_byteStringRoundTrip = testProperty "ByteString round trip" byteStringRoundTrip
8488 where byteStringRoundTrip :: U.UUID -> Bool
8589 byteStringRoundTrip u = maybe False (== u)
8690 $ U.fromByteString (U.toByteString u)
8791
88−prop_stringLength :: Property
89−prop_stringLength = label "String length" stringLength
92+prop_stringLength :: Test
93+prop_stringLength = testProperty "String length" stringLength
9094 where stringLength :: U.UUID -> Bool
9195 stringLength u = length (U.toString u) == 36
9296
93−prop_byteStringLength :: Property
94−prop_byteStringLength = label "ByteString length" byteStringLength
97+prop_byteStringLength :: Test
98+prop_byteStringLength = testProperty "ByteString length" byteStringLength
9599 where byteStringLength :: U.UUID -> Bool
96100 byteStringLength u = B.length (U.toByteString u) == 16
97101
98−prop_randomsDiffer :: Property
99−prop_randomsDiffer = label "Randoms differ" randomsDiffer
102+prop_randomsDiffer :: Test
103+prop_randomsDiffer = testProperty "Randoms differ" randomsDiffer
100104 where randomsDiffer :: (U.UUID, U.UUID) -> Bool
101105 randomsDiffer (u1, u2) = u1 /= u2
102106
103−prop_randomNotNull :: Property
104−prop_randomNotNull = label "Random not null" randomNotNull
107+prop_randomNotNull :: Test
108+prop_randomNotNull = testProperty "Random not null" randomNotNull
105109 where randomNotNull :: U.UUID -> Bool
106110 randomNotNull = not. U.null
107111
108−prop_randomsValid :: Property
109−prop_randomsValid = label "Random valid" randomsValid
112+prop_randomsValid :: Test
113+prop_randomsValid = testProperty "Random valid" randomsValid
110114 where randomsValid :: U.UUID -> Bool
111115 randomsValid = isValidVersion 4
112116
113−prop_v3NotNull :: Property
114−prop_v3NotNull = label "V3 not null" v3NotNull
117+prop_v3NotNull :: Test
118+prop_v3NotNull = testProperty "V3 not null" v3NotNull
115119 where v3NotNull :: [Word8] -> Bool
116120 v3NotNull = not . U.null . U3.generateNamed U3.namespaceDNS
117121
118−prop_v3Valid :: Property
119−prop_v3Valid = label "V3 valid" v3Valid
122+prop_v3Valid :: Test
123+prop_v3Valid = testProperty "V3 valid" v3Valid
120124 where v3Valid :: [Word8] -> Bool
121125 v3Valid = isValidVersion 3 . U3.generateNamed U3.namespaceDNS
122126
123−prop_v5NotNull :: Property
124−prop_v5NotNull = label "V5 not null" v5NotNull
127+prop_v5NotNull :: Test
128+prop_v5NotNull = testProperty "V5 not null" v5NotNull
125129 where v5NotNull :: [Word8] -> Bool
126130 v5NotNull = not . U.null . U5.generateNamed U5.namespaceDNS
127131
128−prop_v5Valid :: Property
129−prop_v5Valid = label "V5 valid" v5Valid
132+prop_v5Valid :: Test
133+prop_v5Valid = testProperty "V5 valid" v5Valid
130134 where v5Valid :: [Word8] -> Bool
131135 v5Valid = isValidVersion 5 . U5.generateNamed U5.namespaceDNS
132136
133−prop_readShowRoundTrip :: Property
134−prop_readShowRoundTrip = label "Read/Show round-trip" prop
137+prop_readShowRoundTrip :: Test
138+prop_readShowRoundTrip = testProperty "Read/Show round-trip" prop
135139 where -- we're using 'Maybe UUID' to add a bit of
136140 -- real-world complexity.
137141 prop :: U.UUID -> Bool
@@ -140,25 +144,27 @@ prop_readShowRoundTrip = label "Read/Show round-trip" prop
140144main :: IO ()
141145main = do
142146 v1s <- replicateM 100 U.nextUUID
143− _ <- runTestText (putTextToHandle stderr False) (TestList [
147+ defaultMain $
148+ concat $
149+ [ hUnitTestToTests $ H.TestList [
144150 test_null,
145151 test_nil,
146152 test_conv,
147153 test_v1 v1s,
148154 test_v3,
149155 test_v5
150− ])
151− mapM_ quickCheck $ [
152− prop_stringRoundTrip,
153− prop_readShowRoundTrip,
154− prop_byteStringRoundTrip,
155− prop_stringLength,
156− prop_byteStringLength,
157− prop_randomsDiffer,
158− prop_randomNotNull,
159− prop_randomsValid,
160− prop_v3NotNull,
161− prop_v3Valid,
162− prop_v5NotNull,
163− prop_v5Valid
156+ ]
157+ , [ prop_stringRoundTrip,
158+ prop_readShowRoundTrip,
159+ prop_byteStringRoundTrip,
160+ prop_stringLength,
161+ prop_byteStringLength,
162+ prop_randomsDiffer,
163+ prop_randomNotNull,
164+ prop_randomsValid,
165+ prop_v3NotNull,
166+ prop_v3Valid,
167+ prop_v5NotNull,
168+ prop_v5Valid
169+ ]
164170 ]
uuid.cabal+4−1
@@ -80,4 +80,7 @@ Test-Suite testuuid
8080 bytestring >= 0.9 && < 1.1,
8181 HUnit >=1.2 && < 1.3,
8282 QuickCheck >=2.4 && < 2.7,
83− random >= 1.0.1 && < 1.1
83+ random >= 1.0.1 && < 1.1,
84+ test-framework == 0.8.*,
85+ test-framework-hunit == 0.3.*,
86+ test-framework-quickcheck2 == 0.3.*