hakyll/tests/Hakyll/Core/Runtime/Tests.hs

84 lines
2.6 KiB
Haskell
Raw Normal View History

2012-11-21 19:38:13 +00:00
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Runtime.Tests
( tests
) where
--------------------------------------------------------------------------------
2013-03-07 17:41:00 +00:00
import qualified Data.ByteString as B
2012-11-24 09:56:19 +00:00
import System.FilePath ((</>))
import Test.Framework (Test, testGroup)
import Test.HUnit (Assertion, (@?=))
2012-11-21 19:38:13 +00:00
--------------------------------------------------------------------------------
2012-11-24 09:56:19 +00:00
import Hakyll
2012-12-31 14:16:14 +00:00
import qualified Hakyll.Core.Logger as Logger
2012-11-21 19:38:13 +00:00
import Hakyll.Core.Runtime
import TestSuite.Util
--------------------------------------------------------------------------------
tests :: Test
2013-02-16 11:59:38 +00:00
tests = testGroup "Hakyll.Core.Runtime.Tests" $
fromAssertions "run" [case01, case02]
2012-11-21 19:38:13 +00:00
--------------------------------------------------------------------------------
case01 :: Assertion
2013-01-06 17:33:00 +00:00
case01 = do
logger <- Logger.new Logger.Error
_ <- run testConfiguration logger $ do
2013-03-07 17:41:00 +00:00
match "images/*" $ do
route idRoute
compile copyFileCompiler
2012-11-21 19:38:13 +00:00
match "*.md" $ do
route $ setExtension "html"
2012-11-24 09:56:19 +00:00
compile $ do
2012-12-30 08:50:02 +00:00
getResourceBody
>>= saveSnapshot "raw"
2015-05-29 09:52:36 +00:00
>>= renderPandoc
2012-11-21 19:38:13 +00:00
2013-01-06 08:51:09 +00:00
create ["bodies.txt"] $ do
2012-11-24 12:34:50 +00:00
route idRoute
compile $ do
items <- loadAllSnapshots "*.md" "raw"
2012-11-24 12:34:50 +00:00
makeItem $ concat $ map itemBody (items :: [Item String])
2012-11-24 09:56:19 +00:00
2013-03-07 17:41:00 +00:00
favicon <- B.readFile $
providerDirectory testConfiguration </> "images/favicon.ico"
favicon' <- B.readFile $
destinationDirectory testConfiguration </> "images/favicon.ico"
favicon @?= favicon'
2013-01-06 17:33:00 +00:00
example <- readFile $
destinationDirectory testConfiguration </> "example.html"
2012-11-24 09:56:19 +00:00
lines example @?= ["<p>This is an example.</p>"]
2013-01-06 17:33:00 +00:00
bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
2012-11-24 09:56:19 +00:00
head (lines bodies) @?= "This is an example."
2013-01-06 17:33:00 +00:00
cleanTestEnv
2013-02-16 11:59:38 +00:00
--------------------------------------------------------------------------------
case02 :: Assertion
case02 = do
logger <- Logger.new Logger.Error
_ <- run testConfiguration logger $ do
2013-02-16 11:59:38 +00:00
match "images/favicon.ico" $ do
route $ gsubRoute "images/" (const "")
compile $ makeItem ("Test" :: String)
match "images/**" $ do
route idRoute
compile copyFileCompiler
favicon <- readFile $
destinationDirectory testConfiguration </> "favicon.ico"
favicon @?= "Test"
cleanTestEnv