@@ -3,19 +3,17 @@
33module TestSuite.Util
44 ( fromAssertions
55 , newTestStore
6− , cleanTestStore
7− , withTestStore
86 , newTestProvider
97 , testCompiler
108 , testCompilerDone
11− , withTestConfiguration
9+ , testConfiguration
10+ , cleanTestEnv
1211 ) where
1312
1413
1514--------------------------------------------------------------------------------
1615import Data.Monoid (mempty)
1716import qualified Data.Set as S
18−import System.Directory (removeDirectoryRecursive)
1917import Test.Framework
2018import Test.Framework.Providers.HUnit
2119import Test.HUnit hiding (Test)
@@ -30,6 +28,7 @@ import qualified Hakyll.Core.Logger as Logger
3028import Hakyll.Core.Provider
3129import Hakyll.Core.Store (Store)
3230import qualified Hakyll.Core.Store as Store
31+import Hakyll.Core.Util.File
3332
3433
3534--------------------------------------------------------------------------------
@@ -42,26 +41,13 @@ fromAssertions name =
4241
4342--------------------------------------------------------------------------------
4443newTestStore :: IO Store
45−newTestStore = Store.new True "_teststore"
46−
47−
48−--------------------------------------------------------------------------------
49−cleanTestStore :: IO ()
50−cleanTestStore = removeDirectoryRecursive "_teststore"
51−
52−
53−--------------------------------------------------------------------------------
54−withTestStore :: (Store -> IO a) -> IO a
55−withTestStore f = do
56− store <- newTestStore
57− result <- f store
58− cleanTestStore
59− return result
44+newTestStore = Store.new True $ storeDirectory testConfiguration
6045
6146
6247--------------------------------------------------------------------------------
6348newTestProvider :: Store -> IO Provider
64−newTestProvider store = newProvider store (const False) "tests/data"
49+newTestProvider store = newProvider store (const False) $
50+ providerDirectory testConfiguration
6551
6652
6753--------------------------------------------------------------------------------
@@ -70,7 +56,8 @@ testCompiler :: Store -> Provider -> Identifier -> Compiler a
7056testCompiler store provider underlying compiler = do
7157 logger <- Logger.new Logger.Error
7258 let read' = CompilerRead
73− { compilerUnderlying = underlying
59+ { compilerConfig = testConfiguration
60+ , compilerUnderlying = underlying
7461 , compilerProvider = provider
7562 , compilerUniverse = S.empty
7663 , compilerRoutes = mempty
@@ -99,15 +86,18 @@ testCompilerDone store provider underlying compiler = do
9986
10087
10188--------------------------------------------------------------------------------
102−withTestConfiguration :: (Configuration -> IO a) -> IO a
103−withTestConfiguration f = do
104− x <- f config
105− removeDirectoryRecursive $ destinationDirectory config
106− removeDirectoryRecursive $ storeDirectory config
107− return x
108− where
109− config = defaultConfiguration
110− { destinationDirectory = "_testsite"
111− , storeDirectory = "_teststore"
112− , providerDirectory = "tests/data"
113− }
89+testConfiguration :: Configuration
90+testConfiguration = defaultConfiguration
91+ { destinationDirectory = "_testsite"
92+ , storeDirectory = "_teststore"
93+ , tmpDirectory = "_testtmp"
94+ , providerDirectory = "tests/data"
95+ }
96+
97+
98+--------------------------------------------------------------------------------
99+cleanTestEnv :: IO ()
100+cleanTestEnv = do
101+ removeDirectory $ destinationDirectory testConfiguration
102+ removeDirectory $ storeDirectory testConfiguration
103+ removeDirectory $ tmpDirectory testConfiguration