blob: 9c231620331883d434c002d60ead1b47f7541d83 (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Runtime.Tests
( tests
) where
--------------------------------------------------------------------------------
import qualified Data.ByteString as B
import System.FilePath ((</>))
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (Assertion, (@?=))
--------------------------------------------------------------------------------
import Hakyll
import qualified Hakyll.Core.Logger as Logger
import Hakyll.Core.Runtime
import TestSuite.Util
--------------------------------------------------------------------------------
tests :: TestTree
tests = testGroup "Hakyll.Core.Runtime.Tests" $
fromAssertions "run" [case01, case02]
--------------------------------------------------------------------------------
case01 :: Assertion
case01 = do
logger <- Logger.new Logger.Error
_ <- run testConfiguration logger $ do
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "*.md" $ do
route $ setExtension "html"
compile $ do
getResourceBody
>>= saveSnapshot "raw"
>>= renderParagraphs
match (fromList ["partial.html", "partial-helper.html"]) $
compile templateCompiler
create ["partial.html.out"] $ do
route idRoute
compile $ do
example <- loadSnapshotBody "example.md" "raw"
makeItem example
>>= loadAndApplyTemplate "partial.html" defaultContext
create ["bodies.txt"] $ do
route idRoute
compile $ do
items <- loadAllSnapshots "*.md" "raw"
makeItem $ concat $ map itemBody (items :: [Item String])
favicon <- B.readFile $
providerDirectory testConfiguration </> "images/favicon.ico"
favicon' <- B.readFile $
destinationDirectory testConfiguration </> "images/favicon.ico"
favicon @?= favicon'
example <- readFile $
destinationDirectory testConfiguration </> "example.html"
lines example @?= ["<p>This is an example.</p>"]
bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
head (lines bodies) @?= "This is an example."
partial <- readFile $ providerDirectory testConfiguration </> "partial.html.out"
partial' <- readFile $ destinationDirectory testConfiguration </> "partial.html.out"
partial @?= partial'
cleanTestEnv
--------------------------------------------------------------------------------
case02 :: Assertion
case02 = do
logger <- Logger.new Logger.Error
_ <- run testConfiguration logger $ do
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
|