on master help sign in
test-framework is fixed again, so we use it again.
7a75e1fJasper Van der Jeugt
.gitignore+1−1
@@ -14,7 +14,7 @@ dist
14tags
14tags
15
15
16# Ignore test builds.
16# Ignore test builds.
17−tests/Tests
17+tests/Main
18
18
19# Rest of the file: ignore examples
19# Rest of the file: ignore examples
20examples/*/_cache
20examples/*/_cache
tests/Main.hs+6−17
@@ -1,23 +1,12 @@
1module Main where
1module Main where
2
2
3−import Control.Monad (mapM_)
3+import Test.Framework (defaultMain, testGroup)
4−import Test.QuickCheck
4+import Test.Framework.Providers.HUnit
5+import Test.Framework.Providers.QuickCheck2
5
6
6import Template
7import Template
7import Util
8import Util
8
9
9−main = do
10+main = defaultMain [ templateGroup
10− runTests "Template" $ do
11+ , utilGroup
11− quickCheck prop_template_encode_id
12+ ]
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
tests/Template.hs+25−7
@@ -1,12 +1,25 @@
1−module Template where
1+module Template
2+ ( templateGroup
3+ ) where
2
4
3import qualified Data.Map as M
5import qualified Data.Map as M
4
6
5−import Test.QuickCheck
6import Data.Binary
7import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
7
12
8import Text.Hakyll.Internal.Template
13import Text.Hakyll.Internal.Template
9
14
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+
10-- Test encoding/decoding of templates.
23-- Test encoding/decoding of templates.
11prop_template_encode_id :: Template -> Bool
24prop_template_encode_id :: Template -> Bool
12prop_template_encode_id template = decode (encode template) == template
25prop_template_encode_id template = decode (encode template) == template
@@ -16,10 +29,15 @@ prop_substitute_id string =
16 regularSubstitute (fromString string) M.empty == string
29 regularSubstitute (fromString string) M.empty == string
17
30
18-- substitute test case 1.
31-- substitute test case 1.
19−prop_substitute_case1 string1 string2 =
32+test_substitute_1 =
20− finalSubstitute template context == string1 ++ " costs $" ++ string2 ++ "."
33+ finalSubstitute template context @?= "Banana costs $4."
21 where
34 where
22 template = fromString "$product costs $$$price."
35 template = fromString "$product costs $$$price."
23− context = M.fromList [ ("product", string1)
36+ context = M.fromList [("product", "Banana"), ("price", "4")]
24− , ("price", string2)
37+
25− ]
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
2
4
3import Data.Char
5import Data.Char
4
6
5import Test.QuickCheck
7import Test.QuickCheck
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
6
11
7import Text.Hakyll.Util
12import Text.Hakyll.Util
8
13
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+
9-- Test that a string always becomes shorter when trimmed.
22-- Test that a string always becomes shorter when trimmed.
10prop_trim_length str = length str >= length (trim str)
23prop_trim_length str = length str >= length (trim str)
11
24