summaryrefslogtreecommitdiff
path: root/tests/TestSuite
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/TestSuite
parente477ea753b59657ba8d185986c646cc45c66fcec (diff)
downloadhakyll-bbc2631c76db01e85ac5c4e75b1babb6c5b05697.tar.gz
Add TmpFile utilities
Diffstat (limited to 'tests/TestSuite')
-rw-r--r--tests/TestSuite/Util.hs56
1 files changed, 23 insertions, 33 deletions
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