summaryrefslogtreecommitdiff
path: root/tests/TestSuite/Util.hs
blob: 50688ae5c253c031564f8d2731923da5599a50aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- | Test utilities
--
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