on master help sign in
Add a runtime test
c32e572Jasper Van der Jeugt
hakyll.cabal+6
@@ -200,6 +200,12 @@ Test-suite hakyll-tests
200
200
201 Other-modules:
201 Other-modules:
202 Hakyll.Core.Dependencies.Tests
202 Hakyll.Core.Dependencies.Tests
203+ Hakyll.Core.Identifier.Tests
203 Hakyll.Core.Provider.Tests
204 Hakyll.Core.Provider.Tests
205+ Hakyll.Core.Runtime.Tests
206+ Hakyll.Core.Store.Tests
207+ Hakyll.Core.UnixFilter.Tests
204 Hakyll.Web.Template.Tests
208 Hakyll.Web.Template.Tests
209+ Hakyll.Web.Urls.Tests
210+ Hakyll.Web.Urls.Relativize.Tests
205 TestSuite.Util
211 TestSuite.Util
src/Hakyll/Core/Configuration.hs+4
@@ -18,6 +18,9 @@ data Configuration = Configuration
18 destinationDirectory :: FilePath
18 destinationDirectory :: FilePath
19 , -- | Directory where hakyll's internal store is kept
19 , -- | Directory where hakyll's internal store is kept
20 storeDirectory :: FilePath
20 storeDirectory :: FilePath
21+ , -- | Directory where hakyll finds the files to compile. This is @.@ by
22+ -- default.
23+ providerDirectory :: FilePath
21 , -- | Function to determine ignored files
24 , -- | Function to determine ignored files
22 --
25 --
23 -- In 'defaultHakyllConfiguration', the following files are ignored:
26 -- In 'defaultHakyllConfiguration', the following files are ignored:
@@ -58,6 +61,7 @@ defaultConfiguration :: Configuration
58defaultConfiguration = Configuration
61defaultConfiguration = Configuration
59 { destinationDirectory = "_site"
62 { destinationDirectory = "_site"
60 , storeDirectory = "_cache"
63 , storeDirectory = "_cache"
64+ , providerDirectory = "."
61 , ignoreFile = ignoreFile'
65 , ignoreFile = ignoreFile'
62 , deployCommand = "echo 'No deploy command specified'"
66 , deployCommand = "echo 'No deploy command specified'"
63 , inMemoryCache = True
67 , inMemoryCache = True
src/Hakyll/Core/Runtime.hs+4−5
@@ -42,15 +42,14 @@ import Hakyll.Core.Writable
42
42
43--------------------------------------------------------------------------------
43--------------------------------------------------------------------------------
44run :: Configuration -> Rules a -> IO RuleSet
44run :: Configuration -> Rules a -> IO RuleSet
45−run configuration rules = do
45+run config rules = do
46 -- Initialization
46 -- Initialization
47 logger <- Logger.new Logger.Debug putStrLn
47 logger <- Logger.new Logger.Debug putStrLn
48 Logger.header logger "Initialising..."
48 Logger.header logger "Initialising..."
49 Logger.message logger "Creating store..."
49 Logger.message logger "Creating store..."
50− store <- Store.new (inMemoryCache configuration) $
50+ store <- Store.new (inMemoryCache config) $ storeDirectory config
51− storeDirectory configuration
52 Logger.message logger "Creating provider..."
51 Logger.message logger "Creating provider..."
53− provider <- newProvider store (ignoreFile configuration) "."
52+ provider <- newProvider store (ignoreFile config) $ providerDirectory config
54 Logger.message logger "Running rules..."
53 Logger.message logger "Running rules..."
55 ruleSet <- runRules rules provider
54 ruleSet <- runRules rules provider
56
55
@@ -62,7 +61,7 @@ run configuration rules = do
62 -- Build runtime read/state
61 -- Build runtime read/state
63 let compilers = rulesCompilers ruleSet
62 let compilers = rulesCompilers ruleSet
64 read' = RuntimeRead
63 read' = RuntimeRead
65− { runtimeConfiguration = configuration
64+ { runtimeConfiguration = config
66 , runtimeLogger = logger
65 , runtimeLogger = logger
67 , runtimeProvider = provider
66 , runtimeProvider = provider
68 , runtimeStore = store
67 , runtimeStore = store
tests/Hakyll/Core/Runtime/Tests.hsnew file+37
@@ -0,0 +1,37 @@
1+--------------------------------------------------------------------------------
2+{-# LANGUAGE OverloadedStrings #-}
3+module Hakyll.Core.Runtime.Tests
4+ ( tests
5+ ) where
6+
7+
8+--------------------------------------------------------------------------------
9+import System.FilePath ((</>))
10+import Test.Framework (Test, testGroup)
11+import Test.HUnit (Assertion, (@?=))
12+
13+
14+--------------------------------------------------------------------------------
15+import Hakyll.Core.Configuration
16+import Hakyll.Core.Routes
17+import Hakyll.Core.Rules
18+import Hakyll.Core.Runtime
19+import Hakyll.Web.Page
20+import TestSuite.Util
21+
22+
23+--------------------------------------------------------------------------------
24+tests :: Test
25+tests = testGroup "Hakyll.Core.Runtime.Tests" $ fromAssertions "run" [case01]
26+
27+
28+--------------------------------------------------------------------------------
29+case01 :: Assertion
30+case01 = withTestConfiguration $ \config -> do
31+ _ <- run config $ do
32+ match "*.md" $ do
33+ route $ setExtension "html"
34+ compile $ pageCompiler
35+
36+ out <- readFile $ destinationDirectory config </> "example.html"
37+ lines out @?= ["<p>This is an example.</p>"]
tests/TestSuite.hs+4−2
@@ -5,18 +5,19 @@ module Main
5
5
6
6
7--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
8−import Test.Framework (defaultMain)
8+import Test.Framework (defaultMain)
9
9
10
10
11--------------------------------------------------------------------------------
11--------------------------------------------------------------------------------
12import qualified Hakyll.Core.Dependencies.Tests
12import qualified Hakyll.Core.Dependencies.Tests
13import qualified Hakyll.Core.Identifier.Tests
13import qualified Hakyll.Core.Identifier.Tests
14import qualified Hakyll.Core.Provider.Tests
14import qualified Hakyll.Core.Provider.Tests
15+import qualified Hakyll.Core.Runtime.Tests
15import qualified Hakyll.Core.Store.Tests
16import qualified Hakyll.Core.Store.Tests
16import qualified Hakyll.Core.UnixFilter.Tests
17import qualified Hakyll.Core.UnixFilter.Tests
17import qualified Hakyll.Web.Template.Tests
18import qualified Hakyll.Web.Template.Tests
18−import qualified Hakyll.Web.Urls.Tests
19import qualified Hakyll.Web.Urls.Relativize.Tests
19import qualified Hakyll.Web.Urls.Relativize.Tests
20+import qualified Hakyll.Web.Urls.Tests
20
21
21
22
22--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
@@ -25,6 +26,7 @@ main = defaultMain
25 [ Hakyll.Core.Dependencies.Tests.tests
26 [ Hakyll.Core.Dependencies.Tests.tests
26 , Hakyll.Core.Identifier.Tests.tests
27 , Hakyll.Core.Identifier.Tests.tests
27 , Hakyll.Core.Provider.Tests.tests
28 , Hakyll.Core.Provider.Tests.tests
29+ , Hakyll.Core.Runtime.Tests.tests
28 , Hakyll.Core.Store.Tests.tests
30 , Hakyll.Core.Store.Tests.tests
29 , Hakyll.Core.UnixFilter.Tests.tests
31 , Hakyll.Core.UnixFilter.Tests.tests
30 , Hakyll.Web.Template.Tests.tests
32 , Hakyll.Web.Template.Tests.tests
tests/TestSuite/Util.hs+18
@@ -8,6 +8,7 @@ module TestSuite.Util
8 , newTestProvider
8 , newTestProvider
9 , testCompiler
9 , testCompiler
10 , testCompilerDone
10 , testCompilerDone
11+ , withTestConfiguration
11 ) where
12 ) where
12
13
13
14
@@ -22,6 +23,7 @@ import Text.Printf (printf)
22
23
23--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
24import Hakyll.Core.Compiler.Internal
25import Hakyll.Core.Compiler.Internal
26+import Hakyll.Core.Configuration
25import Hakyll.Core.Identifier
27import Hakyll.Core.Identifier
26import qualified Hakyll.Core.Logger as Logger
28import qualified Hakyll.Core.Logger as Logger
27import Hakyll.Core.Provider
29import Hakyll.Core.Provider
@@ -92,3 +94,19 @@ testCompilerDone store provider underlying compiler = do
92 CompilerRequire i _ -> error $
94 CompilerRequire i _ -> error $
93 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
95 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
94 " requires: " ++ show i
96 " requires: " ++ show i
97+
98+
99+
100+--------------------------------------------------------------------------------
101+withTestConfiguration :: (Configuration -> IO a) -> IO a
102+withTestConfiguration f = do
103+ x <- f config
104+ removeDirectoryRecursive $ destinationDirectory config
105+ removeDirectoryRecursive $ storeDirectory config
106+ return x
107+ where
108+ config = defaultConfiguration
109+ { destinationDirectory = "_testsite"
110+ , storeDirectory = "_teststore"
111+ , providerDirectory = "tests/data"
112+ }