summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-01-06 18:33:00 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2013-01-06 18:33:00 +0100
commitbbc2631c76db01e85ac5c4e75b1babb6c5b05697 (patch)
tree331dda3a0f45efee866db2a03fb5aa2858e826a8 /tests
parente477ea753b59657ba8d185986c646cc45c66fcec (diff)
downloadhakyll-bbc2631c76db01e85ac5c4e75b1babb6c5b05697.tar.gz
Add TmpFile utilities
Diffstat (limited to 'tests')
-rw-r--r--tests/Hakyll/Core/Provider/Tests.hs3
-rw-r--r--tests/Hakyll/Core/Rules/Tests.hs5
-rw-r--r--tests/Hakyll/Core/Runtime/Tests.hs11
-rw-r--r--tests/Hakyll/Core/Store/Tests.hs7
-rw-r--r--tests/Hakyll/Core/UnixFilter/Tests.hs4
-rw-r--r--tests/Hakyll/Web/Template/Context/Tests.hs5
-rw-r--r--tests/Hakyll/Web/Template/Tests.hs6
-rw-r--r--tests/TestSuite/Util.hs56
8 files changed, 50 insertions, 47 deletions
diff --git a/tests/Hakyll/Core/Provider/Tests.hs b/tests/Hakyll/Core/Provider/Tests.hs
index e1f9083..5fd9c0d 100644
--- a/tests/Hakyll/Core/Provider/Tests.hs
+++ b/tests/Hakyll/Core/Provider/Tests.hs
@@ -26,7 +26,8 @@ tests = testGroup "Hakyll.Core.Provider.Tests"
--------------------------------------------------------------------------------
case01 :: Assertion
-case01 = withTestStore $ \store -> do
+case01 = do
+ store <- newTestStore
provider <- newTestProvider store
assert $ resourceExists provider "example.md"
diff --git a/tests/Hakyll/Core/Rules/Tests.hs b/tests/Hakyll/Core/Rules/Tests.hs
index d6fec31..631e082 100644
--- a/tests/Hakyll/Core/Rules/Tests.hs
+++ b/tests/Hakyll/Core/Rules/Tests.hs
@@ -14,12 +14,12 @@ import Test.HUnit (Assertion, assert, (@=?))
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
+import Hakyll.Core.File
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
import Hakyll.Core.Routes
import Hakyll.Core.Rules
import Hakyll.Core.Rules.Internal
-import Hakyll.Core.Writable.CopyFile
import Hakyll.Web.Pandoc
import TestSuite.Util
@@ -33,7 +33,8 @@ tests = testGroup "Hakyll.Core.Rules.Tests"
--------------------------------------------------------------------------------
rulesTest :: Assertion
-rulesTest = withTestStore $ \store -> do
+rulesTest = do
+ store <- newTestStore
provider <- newTestProvider store
ruleSet <- runRules rules provider
let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
diff --git a/tests/Hakyll/Core/Runtime/Tests.hs b/tests/Hakyll/Core/Runtime/Tests.hs
index 4b41bf5..c68d99e 100644
--- a/tests/Hakyll/Core/Runtime/Tests.hs
+++ b/tests/Hakyll/Core/Runtime/Tests.hs
@@ -25,8 +25,8 @@ tests = testGroup "Hakyll.Core.Runtime.Tests" $ fromAssertions "run" [case01]
--------------------------------------------------------------------------------
case01 :: Assertion
-case01 = withTestConfiguration $ \config -> do
- _ <- run config Logger.Error $ do
+case01 = do
+ _ <- run testConfiguration Logger.Error $ do
match "*.md" $ do
route $ setExtension "html"
compile $ do
@@ -40,8 +40,11 @@ case01 = withTestConfiguration $ \config -> do
items <- loadAllSnapshots "*.md" "raw"
makeItem $ concat $ map itemBody (items :: [Item String])
- example <- readFile $ destinationDirectory config </> "example.html"
+ example <- readFile $
+ destinationDirectory testConfiguration </> "example.html"
lines example @?= ["<p>This is an example.</p>"]
- bodies <- readFile $ destinationDirectory config </> "bodies.txt"
+ bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
head (lines bodies) @?= "This is an example."
+
+ cleanTestEnv
diff --git a/tests/Hakyll/Core/Store/Tests.hs b/tests/Hakyll/Core/Store/Tests.hs
index 11a1a63..19b268b 100644
--- a/tests/Hakyll/Core/Store/Tests.hs
+++ b/tests/Hakyll/Core/Store/Tests.hs
@@ -38,7 +38,7 @@ simpleSetGet = Q.monadicIO $ do
Q.run $ Store.set store key (value :: String)
value' <- Q.run $ Store.get store key
Q.assert $ Store.Found value == value'
- Q.run cleanTestStore
+ Q.run cleanTestEnv
--------------------------------------------------------------------------------
@@ -52,12 +52,13 @@ persistentSetGet = Q.monadicIO $ do
store2 <- Q.run newTestStore
value' <- Q.run $ Store.get store2 key
Q.assert $ Store.Found value == value'
- Q.run cleanTestStore
+ Q.run cleanTestEnv
--------------------------------------------------------------------------------
wrongType :: H.Assertion
-wrongType = withTestStore $ \store -> do
+wrongType = do
+ store <- newTestStore
-- Store a string and try to fetch an int
Store.set store ["foo", "bar"] ("qux" :: String)
value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
diff --git a/tests/Hakyll/Core/UnixFilter/Tests.hs b/tests/Hakyll/Core/UnixFilter/Tests.hs
index c3e1c99..350c857 100644
--- a/tests/Hakyll/Core/UnixFilter/Tests.hs
+++ b/tests/Hakyll/Core/UnixFilter/Tests.hs
@@ -27,11 +27,13 @@ tests = testGroup "Hakyll.Core.UnixFilter.Tests"
--------------------------------------------------------------------------------
unixFilterRev :: H.Assertion
-unixFilterRev = withTestStore $ \store -> do
+unixFilterRev = do
+ store <- newTestStore
provider <- newTestProvider store
output <- testCompilerDone store provider "russian.md" compiler
expected <- testCompilerDone store provider "russian.md" getResourceString
H.assert $ rev (itemBody expected) == lines (itemBody output)
+ cleanTestEnv
where
compiler = getResourceString >>= withItemBody (unixFilter "rev" [])
rev = map reverse . lines
diff --git a/tests/Hakyll/Web/Template/Context/Tests.hs b/tests/Hakyll/Web/Template/Context/Tests.hs
index f2fb42a..5533c71 100644
--- a/tests/Hakyll/Web/Template/Context/Tests.hs
+++ b/tests/Hakyll/Web/Template/Context/Tests.hs
@@ -29,7 +29,8 @@ tests = testGroup "Hakyll.Core.Template.Context.Tests"
--------------------------------------------------------------------------------
testDateField :: Assertion
-testDateField = withTestStore $ \store -> do
+testDateField = do
+ store <- newTestStore
provider <- newTestProvider store
date1 <- testContextDone store provider "example.md" "date" $
@@ -41,6 +42,8 @@ testDateField = withTestStore $ \store -> do
dateField "date" "%B %e, %Y"
date2 @=? "August 26, 2010"
+ cleanTestEnv
+
--------------------------------------------------------------------------------
testContextDone :: Store -> Provider -> Identifier -> String
diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs
index 6c5c77a..fce5503 100644
--- a/tests/Hakyll/Web/Template/Tests.hs
+++ b/tests/Hakyll/Web/Template/Tests.hs
@@ -30,11 +30,13 @@ tests = testGroup "Hakyll.Core.Template.Tests"
--------------------------------------------------------------------------------
case01 :: Assertion
-case01 = withTestStore $ \store -> do
+case01 = do
+ store <- newTestStore
provider <- newTestProvider store
out <- resourceString provider "template.html.out"
- tpl <- testCompilerDone store provider "template.html" $ templateCompiler
+ tpl <- testCompilerDone store provider "template.html" $
+ templateCompiler
item <- testCompilerDone store provider "example.md" $
pandocCompiler >>= applyTemplate (itemBody tpl) testContext
diff --git a/tests/TestSuite/Util.hs b/tests/TestSuite/Util.hs
index 91f4339..6cef730 100644
--- a/tests/TestSuite/Util.hs
+++ b/tests/TestSuite/Util.hs
@@ -3,19 +3,17 @@
module TestSuite.Util
( fromAssertions
, newTestStore
- , cleanTestStore
- , withTestStore
, newTestProvider
, testCompiler
, testCompilerDone
- , withTestConfiguration
+ , testConfiguration
+ , cleanTestEnv
) where
--------------------------------------------------------------------------------
import Data.Monoid (mempty)
import qualified Data.Set as S
-import System.Directory (removeDirectoryRecursive)
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
@@ -30,6 +28,7 @@ import qualified Hakyll.Core.Logger as Logger
import Hakyll.Core.Provider
import Hakyll.Core.Store (Store)
import qualified Hakyll.Core.Store as Store
+import Hakyll.Core.Util.File
--------------------------------------------------------------------------------
@@ -42,26 +41,13 @@ fromAssertions name =
--------------------------------------------------------------------------------
newTestStore :: IO Store
-newTestStore = Store.new True "_teststore"
-
-
---------------------------------------------------------------------------------
-cleanTestStore :: IO ()
-cleanTestStore = removeDirectoryRecursive "_teststore"
-
-
---------------------------------------------------------------------------------
-withTestStore :: (Store -> IO a) -> IO a
-withTestStore f = do
- store <- newTestStore
- result <- f store
- cleanTestStore
- return result
+newTestStore = Store.new True $ storeDirectory testConfiguration
--------------------------------------------------------------------------------
newTestProvider :: Store -> IO Provider
-newTestProvider store = newProvider store (const False) "tests/data"
+newTestProvider store = newProvider store (const False) $
+ providerDirectory testConfiguration
--------------------------------------------------------------------------------
@@ -70,7 +56,8 @@ testCompiler :: Store -> Provider -> Identifier -> Compiler a
testCompiler store provider underlying compiler = do
logger <- Logger.new Logger.Error
let read' = CompilerRead
- { compilerUnderlying = underlying
+ { compilerConfig = testConfiguration
+ , compilerUnderlying = underlying
, compilerProvider = provider
, compilerUniverse = S.empty
, compilerRoutes = mempty
@@ -99,15 +86,18 @@ testCompilerDone store provider underlying compiler = do
--------------------------------------------------------------------------------
-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"
- }
+testConfiguration :: Configuration
+testConfiguration = defaultConfiguration
+ { destinationDirectory = "_testsite"
+ , storeDirectory = "_teststore"
+ , tmpDirectory = "_testtmp"
+ , providerDirectory = "tests/data"
+ }
+
+
+--------------------------------------------------------------------------------
+cleanTestEnv :: IO ()
+cleanTestEnv = do
+ removeDirectory $ destinationDirectory testConfiguration
+ removeDirectory $ storeDirectory testConfiguration
+ removeDirectory $ tmpDirectory testConfiguration