diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Hakyll/Core/Store/Tests.hs | 9 | ||||
-rw-r--r-- | tests/Hakyll/Core/UnixFilter/Tests.hs | 50 | ||||
-rw-r--r-- | tests/TestSuite.hs | 3 | ||||
-rw-r--r-- | tests/TestSuite/Util.hs | 28 |
4 files changed, 86 insertions, 4 deletions
diff --git a/tests/Hakyll/Core/Store/Tests.hs b/tests/Hakyll/Core/Store/Tests.hs index 4f35abd..53ad74e 100644 --- a/tests/Hakyll/Core/Store/Tests.hs +++ b/tests/Hakyll/Core/Store/Tests.hs @@ -15,6 +15,7 @@ import qualified Test.HUnit as H import Hakyll.Core.Identifier import Hakyll.Core.Store +import TestSuite.Util tests :: [Test] tests = @@ -28,7 +29,7 @@ simpleSetGet = monadicIO $ do identifier <- parseIdentifier . unFileName <$> pick arbitrary FileName name <- pick arbitrary value <- pick arbitrary - store <- run $ makeStore "_store" + store <- run $ makeStoreTest run $ storeSet store name identifier (value :: String) value' <- run $ storeGet store name identifier assert $ Found value == value' @@ -38,16 +39,16 @@ persistentSetGet = monadicIO $ do identifier <- parseIdentifier . unFileName <$> pick arbitrary FileName name <- pick arbitrary value <- pick arbitrary - store1 <- run $ makeStore "_store" + store1 <- run $ makeStoreTest run $ storeSet store1 name identifier (value :: String) -- Now Create another store from the same dir to test persistence - store2 <- run $ makeStore "_store" + store2 <- run $ makeStoreTest value' <- run $ storeGet store2 name identifier assert $ Found value == value' wrongType :: H.Assertion wrongType = do - store <- makeStore "_store" + 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) diff --git a/tests/Hakyll/Core/UnixFilter/Tests.hs b/tests/Hakyll/Core/UnixFilter/Tests.hs new file mode 100644 index 0000000..0e8d88d --- /dev/null +++ b/tests/Hakyll/Core/UnixFilter/Tests.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE OverloadedStrings #-} +module Hakyll.Core.UnixFilter.Tests + where + +import Control.Arrow ((>>>)) +import qualified Data.Map as M + +import Test.Framework (Test) +import Test.Framework.Providers.HUnit (testCase) +import qualified Test.HUnit as H +import qualified Data.Text.Lazy as TL +import qualified Data.Text.Lazy.Encoding as TL + +import Hakyll.Core.Compiler +import Hakyll.Core.Resource.Provider.Dummy +import Hakyll.Core.UnixFilter +import TestSuite.Util + +tests :: [Test] +tests = + [ testCase "unixFilter rev" unixFilterRev + ] + +unixFilterRev :: H.Assertion +unixFilterRev = do + provider <- dummyResourceProvider $ M.singleton "foo" $ + TL.encodeUtf8 $ TL.pack text + output <- runCompilerJobTest compiler "foo" provider ["foo"] + H.assert $ rev text == lines output + where + compiler = getResource >>> getResourceString >>> unixFilter "rev" [] + rev = map reverse . lines + +text :: String +text = unlines + [ "Статья 18" + , "" + , "Каждый человек имеет право на свободу мысли, совести и религии; это" + , "право включает свободу менять свою религию или убеждения и свободу" + , "исповедовать свою религию или убеждения как единолично, так и сообща с" + , "другими, публичным или частным порядком в учении, богослужении и" + , "выполнении религиозных и ритуальных обрядов." + , "" + , "Статья 19" + , "" + , "Каждый человек имеет право на свободу убеждений и на свободное выражение" + , "их; это право включает свободу беспрепятственно придерживаться своих" + , "убеждений и свободу искать, получать и распространять информацию и идеи" + , "любыми средствами и независимо от государственных границ." + ] diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs index e459529..fe9012d 100644 --- a/tests/TestSuite.hs +++ b/tests/TestSuite.hs @@ -7,6 +7,7 @@ import qualified Hakyll.Core.Identifier.Tests import qualified Hakyll.Core.Routes.Tests import qualified Hakyll.Core.Rules.Tests import qualified Hakyll.Core.Store.Tests +import qualified Hakyll.Core.UnixFilter.Tests import qualified Hakyll.Web.Page.Tests import qualified Hakyll.Web.Page.Metadata.Tests import qualified Hakyll.Web.RelativizeUrls.Tests @@ -25,6 +26,8 @@ main = defaultMain Hakyll.Core.Rules.Tests.tests , testGroup "Hakyll.Core.Store.Tests" Hakyll.Core.Store.Tests.tests + , testGroup "Hakyll.Core.UnixFilter.Tests" + Hakyll.Core.UnixFilter.Tests.tests , testGroup "Hakyll.Web.Page.Tests" Hakyll.Web.Page.Tests.tests , testGroup "Hakyll.Web.Page.Metadata.Tests" diff --git a/tests/TestSuite/Util.hs b/tests/TestSuite/Util.hs index f32bcad..d82b280 100644 --- a/tests/TestSuite/Util.hs +++ b/tests/TestSuite/Util.hs @@ -2,15 +2,43 @@ -- module TestSuite.Util ( fromAssertions + , makeStoreTest + , runCompilerJobTest ) where +import Data.Monoid (mempty) + import Test.Framework import Test.Framework.Providers.HUnit import Test.HUnit hiding (Test) +import Hakyll.Core.Compiler.Internal +import Hakyll.Core.Identifier +import Hakyll.Core.Logger +import Hakyll.Core.Resource.Provider +import Hakyll.Core.Store + fromAssertions :: String -- ^ Name -> [Assertion] -- ^ Cases -> [Test] -- ^ Result tests fromAssertions name = zipWith testCase names where names = map (\n -> name ++ " [" ++ show n ++ "]") [1 :: Int ..] + +-- | Create a store for testing +-- +makeStoreTest :: IO Store +makeStoreTest = makeStore "_store" + +-- | Testing for 'runCompilerJob' +-- +runCompilerJobTest :: Compiler () a + -> Identifier + -> ResourceProvider + -> [Identifier] + -> IO a +runCompilerJobTest compiler id' provider uni = do + store <- makeStoreTest + logger <- makeLogger $ const $ return () + Right x <- runCompilerJob compiler id' provider uni mempty store True logger + return x |