on master help sign in
Re-add some tests, cleanup...
1bcce77Jasper Van der Jeugt
hakyll.cabal+4
@@ -202,10 +202,14 @@ Test-suite hakyll-tests
202 Hakyll.Core.Dependencies.Tests
202 Hakyll.Core.Dependencies.Tests
203 Hakyll.Core.Identifier.Tests
203 Hakyll.Core.Identifier.Tests
204 Hakyll.Core.Provider.Tests
204 Hakyll.Core.Provider.Tests
205+ Hakyll.Core.Routes.Tests
206+ Hakyll.Core.Rules.Tests
205 Hakyll.Core.Runtime.Tests
207 Hakyll.Core.Runtime.Tests
206 Hakyll.Core.Store.Tests
208 Hakyll.Core.Store.Tests
207 Hakyll.Core.UnixFilter.Tests
209 Hakyll.Core.UnixFilter.Tests
210+ Hakyll.Core.Util.String.Tests
208 Hakyll.Web.Template.Tests
211 Hakyll.Web.Template.Tests
209 Hakyll.Web.Urls.Tests
212 Hakyll.Web.Urls.Tests
210 Hakyll.Web.Urls.Relativize.Tests
213 Hakyll.Web.Urls.Relativize.Tests
214+ Hakyll.Web.Util.Html.Tests
211 TestSuite.Util
215 TestSuite.Util
src/Hakyll/Web/Page/List.hsdeleted−83
@@ -1,83 +0,0 @@
1−-- TODO: Port
2−-- | Provides an easy way to combine several pages in a list. The applications
3−-- are obvious:
4−--
5−-- * A post list on a blog
6−--
7−-- * An image list in a gallery
8−--
9−-- * A sitemap
10−--
11−module Hakyll.Web.Page.List
12− ( setFieldPageList
13− , pageListCompiler
14− , chronological
15− , recentFirst
16− , sortByBaseName
17− ) where
18−
19−import Control.Arrow ((>>>), arr)
20−import Data.List (sortBy)
21−import Data.Monoid (Monoid, mconcat)
22−import Data.Ord (comparing)
23−import System.FilePath (takeBaseName)
24−
25−import Hakyll.Core.Compiler
26−import Hakyll.Core.Identifier
27−import Hakyll.Core.Identifier.Pattern
28−import Hakyll.Web.Page
29−import Hakyll.Web.Page.Metadata
30−import Hakyll.Web.Template
31−
32−-- | Set a field of a page to a listing of pages
33−--
34−setFieldPageList :: ([Page String] -> [Page String])
35− -- ^ Determines list order
36− -> Identifier Template
37− -- ^ Applied to every page
38− -> String
39− -- ^ Key indicating which field should be set
40− -> Pattern (Page String)
41− -- ^ Selects pages to include in the list
42− -> Compiler (Page String) (Page String)
43− -- ^ Compiler that sets the page list in a field
44−setFieldPageList sort template key pattern =
45− requireAllA pattern $ setFieldA key $ pageListCompiler sort template
46−
47−-- | Create a list of pages
48−--
49−pageListCompiler :: ([Page String] -> [Page String]) -- ^ Determine list order
50− -> Identifier Template -- ^ Applied to pages
51− -> Compiler [Page String] String -- ^ Compiles page list
52−pageListCompiler sort template =
53− arr sort >>> applyTemplateToList template >>> arr concatPages
54−
55−-- | Apply a template to every page in a list
56−--
57−applyTemplateToList :: Identifier Template
58− -> Compiler [Page String] [Page String]
59−applyTemplateToList identifier = require identifier $
60− \posts template -> map (applyTemplateToPage template) posts
61−
62−-- | Concatenate the bodies of a page list
63−--
64−concatPages :: Monoid m => [Page m] -> m
65−concatPages = mconcat . map pageBody
66−
67−-- | Sort pages chronologically. This function assumes that the pages have a
68−-- @year-month-day-title.extension@ naming scheme -- as is the convention in
69−-- Hakyll.
70−--
71−chronological :: [Page a] -> [Page a]
72−chronological = sortBy $ comparing $ takeBaseName . getField "path"
73−
74−-- | The reverse of 'chronological'
75−--
76−recentFirst :: [Page a] -> [Page a]
77−recentFirst = reverse . chronological
78−
79−-- | Deprecated, see 'chronological'
80−--
81−sortByBaseName :: [Page a] -> [Page a]
82−sortByBaseName = chronological
83−{-# DEPRECATED sortByBaseName "Use chronological" #-}
tests/Hakyll/Core/Routes/Tests.hs+14−7
@@ -1,17 +1,24 @@
1+--------------------------------------------------------------------------------
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2module Hakyll.Core.Routes.Tests
3module Hakyll.Core.Routes.Tests
3 ( tests
4 ( tests
4 ) where
5 ) where
5
6
6−import Test.Framework
7−import Test.HUnit hiding (Test)
8
7
9−import Hakyll.Core.Identifier
8+--------------------------------------------------------------------------------
10−import Hakyll.Core.Routes
9+import Test.Framework (Test, testGroup)
11−import TestSuite.Util
10+import Test.HUnit ((@=?))
12
11
12+
13+--------------------------------------------------------------------------------
14+import Hakyll.Core.Identifier
15+import Hakyll.Core.Routes
16+import TestSuite.Util
17+
18+
19+--------------------------------------------------------------------------------
13−tests :: [Test]
20+tests :: Test
14−tests = fromAssertions "runRoutes"
21+tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
15 [ Just "foo.html" @=? runRoutes (setExtension "html") "foo"
22 [ Just "foo.html" @=? runRoutes (setExtension "html") "foo"
16 , Just "foo.html" @=? runRoutes (setExtension ".html") "foo"
23 , Just "foo.html" @=? runRoutes (setExtension ".html") "foo"
17 , Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
24 , Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
tests/Hakyll/Core/Rules/Tests.hs+42−44
@@ -1,67 +1,65 @@
1+--------------------------------------------------------------------------------
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2−{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
3module Hakyll.Core.Rules.Tests
3module Hakyll.Core.Rules.Tests
4 ( tests
4 ( tests
5 ) where
5 ) where
6
6
7−import qualified Data.Map as M
8−import qualified Data.Set as S
9
7
8+--------------------------------------------------------------------------------
9+import qualified Data.Set as S
10−import Test.Framework
10+import Test.Framework (Test, testGroup)
11−import Test.Framework.Providers.HUnit
11+import Test.Framework.Providers.HUnit (testCase)
12−import Test.HUnit hiding (Test)
12+import Test.HUnit (Assertion, assert, (@=?))
13
13
14−import Hakyll.Core.Rules
15−import Hakyll.Core.Rules.Internal
16−import Hakyll.Core.Identifier
17−import Hakyll.Core.Routes
18−import Hakyll.Core.Compiler
19−import Hakyll.Core.Resource.Provider
20−import Hakyll.Core.Resource.Provider.Dummy
21−import Hakyll.Web.Page
22
14
15+--------------------------------------------------------------------------------
16+import Hakyll.Core.Compiler
17+import Hakyll.Core.Identifier
18+import Hakyll.Core.Routes
19+import Hakyll.Core.Rules
20+import Hakyll.Core.Rules.Internal
21+import Hakyll.Web.Page
22+import TestSuite.Util
23+
24+
25+--------------------------------------------------------------------------------
23−tests :: [Test]
26+tests :: Test
24−tests =
27+tests = testGroup "Hakyll.Core.Rules.Tests"
25 [ testCase "runRules" rulesTest
28 [ testCase "runRules" rulesTest
26 ]
29 ]
27
30
28−-- | Main test
31+
29−--
32+--------------------------------------------------------------------------------
30rulesTest :: Assertion
33rulesTest :: Assertion
31−rulesTest = do
34+rulesTest = withTestStore $ \store -> do
32− p <- provider
35+ provider <- newTestProvider store
33− let ruleSet = runRules rules p
36+ ruleSet <- runRules rules provider
34− assert $ expected == S.fromList (map fst (rulesCompilers ruleSet))
37+ let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
38+ routes = rulesRoutes ruleSet
39+
40+ -- Test that we have some identifiers and that the routes work out
41+ assert $ all (`S.member` identifiers) expected
42+ Just "example.html" @=? runRoutes routes "example.md"
43+ Just "example.md" @=? runRoutes routes (raw "example.md")
35 where
44 where
45+ raw = setVersion (Just "raw")
36− expected = S.fromList
46+ expected =
37− [ Identifier Nothing "posts/a-post.markdown"
47+ [ "example.md"
38− , Identifier Nothing "posts/some-other-post.markdown"
48+ , "russian.md"
39− , Identifier (Just "raw") "posts/a-post.markdown"
49+ , raw "example.md"
40− , Identifier (Just "raw") "posts/some-other-post.markdown"
50+ , raw "russian.md"
41 ]
51 ]
42
52
43−-- | Dummy resource provider
44−--
45−provider :: IO ResourceProvider
46−provider = dummyResourceProvider $ M.fromList $ map (flip (,) "No content")
47− [ "posts/a-post.markdown"
48− , "posts/some-other-post.markdown"
49− ]
50
53
51−-- | Example rules
54+--------------------------------------------------------------------------------
52−--
53−rules :: Rules
55+rules :: Rules ()
54rules = do
56rules = do
55 -- Compile some posts
57 -- Compile some posts
56− match "posts/*" $ do
58+ match "*.md" $ do
57 route $ setExtension "html"
59 route $ setExtension "html"
58 compile pageCompiler
60 compile pageCompiler
59
61
60 -- Compile them, raw
62 -- Compile them, raw
61− group "raw" $ do
63+ match "*.md" $ version "raw" $ do
62 route idRoute
64 route idRoute
63− match "posts/*" $ do
64− route $ setExtension "html"
65− compile getResourceString
65+ compile getResourceString
66−
67− return ()
tests/Hakyll/Core/Util/String/Tests.hs+13−6
@@ -1,15 +1,22 @@
1+--------------------------------------------------------------------------------
1module Hakyll.Core.Util.String.Tests
2module Hakyll.Core.Util.String.Tests
2 ( tests
3 ( tests
3 ) where
4 ) where
4
5
5−import Test.Framework (Test)
6−import Test.HUnit ((@=?))
7
6
8−import Hakyll.Core.Util.String
7+--------------------------------------------------------------------------------
9−import TestSuite.Util
8+import Test.Framework (Test, testGroup)
9+import Test.HUnit ((@=?))
10
10
11+
12+--------------------------------------------------------------------------------
13+import Hakyll.Core.Util.String
14+import TestSuite.Util
15+
16+
17+--------------------------------------------------------------------------------
11−tests :: [Test]
18+tests :: Test
12−tests = concat
19+tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat
13 [ fromAssertions "trim"
20 [ fromAssertions "trim"
14 [ "foo" @=? trim " foo\n\t "
21 [ "foo" @=? trim " foo\n\t "
15 ]
22 ]
tests/Hakyll/Web/Util/Html/Tests.hs+13−6
@@ -1,15 +1,22 @@
1+--------------------------------------------------------------------------------
1module Hakyll.Web.Util.Html.Tests
2module Hakyll.Web.Util.Html.Tests
2 ( tests
3 ( tests
3 ) where
4 ) where
4
5
5−import Test.Framework
6−import Test.HUnit hiding (Test)
7
6
8−import Hakyll.Web.Util.Html
7+--------------------------------------------------------------------------------
9−import TestSuite.Util
8+import Test.Framework (Test, testGroup)
9+import Test.HUnit ((@=?))
10
10
11+
12+--------------------------------------------------------------------------------
13+import Hakyll.Web.Util.Html
14+import TestSuite.Util
15+
16+
17+--------------------------------------------------------------------------------
11−tests :: [Test]
18+tests :: Test
12−tests = concat
19+tests = testGroup "Hakyll.Web.Util.Html" $ concat
13 [ fromAssertions "stripTags"
20 [ fromAssertions "stripTags"
14 [ "foo" @=? stripTags "<p>foo</p>"
21 [ "foo" @=? stripTags "<p>foo</p>"
15 , "foo bar" @=? stripTags "<p>foo</p> bar"
22 , "foo bar" @=? stripTags "<p>foo</p> bar"
tests/TestSuite.hs+9−1
@@ -12,12 +12,16 @@ import Test.Framework (defaultMain)
12import qualified Hakyll.Core.Dependencies.Tests
12import qualified Hakyll.Core.Dependencies.Tests
13import qualified Hakyll.Core.Identifier.Tests
13import qualified Hakyll.Core.Identifier.Tests
14import qualified Hakyll.Core.Provider.Tests
14import qualified Hakyll.Core.Provider.Tests
15+import qualified Hakyll.Core.Routes.Tests
16+import qualified Hakyll.Core.Rules.Tests
15import qualified Hakyll.Core.Runtime.Tests
17import qualified Hakyll.Core.Runtime.Tests
16import qualified Hakyll.Core.Store.Tests
18import qualified Hakyll.Core.Store.Tests
17import qualified Hakyll.Core.UnixFilter.Tests
19import qualified Hakyll.Core.UnixFilter.Tests
20+import qualified Hakyll.Core.Util.String.Tests
18import qualified Hakyll.Web.Template.Tests
21import qualified Hakyll.Web.Template.Tests
19import qualified Hakyll.Web.Urls.Relativize.Tests
22import qualified Hakyll.Web.Urls.Relativize.Tests
20import qualified Hakyll.Web.Urls.Tests
23import qualified Hakyll.Web.Urls.Tests
24+import qualified Hakyll.Web.Util.Html.Tests
21
25
22
26
23--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
@@ -26,10 +30,14 @@ main = defaultMain
26 [ Hakyll.Core.Dependencies.Tests.tests
30 [ Hakyll.Core.Dependencies.Tests.tests
27 , Hakyll.Core.Identifier.Tests.tests
31 , Hakyll.Core.Identifier.Tests.tests
28 , Hakyll.Core.Provider.Tests.tests
32 , Hakyll.Core.Provider.Tests.tests
33+ , Hakyll.Core.Routes.Tests.tests
34+ , Hakyll.Core.Rules.Tests.tests
29 , Hakyll.Core.Runtime.Tests.tests
35 , Hakyll.Core.Runtime.Tests.tests
30 , Hakyll.Core.Store.Tests.tests
36 , Hakyll.Core.Store.Tests.tests
31 , Hakyll.Core.UnixFilter.Tests.tests
37 , Hakyll.Core.UnixFilter.Tests.tests
38+ , Hakyll.Core.Util.String.Tests.tests
32 , Hakyll.Web.Template.Tests.tests
39 , Hakyll.Web.Template.Tests.tests
33− , Hakyll.Web.Urls.Tests.tests
34 , Hakyll.Web.Urls.Relativize.Tests.tests
40 , Hakyll.Web.Urls.Relativize.Tests.tests
41+ , Hakyll.Web.Urls.Tests.tests
42+ , Hakyll.Web.Util.Html.Tests.tests
35 ]
43 ]