on master help sign in
test-framework is fixed again, so we use it again.
commit7a75e1f4814a36f57558f59d11e5b7b948e03ed5 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 24 Jan 2010, 22:00 (17 years ago) parent81e3df1
4 files changed+46−26
.gitignore+1−1 tests/Main.hs+6−17 tests/Template.hs+25−7 tests/Util.hs+14−1
.gitignore+1−1
@@ -14,7 +14,7 @@ dist
1414tags
1515
1616# Ignore test builds.
17−tests/Tests
17+tests/Main
1818
1919# Rest of the file: ignore examples
2020examples/*/_cache
tests/Main.hs+6−17
@@ -1,23 +1,12 @@
11module Main where
22
3−import Control.Monad (mapM_)
4−import Test.QuickCheck
3+import Test.Framework (defaultMain, testGroup)
4+import Test.Framework.Providers.HUnit
5+import Test.Framework.Providers.QuickCheck2
56
67import Template
78import Util
89
9−main = do
10− runTests "Template" $ do
11− quickCheck prop_template_encode_id
12− quickCheck prop_substitute_id
13− quickCheck prop_substitute_case1
14−
15− runTests "Util" $ do
16− quickCheck prop_trim_length
17− quickCheck prop_trim_id
18− quickCheck prop_stripHTML_length
19− quickCheck prop_stripHTML_id
20−
21− where
22− runTests name action = do putStrLn name
23− action
10+main = defaultMain [ templateGroup
11+ , utilGroup
12+ ]
tests/Template.hs+25−7
@@ -1,12 +1,25 @@
1−module Template where
1+module Template
2+ ( templateGroup
3+ ) where
24
35import qualified Data.Map as M
46
5−import Test.QuickCheck
67import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
712
813import Text.Hakyll.Internal.Template
914
15+-- Template test group.
16+templateGroup = testGroup "Template"
17+ [ testProperty "prop_template_encode_id" prop_template_encode_id
18+ , testProperty "prop_substitute_id" prop_substitute_id
19+ , testCase "test_substitute_1" test_substitute_1
20+ , testCase "test_substitute_2" test_substitute_2
21+ ]
22+
1023-- Test encoding/decoding of templates.
1124prop_template_encode_id :: Template -> Bool
1225prop_template_encode_id template = decode (encode template) == template
@@ -16,10 +29,15 @@ prop_substitute_id string =
1629 regularSubstitute (fromString string) M.empty == string
1730
1831-- substitute test case 1.
19−prop_substitute_case1 string1 string2 =
20− finalSubstitute template context == string1 ++ " costs $" ++ string2 ++ "."
32+test_substitute_1 =
33+ finalSubstitute template context @?= "Banana costs $4."
2134 where
2235 template = fromString "$product costs $$$price."
23− context = M.fromList [ ("product", string1)
24− , ("price", string2)
25− ]
36+ context = M.fromList [("product", "Banana"), ("price", "4")]
37+
38+-- substitute test case 2.
39+test_substitute_2 =
40+ regularSubstitute template context @?= "$$root is a special key."
41+ where
42+ template = fromString "$$root is a special $thing."
43+ context = M.fromList [("root", "foo"), ("thing", "key")]
tests/Util.hs+14−1
@@ -1,11 +1,24 @@
1−module Util where
1+module Util
2+ ( utilGroup
3+ ) where
24
35import Data.Char
46
57import Test.QuickCheck
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
611
712import Text.Hakyll.Util
813
14+-- Util test group.
15+utilGroup = testGroup "Util"
16+ [ testProperty "prop_trim_length" prop_trim_length
17+ , testProperty "prop_trim_id" prop_trim_id
18+ , testProperty "prop_stripHTML_length" prop_stripHTML_length
19+ , testProperty "prop_stripHTML_id" prop_stripHTML_id
20+ ]
21+
922-- Test that a string always becomes shorter when trimmed.
1023prop_trim_length str = length str >= length (trim str)
1124