on master help sign in
Add a runtime test
commitc32e57262b1c4544c323ea04c21608aef1126765 authorJasper Van der Jeugt <m@jaspervdj.be> dateWed 21 Nov 2012, 20:38 (14 years ago) parent6b4c656
6 files changed+73−7
hakyll.cabal+6 src/Hakyll/Core/Configuration.hs+4 src/Hakyll/Core/Runtime.hs+4−5 tests/Hakyll/Core/Runtime/Tests.hs+37 tests/TestSuite.hs+4−2 tests/TestSuite/Util.hs+18
hakyll.cabal+6
@@ -200,6 +200,12 @@ Test-suite hakyll-tests
200200
201201 Other-modules:
202202 Hakyll.Core.Dependencies.Tests
203+ Hakyll.Core.Identifier.Tests
203204 Hakyll.Core.Provider.Tests
205+ Hakyll.Core.Runtime.Tests
206+ Hakyll.Core.Store.Tests
207+ Hakyll.Core.UnixFilter.Tests
204208 Hakyll.Web.Template.Tests
209+ Hakyll.Web.Urls.Tests
210+ Hakyll.Web.Urls.Relativize.Tests
205211 TestSuite.Util
src/Hakyll/Core/Configuration.hs+4
@@ -18,6 +18,9 @@ data Configuration = Configuration
1818 destinationDirectory :: FilePath
1919 , -- | Directory where hakyll's internal store is kept
2020 storeDirectory :: FilePath
21+ , -- | Directory where hakyll finds the files to compile. This is @.@ by
22+ -- default.
23+ providerDirectory :: FilePath
2124 , -- | Function to determine ignored files
2225 --
2326 -- In 'defaultHakyllConfiguration', the following files are ignored:
@@ -58,6 +61,7 @@ defaultConfiguration :: Configuration
5861defaultConfiguration = Configuration
5962 { destinationDirectory = "_site"
6063 , storeDirectory = "_cache"
64+ , providerDirectory = "."
6165 , ignoreFile = ignoreFile'
6266 , deployCommand = "echo 'No deploy command specified'"
6367 , inMemoryCache = True
src/Hakyll/Core/Runtime.hs+4−5
@@ -42,15 +42,14 @@ import Hakyll.Core.Writable
4242
4343--------------------------------------------------------------------------------
4444run :: Configuration -> Rules a -> IO RuleSet
45−run configuration rules = do
45+run config rules = do
4646 -- Initialization
4747 logger <- Logger.new Logger.Debug putStrLn
4848 Logger.header logger "Initialising..."
4949 Logger.message logger "Creating store..."
50− store <- Store.new (inMemoryCache configuration) $
51− storeDirectory configuration
50+ store <- Store.new (inMemoryCache config) $ storeDirectory config
5251 Logger.message logger "Creating provider..."
53− provider <- newProvider store (ignoreFile configuration) "."
52+ provider <- newProvider store (ignoreFile config) $ providerDirectory config
5453 Logger.message logger "Running rules..."
5554 ruleSet <- runRules rules provider
5655
@@ -62,7 +61,7 @@ run configuration rules = do
6261 -- Build runtime read/state
6362 let compilers = rulesCompilers ruleSet
6463 read' = RuntimeRead
65− { runtimeConfiguration = configuration
64+ { runtimeConfiguration = config
6665 , runtimeLogger = logger
6766 , runtimeProvider = provider
6867 , 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
55
66
77--------------------------------------------------------------------------------
8−import Test.Framework (defaultMain)
8+import Test.Framework (defaultMain)
99
1010
1111--------------------------------------------------------------------------------
1212import qualified Hakyll.Core.Dependencies.Tests
1313import qualified Hakyll.Core.Identifier.Tests
1414import qualified Hakyll.Core.Provider.Tests
15+import qualified Hakyll.Core.Runtime.Tests
1516import qualified Hakyll.Core.Store.Tests
1617import qualified Hakyll.Core.UnixFilter.Tests
1718import qualified Hakyll.Web.Template.Tests
18−import qualified Hakyll.Web.Urls.Tests
1919import qualified Hakyll.Web.Urls.Relativize.Tests
20+import qualified Hakyll.Web.Urls.Tests
2021
2122
2223--------------------------------------------------------------------------------
@@ -25,6 +26,7 @@ main = defaultMain
2526 [ Hakyll.Core.Dependencies.Tests.tests
2627 , Hakyll.Core.Identifier.Tests.tests
2728 , Hakyll.Core.Provider.Tests.tests
29+ , Hakyll.Core.Runtime.Tests.tests
2830 , Hakyll.Core.Store.Tests.tests
2931 , Hakyll.Core.UnixFilter.Tests.tests
3032 , Hakyll.Web.Template.Tests.tests
tests/TestSuite/Util.hs+18
@@ -8,6 +8,7 @@ module TestSuite.Util
88 , newTestProvider
99 , testCompiler
1010 , testCompilerDone
11+ , withTestConfiguration
1112 ) where
1213
1314
@@ -22,6 +23,7 @@ import Text.Printf (printf)
2223
2324--------------------------------------------------------------------------------
2425import Hakyll.Core.Compiler.Internal
26+import Hakyll.Core.Configuration
2527import Hakyll.Core.Identifier
2628import qualified Hakyll.Core.Logger as Logger
2729import Hakyll.Core.Provider
@@ -92,3 +94,19 @@ testCompilerDone store provider underlying compiler = do
9294 CompilerRequire i _ -> error $
9395 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
9496 " 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+ }