summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Hakyll/Core/Store/Tests.hs81
-rw-r--r--tests/TestSuite/Util.hs5
2 files changed, 44 insertions, 42 deletions
diff --git a/tests/Hakyll/Core/Store/Tests.hs b/tests/Hakyll/Core/Store/Tests.hs
index 53ad74e..3188c30 100644
--- a/tests/Hakyll/Core/Store/Tests.hs
+++ b/tests/Hakyll/Core/Store/Tests.hs
@@ -1,67 +1,68 @@
+--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Store.Tests
( tests
) where
-import Control.Applicative ((<$>))
-import Control.Monad (replicateM)
-import Test.Framework
-import Test.Framework.Providers.QuickCheck2
-import Test.Framework.Providers.HUnit
-import Test.QuickCheck
-import Test.QuickCheck.Monadic
-import qualified Test.HUnit as H
+--------------------------------------------------------------------------------
+import Data.Typeable (typeOf)
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import Test.Framework.Providers.QuickCheck2
+import qualified Test.HUnit as H
+import Test.QuickCheck
+import Test.QuickCheck.Monadic
-import Hakyll.Core.Identifier
-import Hakyll.Core.Store
-import TestSuite.Util
+--------------------------------------------------------------------------------
+import qualified Hakyll.Core.Store as Store
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
tests :: [Test]
tests =
- [ testProperty "simple storeGet . storeSet" simpleSetGet
- , testProperty "persistent storeGet . storeSet" persistentSetGet
- , testCase "WrongType storeGet . storeSet" wrongType
+ [ testProperty "simple get . set" simpleSetGet
+ , testProperty "persistent get . set" persistentSetGet
+ , testCase "WrongType get . set" wrongType
]
+
+--------------------------------------------------------------------------------
simpleSetGet :: Property
simpleSetGet = monadicIO $ do
- identifier <- parseIdentifier . unFileName <$> pick arbitrary
- FileName name <- pick arbitrary
+ key <- pick arbitrary
value <- pick arbitrary
store <- run $ makeStoreTest
- run $ storeSet store name identifier (value :: String)
- value' <- run $ storeGet store name identifier
- assert $ Found value == value'
+ run $ Store.set store key (value :: String)
+ value' <- run $ Store.get store key
+ assert $ Store.Found value == value'
+
+--------------------------------------------------------------------------------
persistentSetGet :: Property
persistentSetGet = monadicIO $ do
- identifier <- parseIdentifier . unFileName <$> pick arbitrary
- FileName name <- pick arbitrary
- value <- pick arbitrary
+ key <- pick arbitrary
+ value <- pick arbitrary
store1 <- run $ makeStoreTest
- run $ storeSet store1 name identifier (value :: String)
+ run $ Store.set store1 key (value :: String)
-- Now Create another store from the same dir to test persistence
store2 <- run $ makeStoreTest
- value' <- run $ storeGet store2 name identifier
- assert $ Found value == value'
+ value' <- run $ Store.get store2 key
+ assert $ Store.Found value == value'
+
+--------------------------------------------------------------------------------
wrongType :: H.Assertion
wrongType = do
store <- makeStoreTest
-- Store a string and try to fetch an int
- storeSet store "foo" "bar" ("qux" :: String)
- value <- storeGet store "foo" "bar" :: IO (StoreGet Int)
- H.assert $ case value of WrongType _ _ -> True
- _ -> False
-
-newtype FileName = FileName {unFileName :: String}
- deriving (Show)
-
-instance Arbitrary FileName where
- arbitrary = do
- length' <- choose (5, 100)
- str <- replicateM length' $ elements cs
- return $ FileName str
- where
- cs = ['a' .. 'z'] ++ ['A' .. 'Z'] ++ ['0' .. '9'] ++ ".- "
+ Store.set store ["foo", "bar"] ("qux" :: String)
+ value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
+ print value
+ H.assert $ case value of
+ Store.WrongType e t ->
+ e == typeOf (undefined :: Int) &&
+ t == typeOf (undefined :: String)
+ _ -> False
diff --git a/tests/TestSuite/Util.hs b/tests/TestSuite/Util.hs
index aa34ab6..4fd87bf 100644
--- a/tests/TestSuite/Util.hs
+++ b/tests/TestSuite/Util.hs
@@ -16,7 +16,8 @@ import Hakyll.Core.Compiler.Internal
import Hakyll.Core.Identifier
import Hakyll.Core.Logger
import Hakyll.Core.Resource.Provider
-import Hakyll.Core.Store
+import Hakyll.Core.Store (Store)
+import qualified Hakyll.Core.Store as Store
fromAssertions :: String -- ^ Name
-> [Assertion] -- ^ Cases
@@ -28,7 +29,7 @@ fromAssertions name = zipWith testCase names
-- | Create a store for testing
--
makeStoreTest :: IO Store
-makeStoreTest = makeStore True "_store"
+makeStoreTest = Store.new True "_store"
-- | Testing for 'runCompilerJob'
--