summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-21 20:38:13 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-21 20:38:13 +0100
commitc32e57262b1c4544c323ea04c21608aef1126765 (patch)
treeaa9a2375586a30014d617bf5836faceda699f03e /tests
parent6b4c65642e21684bc143eaf29453d1d99fd9e227 (diff)
downloadhakyll-c32e57262b1c4544c323ea04c21608aef1126765.tar.gz
Add a runtime test
Diffstat (limited to 'tests')
-rw-r--r--tests/Hakyll/Core/Runtime/Tests.hs37
-rw-r--r--tests/TestSuite.hs6
-rw-r--r--tests/TestSuite/Util.hs18
3 files changed, 59 insertions, 2 deletions
diff --git a/tests/Hakyll/Core/Runtime/Tests.hs b/tests/Hakyll/Core/Runtime/Tests.hs
new file mode 100644
index 0000000..bb39a5f
--- /dev/null
+++ b/tests/Hakyll/Core/Runtime/Tests.hs
@@ -0,0 +1,37 @@
+--------------------------------------------------------------------------------
+{-# LANGUAGE OverloadedStrings #-}
+module Hakyll.Core.Runtime.Tests
+ ( tests
+ ) where
+
+
+--------------------------------------------------------------------------------
+import System.FilePath ((</>))
+import Test.Framework (Test, testGroup)
+import Test.HUnit (Assertion, (@?=))
+
+
+--------------------------------------------------------------------------------
+import Hakyll.Core.Configuration
+import Hakyll.Core.Routes
+import Hakyll.Core.Rules
+import Hakyll.Core.Runtime
+import Hakyll.Web.Page
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
+tests :: Test
+tests = testGroup "Hakyll.Core.Runtime.Tests" $ fromAssertions "run" [case01]
+
+
+--------------------------------------------------------------------------------
+case01 :: Assertion
+case01 = withTestConfiguration $ \config -> do
+ _ <- run config $ do
+ match "*.md" $ do
+ route $ setExtension "html"
+ compile $ pageCompiler
+
+ out <- readFile $ destinationDirectory config </> "example.html"
+ lines out @?= ["<p>This is an example.</p>"]
diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs
index b783d7a..0476869 100644
--- a/tests/TestSuite.hs
+++ b/tests/TestSuite.hs
@@ -5,18 +5,19 @@ module Main
--------------------------------------------------------------------------------
-import Test.Framework (defaultMain)
+import Test.Framework (defaultMain)
--------------------------------------------------------------------------------
import qualified Hakyll.Core.Dependencies.Tests
import qualified Hakyll.Core.Identifier.Tests
import qualified Hakyll.Core.Provider.Tests
+import qualified Hakyll.Core.Runtime.Tests
import qualified Hakyll.Core.Store.Tests
import qualified Hakyll.Core.UnixFilter.Tests
import qualified Hakyll.Web.Template.Tests
-import qualified Hakyll.Web.Urls.Tests
import qualified Hakyll.Web.Urls.Relativize.Tests
+import qualified Hakyll.Web.Urls.Tests
--------------------------------------------------------------------------------
@@ -25,6 +26,7 @@ main = defaultMain
[ Hakyll.Core.Dependencies.Tests.tests
, Hakyll.Core.Identifier.Tests.tests
, Hakyll.Core.Provider.Tests.tests
+ , Hakyll.Core.Runtime.Tests.tests
, Hakyll.Core.Store.Tests.tests
, Hakyll.Core.UnixFilter.Tests.tests
, Hakyll.Web.Template.Tests.tests
diff --git a/tests/TestSuite/Util.hs b/tests/TestSuite/Util.hs
index 5d62ffc..8f0911d 100644
--- a/tests/TestSuite/Util.hs
+++ b/tests/TestSuite/Util.hs
@@ -8,6 +8,7 @@ module TestSuite.Util
, newTestProvider
, testCompiler
, testCompilerDone
+ , withTestConfiguration
) where
@@ -22,6 +23,7 @@ import Text.Printf (printf)
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler.Internal
+import Hakyll.Core.Configuration
import Hakyll.Core.Identifier
import qualified Hakyll.Core.Logger as Logger
import Hakyll.Core.Provider
@@ -92,3 +94,19 @@ testCompilerDone store provider underlying compiler = do
CompilerRequire i _ -> error $
"TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
" requires: " ++ show i
+
+
+
+--------------------------------------------------------------------------------
+withTestConfiguration :: (Configuration -> IO a) -> IO a
+withTestConfiguration f = do
+ x <- f config
+ removeDirectoryRecursive $ destinationDirectory config
+ removeDirectoryRecursive $ storeDirectory config
+ return x
+ where
+ config = defaultConfiguration
+ { destinationDirectory = "_testsite"
+ , storeDirectory = "_teststore"
+ , providerDirectory = "tests/data"
+ }