on master help sign in
Add tests again
commit88ffd3c5bea6b5e5cb1004173130b5691a7591f6 authorJasper Van der Jeugt <m@jaspervdj.be> dateMon 19 Nov 2012, 14:59 (14 years ago) parent6b5c299
17 files changed+256−201
hakyll.cabal+9−14 src/Hakyll/Core/Compiler.hs+2−2 src/Hakyll/Core/Provider/Internal.hs+23−15 src/Hakyll/Core/Provider/Metadata.hs+4−4 src/Hakyll/Core/Provider/MetadataCache.hs+1−1 src/Hakyll/Core/Provider/Modified.hs+12−9 src/Hakyll/Core/Util/File.hs+36−28 src/Hakyll/Web/Template/Context.hs+3−1 tests/Hakyll/Core/Dependencies/Tests.hs+3−3 tests/Hakyll/Core/Provider/Tests.hs+35 tests/Hakyll/Web/Template/Tests.hs+33−48 tests/TestSuite.hs+16−46 tests/TestSuite/Util.hs+67−30 tests/data/example.md+5 tests/data/example.md.metadata+1 tests/data/example.md.out+3 tests/data/template.html+3
hakyll.cabal+9−14
@@ -40,12 +40,19 @@ Category: Web
4040Cabal-Version: >= 1.8
4141Build-Type: Simple
4242Data-Dir: data
43+
4344Data-Files:
4445 templates/atom.xml
4546 templates/atom-item.xml
4647 templates/rss.xml
4748 templates/rss-item.xml
4849
50+Extra-source-files:
51+ tests/data/example.md
52+ tests/data/example.md.metadata
53+ tests/data/example.md.out
54+ tests/data/template.html
55+
4956Source-Repository head
5057 Type: git
5158 Location: git://github.com/jaspervdj/hakyll.git
@@ -200,19 +207,7 @@ Test-suite hakyll-tests
200207 unix >= 2.4 && < 2.7
201208
202209 Other-modules:
203− Hakyll.Web.Util.Html.Tests
204− Hakyll.Web.Urls.Relativize.Tests
205− Hakyll.Web.Urls.Tests
210+ Hakyll.Core.Dependencies.Tests
211+ Hakyll.Core.Provider.Tests
206212 Hakyll.Web.Template.Tests
207− Hakyll.Web.Page.Metadata.Tests
208− Hakyll.Web.Page.Tests
209− Hakyll.Core.Compiler.Tests
210− Hakyll.Core.Identifier.Tests
211− Hakyll.Core.Util.Arrow.Tests
212− Hakyll.Core.Util.String.Tests
213− Hakyll.Core.UnixFilter.Tests
214− Hakyll.Core.Routes.Tests
215− Hakyll.Core.Store.Tests
216− Hakyll.Core.Rules.Tests
217− Hakyll.Core.DependencyAnalyzer.Tests
218213 TestSuite.Util
src/Hakyll/Core/Compiler.hs+2−2
@@ -81,13 +81,13 @@ getResourceBody = getResourceWith resourceBody
8181--------------------------------------------------------------------------------
8282-- | Get the resource we are compiling as a string
8383getResourceString :: Compiler (Item String)
84−getResourceString = getResourceWith $ const resourceString
84+getResourceString = getResourceWith resourceString
8585
8686
8787--------------------------------------------------------------------------------
8888-- | Get the resource we are compiling as a lazy bytestring
8989getResourceLBS :: Compiler (Item ByteString)
90−getResourceLBS = getResourceWith $ const resourceLBS
90+getResourceLBS = getResourceWith resourceLBS
9191
9292
9393--------------------------------------------------------------------------------
src/Hakyll/Core/Provider/Internal.hs+23−15
@@ -7,32 +7,35 @@ module Hakyll.Core.Provider.Internal
77 , resourceExists
88 , resourceMetadataResource
99
10+ , resourceFilePath
1011 , resourceString
1112 , resourceLBS
1213 ) where
1314
1415
1516--------------------------------------------------------------------------------
16−import Control.Applicative ((<$>))
17−import qualified Data.ByteString.Lazy as BL
17+import Control.Applicative ((<$>))
18+import qualified Data.ByteString.Lazy as BL
1819import Data.IORef
19−import Data.Map (Map)
20−import qualified Data.Map as M
21−import Data.Set (Set)
22−import qualified Data.Set as S
23−import System.FilePath (addExtension)
20+import Data.Map (Map)
21+import qualified Data.Map as M
22+import Data.Set (Set)
23+import qualified Data.Set as S
24+import System.FilePath (addExtension, (</>))
2425
2526
2627--------------------------------------------------------------------------------
28+import Hakyll.Core.Identifier
2729import Hakyll.Core.Store
2830import Hakyll.Core.Util.File
29−import Hakyll.Core.Identifier
3031
3132
3233--------------------------------------------------------------------------------
3334-- | Responsible for retrieving and listing resources
3435data Provider = Provider
35− { -- | A list of all files found
36+ { -- Top of the provided directory
37+ providerDirectory :: FilePath
38+ , -- | A list of all files found
3639 providerSet :: Set Identifier
3740 , -- | Cache keeping track of modified files
3841 providerModifiedCache :: IORef (Map Identifier Bool)
@@ -49,9 +52,9 @@ newProvider :: Store -- ^ Store to use
4952 -> IO Provider -- ^ Resulting provider
5053newProvider store ignore directory = do
5154 list <- map fromFilePath . filter (not . ignore) <$>
52− getRecursiveContents False directory
55+ getRecursiveContents directory
5356 cache <- newIORef M.empty
54− return $ Provider (S.fromList list) cache store
57+ return $ Provider directory (S.fromList list) cache store
5558
5659
5760--------------------------------------------------------------------------------
@@ -74,13 +77,18 @@ resourceMetadataResource =
7477 fromFilePath . flip addExtension "metadata" . toFilePath
7578
7679
80+--------------------------------------------------------------------------------
81+resourceFilePath :: Provider -> Identifier -> FilePath
82+resourceFilePath p i = providerDirectory p </> toFilePath i
83+
84+
7785--------------------------------------------------------------------------------
7886-- | Get the raw body of a resource as string
79−resourceString :: Identifier -> IO String
80−resourceString = readFile . toFilePath
87+resourceString :: Provider -> Identifier -> IO String
88+resourceString p i = readFile $ resourceFilePath p i
8189
8290
8391--------------------------------------------------------------------------------
8492-- | Get the raw body of a resource of a lazy bytestring
85−resourceLBS :: Identifier -> IO BL.ByteString
86−resourceLBS = BL.readFile . toFilePath
93+resourceLBS :: Provider -> Identifier -> IO BL.ByteString
94+resourceLBS p i = BL.readFile $ resourceFilePath p i
src/Hakyll/Core/Provider/Metadata.hs+4−4
@@ -25,19 +25,19 @@ import Hakyll.Core.Util.String
2525
2626--------------------------------------------------------------------------------
2727loadMetadata :: Provider -> Identifier -> IO (Metadata, Maybe String)
28−loadMetadata rp identifier = do
28+loadMetadata p identifier = do
2929 hasHeader <- probablyHasMetadataHeader fp
3030 (md, body) <- if hasHeader
3131 then second Just <$> loadMetadataHeader fp
3232 else return (M.empty, Nothing)
3333
34− emd <- if resourceExists rp mi then loadMetadataFile mfp else return M.empty
34+ emd <- if resourceExists p mi then loadMetadataFile mfp else return M.empty
3535
3636 return (M.union md emd, body)
3737 where
38− fp = toFilePath identifier
38+ fp = resourceFilePath p identifier
3939 mi = resourceMetadataResource identifier
40− mfp = toFilePath mi
40+ mfp = resourceFilePath p mi
4141
4242
4343--------------------------------------------------------------------------------
src/Hakyll/Core/Provider/MetadataCache.hs+1−1
@@ -29,7 +29,7 @@ resourceBody p r = do
2929 load p r
3030 Store.Found bd <- Store.get (providerStore p)
3131 [name, toFilePath r, "body"]
32− maybe (resourceString r) return bd
32+ maybe (resourceString p r) return bd
3333
3434
3535--------------------------------------------------------------------------------
src/Hakyll/Core/Provider/Modified.hs+12−9
@@ -15,6 +15,7 @@ import Data.IORef
1515import qualified Data.Map as M
1616import Data.Time (UTCTime)
1717import System.Directory (getModificationTime)
18+import System.FilePath ((</>))
1819
1920
2021--------------------------------------------------------------------------------
@@ -28,7 +29,7 @@ import qualified Hakyll.Core.Store as Store
2829--------------------------------------------------------------------------------
2930-- | A resource is modified if it or its metadata has changed
3031resourceModified :: Provider -> Identifier -> IO Bool
31−resourceModified rp r
32+resourceModified p r
3233 | not exists = return False
3334 | otherwise = do
3435 cache <- readIORef cacheRef
@@ -38,19 +39,20 @@ resourceModified rp r
3839 -- Check if the actual file was modified, and do a recursive
3940 -- call to check if the metadata file was modified
4041 m <- (||)
41− <$> fileDigestModified store (toFilePath r)
42− <*> resourceModified rp (resourceMetadataResource r)
42+ <$> fileDigestModified store filePath
43+ <*> resourceModified p (resourceMetadataResource r)
4344 modifyIORef cacheRef (M.insert normalized m)
4445
4546 -- Important! (But ugly)
46− when m $ resourceInvalidateMetadataCache rp r
47+ when m $ resourceInvalidateMetadataCache p r
4748
4849 return m
4950 where
5051 normalized = setVersion Nothing r
51− exists = resourceExists rp r
52− store = providerStore rp
53− cacheRef = providerModifiedCache rp
52+ exists = resourceExists p r
53+ store = providerStore p
54+ cacheRef = providerModifiedCache p
55+ filePath = resourceFilePath p r
5456
5557
5658--------------------------------------------------------------------------------
@@ -79,5 +81,6 @@ fileDigest = fmap MD5.hashlazy . BL.readFile
7981
8082
8183--------------------------------------------------------------------------------
82−resourceModificationTime :: Identifier -> IO UTCTime
83−resourceModificationTime = getModificationTime . toFilePath
84+resourceModificationTime :: Provider -> Identifier -> IO UTCTime
85+resourceModificationTime p i =
86+ getModificationTime $ providerDirectory p </> toFilePath i
src/Hakyll/Core/Util/File.hs+36−28
@@ -1,52 +1,60 @@
1+--------------------------------------------------------------------------------
12-- | A module containing various file utility functions
2−--
33module Hakyll.Core.Util.File
44 ( makeDirectories
55 , getRecursiveContents
66 , isFileInternal
77 ) where
88
9−import Control.Applicative ((<$>))
10−import Control.Monad (forM)
11−import Data.List (isPrefixOf)
12−import System.Directory ( createDirectoryIfMissing, doesDirectoryExist
13− , getDirectoryContents
14− )
15−import System.FilePath ( normalise, takeDirectory, splitPath
16− , dropTrailingPathSeparator, (</>)
17− )
189
19−import Hakyll.Core.Configuration
10+--------------------------------------------------------------------------------
11+import Control.Applicative ((<$>))
12+import Control.Monad (forM)
13+import Data.List (isPrefixOf)
14+import System.Directory (createDirectoryIfMissing,
15+ doesDirectoryExist,
16+ getDirectoryContents)
17+import System.FilePath (dropTrailingPathSeparator,
18+ splitPath, takeDirectory, (</>))
2019
20+
21+--------------------------------------------------------------------------------
22+import Hakyll.Core.Configuration
23+
24+
25+--------------------------------------------------------------------------------
2126-- | Given a path to a file, try to make the path writable by making
2227-- all directories on the path.
23−--
2428makeDirectories :: FilePath -> IO ()
2529makeDirectories = createDirectoryIfMissing True . takeDirectory
2630
31+
32+--------------------------------------------------------------------------------
2733-- | Get all contents of a directory.
28−getRecursiveContents :: Bool -- ^ Include directories?
29− -> FilePath -- ^ Directory to search
34+getRecursiveContents :: FilePath -- ^ Directory to search
3035 -> IO [FilePath] -- ^ List of files found
31−getRecursiveContents includeDirs topdir = do
32− topdirExists <- doesDirectoryExist topdir
33− if not topdirExists
34− then return []
35− else do
36− names <- filter isProper <$> getDirectoryContents topdir
37− paths <- forM names $ \name -> do
38− let path = normalise $ topdir </> name
39− isDirectory <- doesDirectoryExist path
40− if isDirectory then getRecursiveContents includeDirs path
41− else return [path]
42− return $ if includeDirs then topdir : concat paths
43− else concat paths
36+getRecursiveContents top = go ""
4437 where
4538 isProper = (`notElem` [".", ".."])
39+ go dir = do
40+ dirExists <- doesDirectoryExist (top </> dir)
41+ if not dirExists
42+ then return []
43+ else do
44+ names <- filter isProper <$> getDirectoryContents (top </> dir)
45+ paths <- forM names $ \name -> do
46+ let rel = dir </> name
47+ isDirectory <- doesDirectoryExist (top </> rel)
48+ if isDirectory
49+ then go rel
50+ else return [rel]
51+
52+ return $ concat paths
53+
4654
55+--------------------------------------------------------------------------------
4756-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in
4857-- the destination or store directory
49−--
5058isFileInternal :: Configuration -- ^ Configuration
5159 -> FilePath -- ^ File to check
5260 -> Bool -- ^ If the given file is internal
src/Hakyll/Web/Template/Context.hs+3−1
@@ -195,7 +195,9 @@ modificationTimeFieldWith :: TimeLocale -- ^ Time output locale
195195 -> String -- ^ Format
196196 -> Context a -- ^ Resulting context
197197modificationTimeFieldWith locale key fmt = field key $ \i -> do
198− mtime <- compilerUnsafeIO $ resourceModificationTime $ itemIdentifier i
198+ provider <- compilerProvider <$> compilerAsk
199+ mtime <- compilerUnsafeIO $
200+ resourceModificationTime provider $ itemIdentifier i
199201 return $ formatTime locale fmt mtime
200202
201203
tests/Hakyll/Core/Dependencies/Tests.hs+3−3
@@ -41,9 +41,9 @@ oldFacts = M.fromList
4141 , ("posts/02.md",
4242 [])
4343 , ("index.md",
44− [ Pattern "posts/*" ["posts/01.md", "posts/02.md"]
45− , Identifier "posts/01.md"
46− , Identifier "posts/02.md"
44+ [ PatternDependency "posts/*" ["posts/01.md", "posts/02.md"]
45+ , IdentifierDependency "posts/01.md"
46+ , IdentifierDependency "posts/02.md"
4747 ])
4848 ]
4949
tests/Hakyll/Core/Provider/Tests.hsnew file+35
@@ -0,0 +1,35 @@
1+--------------------------------------------------------------------------------
2+{-# LANGUAGE OverloadedStrings #-}
3+module Hakyll.Core.Provider.Tests
4+ ( tests
5+ ) where
6+
7+
8+--------------------------------------------------------------------------------
9+import qualified Data.Map as M
10+import Test.Framework (Test, testGroup)
11+import Test.Framework.Providers.HUnit (testCase)
12+import Test.HUnit (Assertion, assert, (@=?))
13+
14+
15+--------------------------------------------------------------------------------
16+import Hakyll.Core.Provider
17+import TestSuite.Util
18+
19+
20+--------------------------------------------------------------------------------
21+tests :: Test
22+tests = testGroup "Hakyll.Core.Provider.Tests"
23+ [ testCase "case01" case01
24+ ]
25+
26+
27+--------------------------------------------------------------------------------
28+case01 :: Assertion
29+case01 = withTestStore $ \store -> do
30+ provider <- newTestProvider store
31+ assert $ resourceExists provider "example.md"
32+
33+ metadata <- resourceMetadata provider "example.md"
34+ Just "An example" @=? M.lookup "title" metadata
35+ Just "External data" @=? M.lookup "external" metadata
tests/Hakyll/Web/Template/Tests.hs+33−48
@@ -1,55 +1,40 @@
1+--------------------------------------------------------------------------------
12{-# LANGUAGE OverloadedStrings #-}
23module Hakyll.Web.Template.Tests
34 ( tests
45 ) where
56
6−import Test.Framework
7−import Test.HUnit hiding (Test)
8−
9−import qualified Data.Map as M
10−
11−import Hakyll.Web.Page
12−import Hakyll.Web.Template
13−import Hakyll.Web.Template.Read
14−import TestSuite.Util
15−
16−tests :: [Test]
17−tests = fromAssertions "applyTemplate"
18− -- Hakyll templates
19− [ applyTemplateAssertion readTemplate applyTemplate
20− ("bar" @=?) "$foo$" [("foo", "bar")]
21−
22− , applyTemplateAssertion readTemplate applyTemplate
23− ("$ barqux" @=?) "$$ $foo$$bar$" [("foo", "bar"), ("bar", "qux")]
24−
25− , applyTemplateAssertion readTemplate applyTemplate
26− ("$foo$" @=?) "$foo$" []
27−
28− -- Hamlet templates
29− , applyTemplateAssertion readHamletTemplate applyTemplate
30− (("<head><title>notice</title></head><body>A paragraph</body>" @=?) .
31− filter (/= '\n'))
32− "<head>\n\
33− \ <title>#{title}\n\
34− \<body>\n\
35− \ A paragraph\n"
36− [("title", "notice")]
37−
38− -- Missing keys
39− , let missing "foo" = "bar"
40− missing "bar" = "qux"
41− missing x = reverse x
42− in applyTemplateAssertion readTemplate (applyTemplateWith missing)
43− ("bar foo ver" @=?) "$foo$ $bar$ $rev$" [("bar", "foo")]
7+
8+--------------------------------------------------------------------------------
9+import Test.Framework (Test, testGroup)
10+import Test.Framework.Providers.HUnit (testCase)
11+import Test.HUnit (Assertion, (@=?))
12+
13+
14+--------------------------------------------------------------------------------
15+import Hakyll.Core.Item
16+import Hakyll.Core.Provider
17+import Hakyll.Web.Page
18+import Hakyll.Web.Template
19+import Hakyll.Web.Template.Context
20+import TestSuite.Util
21+
22+
23+--------------------------------------------------------------------------------
24+tests :: Test
25+tests = testGroup "Hakyll.Core.Template.Tests"
26+ [ testCase "case01" case01
4427 ]
4528
46−-- | Utility function to create quick template tests
47−--
48−applyTemplateAssertion :: (String -> Template)
49− -> (Template -> Page String -> Page String)
50− -> (String -> Assertion)
51− -> String
52− -> [(String, String)]
53− -> Assertion
54−applyTemplateAssertion parser apply correct template page =
55− correct $ pageBody (apply (parser template) (fromMap $ M.fromList page))
29+
30+--------------------------------------------------------------------------------
31+case01 :: Assertion
32+case01 = withTestStore $ \store -> do
33+ provider <- newTestProvider store
34+
35+ out <- resourceString provider "example.md.out"
36+ tpl <- testCompilerDone store provider "template.html" $ templateCompiler
37+ item <- testCompilerDone store provider "example.md" $
38+ pageCompiler >>= applyTemplate (itemBody tpl) defaultContext
39+
40+ out @=? itemBody item
tests/TestSuite.hs+16−46
@@ -1,53 +1,23 @@
1−module Main where
1+--------------------------------------------------------------------------------
2+module Main
3+ ( main
4+ ) where
25
3−import Test.Framework (defaultMain, testGroup)
46
5−import qualified Hakyll.Core.Compiler.Tests
6−import qualified Hakyll.Core.DependencyAnalyzer.Tests
7−import qualified Hakyll.Core.Identifier.Tests
8−import qualified Hakyll.Core.Routes.Tests
9−import qualified Hakyll.Core.Rules.Tests
10−import qualified Hakyll.Core.Store.Tests
11−import qualified Hakyll.Core.UnixFilter.Tests
12−import qualified Hakyll.Core.Util.Arrow.Tests
13−import qualified Hakyll.Core.Util.String.Tests
14−import qualified Hakyll.Web.Page.Tests
15−import qualified Hakyll.Web.Page.Metadata.Tests
7+--------------------------------------------------------------------------------
8+import Test.Framework (defaultMain)
9+
10+
11+--------------------------------------------------------------------------------
12+import qualified Hakyll.Core.Dependencies.Tests
13+import qualified Hakyll.Core.Provider.Tests
1614import qualified Hakyll.Web.Template.Tests
17−import qualified Hakyll.Web.Urls.Tests
18−import qualified Hakyll.Web.Urls.Relativize.Tests
19−import qualified Hakyll.Web.Util.Html.Tests
2015
16+
17+--------------------------------------------------------------------------------
2118main :: IO ()
2219main = defaultMain
23− [ testGroup "Hakyll.Core.Compiler.Tests"
24− Hakyll.Core.Compiler.Tests.tests
25− , testGroup "Hakyll.Core.DependencyAnalyzer.Tests"
26− Hakyll.Core.DependencyAnalyzer.Tests.tests
27− , testGroup "Hakyll.Core.Identifier.Tests"
28− Hakyll.Core.Identifier.Tests.tests
29− , testGroup "Hakyll.Core.Routes.Tests"
30− Hakyll.Core.Routes.Tests.tests
31− , testGroup "Hakyll.Core.Rules.Tests"
32− Hakyll.Core.Rules.Tests.tests
33− , testGroup "Hakyll.Core.Store.Tests"
34− Hakyll.Core.Store.Tests.tests
35− , testGroup "Hakyll.Core.UnixFilter.Tests"
36− Hakyll.Core.UnixFilter.Tests.tests
37− , testGroup "Hakyll.Core.Util.Arrow.Tests"
38− Hakyll.Core.Util.Arrow.Tests.tests
39− , testGroup "Hakyll.Core.Util.String.Tests"
40− Hakyll.Core.Util.String.Tests.tests
41− , testGroup "Hakyll.Web.Page.Tests"
42− Hakyll.Web.Page.Tests.tests
43− , testGroup "Hakyll.Web.Page.Metadata.Tests"
44− Hakyll.Web.Page.Metadata.Tests.tests
45− , testGroup "Hakyll.Web.Template.Tests"
46− Hakyll.Web.Template.Tests.tests
47− , testGroup "Hakyll.Web.Urls.Tests"
48− Hakyll.Web.Urls.Tests.tests
49− , testGroup "Hakyll.Web.Urls.Relativize.Tests"
50− Hakyll.Web.Urls.Relativize.Tests.tests
51− , testGroup "Hakyll.Web.Util.Html.Tests"
52− Hakyll.Web.Util.Html.Tests.tests
20+ [ Hakyll.Core.Dependencies.Tests.tests
21+ , Hakyll.Core.Provider.Tests.tests
22+ , Hakyll.Web.Template.Tests.tests
5323 ]
tests/TestSuite/Util.hs+67−30
@@ -1,24 +1,32 @@
1+--------------------------------------------------------------------------------
12-- | Test utilities
2−--
33module TestSuite.Util
44 ( fromAssertions
5− , makeStoreTest
6− , runCompilerJobTest
5+ , withTestStore
6+ , newTestProvider
7+ , testCompiler
8+ , testCompilerDone
79 ) where
810
9−import Data.Monoid (mempty)
1011
11−import Test.Framework
12−import Test.Framework.Providers.HUnit
13−import Test.HUnit hiding (Test)
12+--------------------------------------------------------------------------------
13+import Data.Monoid (mempty)
14+import System.Directory (removeDirectoryRecursive)
15+import Test.Framework
16+import Test.Framework.Providers.HUnit
17+import Test.HUnit hiding (Test)
1418
15−import Hakyll.Core.Compiler.Internal
16−import Hakyll.Core.Identifier
17−import Hakyll.Core.Logger
18−import Hakyll.Core.Resource.Provider
19−import Hakyll.Core.Store (Store)
20−import qualified Hakyll.Core.Store as Store
2119
20+--------------------------------------------------------------------------------
21+import Hakyll.Core.Compiler.Internal
22+import Hakyll.Core.Identifier
23+import qualified Hakyll.Core.Logger as Logger
24+import Hakyll.Core.Provider
25+import Hakyll.Core.Store (Store)
26+import qualified Hakyll.Core.Store as Store
27+
28+
29+--------------------------------------------------------------------------------
2230fromAssertions :: String -- ^ Name
2331 -> [Assertion] -- ^ Cases
2432 -> [Test] -- ^ Result tests
@@ -26,20 +34,49 @@ fromAssertions name = zipWith testCase names
2634 where
2735 names = map (\n -> name ++ " [" ++ show n ++ "]") [1 :: Int ..]
2836
29−-- | Create a store for testing
30−--
31−makeStoreTest :: IO Store
32−makeStoreTest = Store.new True "_store"
33−
34−-- | Testing for 'runCompilerJob'
35−--
36−runCompilerJobTest :: Compiler () a
37− -> Identifier ()
38− -> ResourceProvider
39− -> [Identifier ()]
40− -> IO a
41−runCompilerJobTest compiler id' provider uni = do
42− store <- makeStoreTest
43− logger <- makeLogger $ const $ return ()
44− Right x <- runCompilerJob compiler id' provider uni mempty store True logger
45− return x
37+
38+--------------------------------------------------------------------------------
39+withTestStore :: (Store -> IO a) -> IO a
40+withTestStore f = do
41+ store <- Store.new True "_teststore"
42+ result <- f store
43+ removeDirectoryRecursive "_teststore"
44+ return result
45+
46+
47+--------------------------------------------------------------------------------
48+newTestProvider :: Store -> IO Provider
49+newTestProvider store = newProvider store (const False) "tests/data"
50+
51+
52+--------------------------------------------------------------------------------
53+testCompiler :: Store -> Provider -> Identifier -> Compiler a
54+ -> IO (CompilerResult a)
55+testCompiler store provider underlying compiler = do
56+ logger <- Logger.new Logger.Debug (\_ -> return ())
57+ let read' = CompilerRead
58+ { compilerUnderlying = underlying
59+ , compilerProvider = provider
60+ , compilerUniverse = []
61+ , compilerRoutes = mempty
62+ , compilerStore = store
63+ , compilerLogger = logger
64+ }
65+
66+ result <- runCompiler compiler read'
67+ Logger.flush logger
68+ return result
69+
70+
71+--------------------------------------------------------------------------------
72+testCompilerDone :: Store -> Provider -> Identifier -> Compiler a -> IO a
73+testCompilerDone store provider underlying compiler = do
74+ result <- testCompiler store provider underlying compiler
75+ case result of
76+ CompilerDone x _ -> return x
77+ CompilerError e -> error $
78+ "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
79+ " threw: " ++ e
80+ CompilerRequire i _ -> error $
81+ "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
82+ " requires: " ++ show i
tests/data/example.mdnew file+5
@@ -0,0 +1,5 @@
1+---
2+title: An example
3+---
4+
5+This is an example.
tests/data/example.md.metadatanew file+1
@@ -0,0 +1 @@
1+external: External data
tests/data/example.md.outnew file+3
@@ -0,0 +1,3 @@
1+<div>
2+ <p>This is an example.</p>
3+</div>
tests/data/template.htmlnew file+3
@@ -0,0 +1,3 @@
1+<div>
2+ $body$
3+</div>