on master help sign in
Re-enable some tests
bfa1056Jasper Van der Jeugt
src/Hakyll/Core/Item.hs+6
@@ -5,6 +5,7 @@
5module Hakyll.Core.Item
5module Hakyll.Core.Item
6 ( Item (..)
6 ( Item (..)
7 , itemSetBody
7 , itemSetBody
8+ , itemM
8 ) where
9 ) where
9
10
10
11
@@ -39,3 +40,8 @@ instance Binary a => Binary (Item a) where
39--------------------------------------------------------------------------------
40--------------------------------------------------------------------------------
40itemSetBody :: a -> Item b -> Item a
41itemSetBody :: a -> Item b -> Item a
41itemSetBody x (Item i _) = Item i x
42itemSetBody x (Item i _) = Item i x
43+
44+
45+--------------------------------------------------------------------------------
46+itemM :: Monad m => (a -> m b) -> Item a -> m (Item b)
47+itemM f (Item i b) = f b >>= \b' -> return (Item i b')
tests/Hakyll/Core/DependencyAnalyzer/Tests.hsdeleted−70
@@ -1,70 +0,0 @@
1−module Hakyll.Core.DependencyAnalyzer.Tests where
2−
3−import Control.Arrow (second)
4−import qualified Data.Set as S
5−import Data.Monoid (mempty)
6−
7−import Test.Framework
8−import Test.Framework.Providers.HUnit
9−import Test.HUnit hiding (Test)
10−
11−import Hakyll.Core.DirectedGraph
12−import Hakyll.Core.DependencyAnalyzer
13−
14−tests :: [Test]
15−tests =
16− [ testCase "step [1]" step1
17− , testCase "step [2]" step2
18− ]
19−
20−step1 :: Assertion
21−step1 = Just (S.fromList [1, 2, 5, 6, 7, 8, 9]) @?=
22− stepAll (makeDependencyAnalyzer graph isOutOfDate prev)
23− where
24− node = curry $ second S.fromList
25−
26− graph = fromList
27− [ node (8 :: Int) [2, 4, 6]
28− , node 2 [4, 3]
29− , node 4 [3]
30− , node 6 [4]
31− , node 3 []
32− , node 9 [5]
33− , node 5 [7]
34− , node 1 [7]
35− , node 7 []
36− ]
37−
38− prev = fromList
39− [ node 8 [2, 4, 6]
40− , node 2 [4, 3]
41− , node 4 [3]
42− , node 6 [4]
43− , node 3 []
44− , node 9 [5]
45− , node 5 [7]
46− , node 1 [7]
47− , node 7 [8]
48− ]
49−
50− isOutOfDate = (`elem` [5, 2, 6])
51−
52−step2 :: Assertion
53−step2 = Nothing @?= stepAll (makeDependencyAnalyzer graph isOutOfDate mempty)
54− where
55− node = curry $ second S.fromList
56−
57− -- Cycle: 4 -> 7 -> 5 -> 9 -> 4
58− graph = fromList
59− [ node (1 :: Int) [6]
60− , node 2 [3]
61− , node 3 []
62− , node 4 [1, 7, 8]
63− , node 5 [9]
64− , node 6 [3]
65− , node 7 [5]
66− , node 8 [2]
67− , node 9 [4]
68− ]
69−
70− isOutOfDate = const True
tests/Hakyll/Core/Identifier/Tests.hs+23−11
@@ -1,21 +1,30 @@
1+--------------------------------------------------------------------------------
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2module Hakyll.Core.Identifier.Tests
3module Hakyll.Core.Identifier.Tests
3 ( tests
4 ( tests
4 ) where
5 ) where
5
6
6−import Test.Framework
7−import Test.HUnit hiding (Test)
8
7
9−import Hakyll.Core.Identifier
8+--------------------------------------------------------------------------------
10−import Hakyll.Core.Identifier.Pattern
9+import Test.Framework (Test, testGroup)
11−import TestSuite.Util
10+import Test.HUnit ((@=?))
12
11
12+
13+--------------------------------------------------------------------------------
14+import Hakyll.Core.Identifier
15+import Hakyll.Core.Identifier.Pattern
16+import TestSuite.Util
17+
18+
19+--------------------------------------------------------------------------------
13−tests :: [Test]
20+tests :: Test
14−tests = concat
21+tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
15 [ captureTests
22 [ captureTests
16 , matchesTests
23 , matchesTests
17 ]
24 ]
18
25
26+
27+--------------------------------------------------------------------------------
19captureTests :: [Test]
28captureTests :: [Test]
20captureTests = fromAssertions "capture"
29captureTests = fromAssertions "capture"
21 [ Just ["bar"] @=? capture "foo/**" "foo/bar"
30 [ Just ["bar"] @=? capture "foo/**" "foo/bar"
@@ -35,12 +44,15 @@ captureTests = fromAssertions "capture"
35 , Nothing @=? capture "\\*.jpg" "foo.jpg"
44 , Nothing @=? capture "\\*.jpg" "foo.jpg"
36 ]
45 ]
37
46
47+
48+--------------------------------------------------------------------------------
38matchesTests :: [Test]
49matchesTests :: [Test]
39matchesTests = fromAssertions "matches"
50matchesTests = fromAssertions "matches"
40− [ True @=? matches (list ["foo.markdown"]) "foo.markdown"
51+ [ True @=? matches (fromList ["foo.markdown"]) "foo.markdown"
41− , False @=? matches (list ["foo"]) (Identifier (Just "foo") "foo")
52+ , False @=? matches (fromList ["foo"]) (setVersion (Just "x") "foo")
53+ , True @=? matches (fromVersion (Just "xz")) (setVersion (Just "xz") "bar")
42− , True @=? matches (regex "^foo/[^x]*$") "foo/bar"
54+ , True @=? matches (fromRegex "^foo/[^x]*$") "foo/bar"
43− , False @=? matches (regex "^foo/[^x]*$") "foo/barx"
55+ , False @=? matches (fromRegex "^foo/[^x]*$") "foo/barx"
44 , True @=? matches (complement "foo.markdown") "bar.markdown"
56 , True @=? matches (complement "foo.markdown") "bar.markdown"
45 , False @=? matches (complement "foo.markdown") "foo.markdown"
57 , False @=? matches (complement "foo.markdown") "foo.markdown"
46 ]
58 ]
tests/Hakyll/Core/Store/Tests.hs+27−26
@@ -7,12 +7,12 @@ module Hakyll.Core.Store.Tests
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9import Data.Typeable (typeOf)
9import Data.Typeable (typeOf)
10−import Test.Framework
10+import Test.Framework (Test, testGroup)
11−import Test.Framework.Providers.HUnit
11+import Test.Framework.Providers.HUnit (testCase)
12−import Test.Framework.Providers.QuickCheck2
12+import Test.Framework.Providers.QuickCheck2 (testProperty)
13import qualified Test.HUnit as H
13import qualified Test.HUnit as H
14−import Test.QuickCheck
14+import qualified Test.QuickCheck as Q
15−import Test.QuickCheck.Monadic
15+import qualified Test.QuickCheck.Monadic as Q
16
16
17
17
18--------------------------------------------------------------------------------
18--------------------------------------------------------------------------------
@@ -21,8 +21,8 @@ import TestSuite.Util
21
21
22
22
23--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
24−tests :: [Test]
24+tests :: Test
25−tests =
25+tests = testGroup "Hakyll.Core.Store.Tests"
26 [ testProperty "simple get . set" simpleSetGet
26 [ testProperty "simple get . set" simpleSetGet
27 , testProperty "persistent get . set" persistentSetGet
27 , testProperty "persistent get . set" persistentSetGet
28 , testCase "WrongType get . set" wrongType
28 , testCase "WrongType get . set" wrongType
@@ -30,33 +30,34 @@ tests =
30
30
31
31
32--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
33−simpleSetGet :: Property
33+simpleSetGet :: Q.Property
34−simpleSetGet = monadicIO $ do
34+simpleSetGet = Q.monadicIO $ do
35− key <- pick arbitrary
35+ key <- Q.pick Q.arbitrary
36− value <- pick arbitrary
36+ value <- Q.pick Q.arbitrary
37− store <- run $ makeStoreTest
37+ store <- Q.run newTestStore
38− run $ Store.set store key (value :: String)
38+ Q.run $ Store.set store key (value :: String)
39− value' <- run $ Store.get store key
39+ value' <- Q.run $ Store.get store key
40− assert $ Store.Found value == value'
40+ Q.assert $ Store.Found value == value'
41+ Q.run cleanTestStore
41
42
42
43
43--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
44−persistentSetGet :: Property
45+persistentSetGet :: Q.Property
45−persistentSetGet = monadicIO $ do
46+persistentSetGet = Q.monadicIO $ do
46− key <- pick arbitrary
47+ key <- Q.pick Q.arbitrary
47− value <- pick arbitrary
48+ value <- Q.pick Q.arbitrary
48− store1 <- run $ makeStoreTest
49+ store1 <- Q.run newTestStore
49− run $ Store.set store1 key (value :: String)
50+ Q.run $ Store.set store1 key (value :: String)
50 -- Now Create another store from the same dir to test persistence
51 -- Now Create another store from the same dir to test persistence
51− store2 <- run $ makeStoreTest
52+ store2 <- Q.run newTestStore
52− value' <- run $ Store.get store2 key
53+ value' <- Q.run $ Store.get store2 key
53− assert $ Store.Found value == value'
54+ Q.assert $ Store.Found value == value'
55+ Q.run cleanTestStore
54
56
55
57
56--------------------------------------------------------------------------------
58--------------------------------------------------------------------------------
57wrongType :: H.Assertion
59wrongType :: H.Assertion
58−wrongType = do
60+wrongType = withTestStore $ \store -> do
59− store <- makeStoreTest
60 -- Store a string and try to fetch an int
61 -- Store a string and try to fetch an int
61 Store.set store ["foo", "bar"] ("qux" :: String)
62 Store.set store ["foo", "bar"] ("qux" :: String)
62 value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
63 value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
tests/Hakyll/Core/UnixFilter/Tests.hs+26−39
@@ -1,50 +1,37 @@
1+--------------------------------------------------------------------------------
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2module Hakyll.Core.UnixFilter.Tests
3module Hakyll.Core.UnixFilter.Tests
4+ ( tests
3− where
5+ ) where
4
6
5−import Control.Arrow ((>>>))
6−import qualified Data.Map as M
7
7
8+--------------------------------------------------------------------------------
8−import Test.Framework (Test)
9+import Test.Framework (Test, testGroup)
9−import Test.Framework.Providers.HUnit (testCase)
10+import Test.Framework.Providers.HUnit (testCase)
10−import qualified Test.HUnit as H
11+import qualified Test.HUnit as H
11−import qualified Data.Text.Lazy as TL
12−import qualified Data.Text.Lazy.Encoding as TL
13
12
14−import Hakyll.Core.Compiler
15−import Hakyll.Core.Resource.Provider.Dummy
16−import Hakyll.Core.UnixFilter
17−import TestSuite.Util
18
13
14+--------------------------------------------------------------------------------
15+import Hakyll.Core.Compiler
16+import Hakyll.Core.Item
17+import Hakyll.Core.UnixFilter
18+import TestSuite.Util
19+
20+
21+--------------------------------------------------------------------------------
19−tests :: [Test]
22+tests :: Test
20−tests =
23+tests = testGroup "Hakyll.Core.UnixFilter.Tests"
21 [ testCase "unixFilter rev" unixFilterRev
24 [ testCase "unixFilter rev" unixFilterRev
22 ]
25 ]
23
26
27+
28+--------------------------------------------------------------------------------
24unixFilterRev :: H.Assertion
29unixFilterRev :: H.Assertion
25−unixFilterRev = do
30+unixFilterRev = withTestStore $ \store -> do
26− provider <- dummyResourceProvider $ M.singleton "foo" $
31+ provider <- newTestProvider store
27− TL.encodeUtf8 $ TL.pack text
32+ output <- testCompilerDone store provider "russian.md" compiler
28− output <- runCompilerJobTest compiler "foo" provider ["foo"]
33+ expected <- testCompilerDone store provider "russian.md" getResourceString
29− H.assert $ rev text == lines output
34+ H.assert $ rev (itemBody expected) == lines (itemBody output)
30 where
35 where
31− compiler = getResource >>> getResourceString >>> unixFilter "rev" []
36+ compiler = getResourceString >>= itemM (unixFilter "rev" [])
32− rev = map reverse . lines
37+ rev = map reverse . lines
33−
34−text :: String
35−text = unlines
36− [ "Статья 18"
37− , ""
38− , "Каждый человек имеет право на свободу мысли, совести и религии; это"
39− , "право включает свободу менять свою религию или убеждения и свободу"
40− , "исповедовать свою религию или убеждения как единолично, так и сообща с"
41− , "другими, публичным или частным порядком в учении, богослужении и"
42− , "выполнении религиозных и ритуальных обрядов."
43− , ""
44− , "Статья 19"
45− , ""
46− , "Каждый человек имеет право на свободу убеждений и на свободное выражение"
47− , "их; это право включает свободу беспрепятственно придерживаться своих"
48− , "убеждений и свободу искать, получать и распространять информацию и идеи"
49− , "любыми средствами и независимо от государственных границ."
50− ]
tests/TestSuite.hs+7−1
@@ -5,12 +5,15 @@ module Main
5
5
6
6
7--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
8−import Test.Framework (defaultMain)
8+import Test.Framework (defaultMain)
9
9
10
10
11--------------------------------------------------------------------------------
11--------------------------------------------------------------------------------
12import qualified Hakyll.Core.Dependencies.Tests
12import qualified Hakyll.Core.Dependencies.Tests
13+import qualified Hakyll.Core.Identifier.Tests
13import qualified Hakyll.Core.Provider.Tests
14import qualified Hakyll.Core.Provider.Tests
15+import qualified Hakyll.Core.Store.Tests
16+import qualified Hakyll.Core.UnixFilter.Tests
14import qualified Hakyll.Web.Template.Tests
17import qualified Hakyll.Web.Template.Tests
15
18
16
19
@@ -18,6 +21,9 @@ import qualified Hakyll.Web.Template.Tests
18main :: IO ()
21main :: IO ()
19main = defaultMain
22main = defaultMain
20 [ Hakyll.Core.Dependencies.Tests.tests
23 [ Hakyll.Core.Dependencies.Tests.tests
24+ , Hakyll.Core.Identifier.Tests.tests
21 , Hakyll.Core.Provider.Tests.tests
25 , Hakyll.Core.Provider.Tests.tests
26+ , Hakyll.Core.Store.Tests.tests
27+ , Hakyll.Core.UnixFilter.Tests.tests
22 , Hakyll.Web.Template.Tests.tests
28 , Hakyll.Web.Template.Tests.tests
23 ]
29 ]
tests/TestSuite/Util.hs+14−2
@@ -2,6 +2,8 @@
2-- | Test utilities
2-- | Test utilities
3module TestSuite.Util
3module TestSuite.Util
4 ( fromAssertions
4 ( fromAssertions
5+ , newTestStore
6+ , cleanTestStore
5 , withTestStore
7 , withTestStore
6 , newTestProvider
8 , newTestProvider
7 , testCompiler
9 , testCompiler
@@ -35,12 +37,22 @@ fromAssertions name = zipWith testCase names
35 names = map (\n -> name ++ " [" ++ show n ++ "]") [1 :: Int ..]
37 names = map (\n -> name ++ " [" ++ show n ++ "]") [1 :: Int ..]
36
38
37
39
40+--------------------------------------------------------------------------------
41+newTestStore :: IO Store
42+newTestStore = Store.new True "_teststore"
43+
44+
45+--------------------------------------------------------------------------------
46+cleanTestStore :: IO ()
47+cleanTestStore = removeDirectoryRecursive "_teststore"
48+
49+
38--------------------------------------------------------------------------------
50--------------------------------------------------------------------------------
39withTestStore :: (Store -> IO a) -> IO a
51withTestStore :: (Store -> IO a) -> IO a
40withTestStore f = do
52withTestStore f = do
41− store <- Store.new True "_teststore"
53+ store <- newTestStore
42 result <- f store
54 result <- f store
43− removeDirectoryRecursive "_teststore"
55+ cleanTestStore
44 return result
56 return result
45
57
46
58
tests/data/russian.mdnew file+14
@@ -0,0 +1,14 @@
1+Статья 18
2+
3+Каждый человек имеет право на свободу мысли, совести и религии; это
4+право включает свободу менять свою религию или убеждения и свободу
5+исповедовать свою религию или убеждения как единолично, так и сообща с
6+другими, публичным или частным порядком в учении, богослужении и
7+выполнении религиозных и ритуальных обрядов.
8+
9+Статья 19
10+
11+Каждый человек имеет право на свободу убеждений и на свободное выражение
12+их; это право включает свободу беспрепятственно придерживаться своих
13+убеждений и свободу искать, получать и распространять информацию и идеи
14+любыми средствами и независимо от государственных границ.