on master help sign in
Update more tests
b5adcb6Jasper Van der Jeugt
hakyll.cabal−1
@@ -109,7 +109,6 @@ Library
109 Hakyll.Core.Rules
109 Hakyll.Core.Rules
110 Hakyll.Core.Runtime
110 Hakyll.Core.Runtime
111 Hakyll.Core.Store
111 Hakyll.Core.Store
112− Hakyll.Core.Util.Arrow
113 Hakyll.Core.Util.File
112 Hakyll.Core.Util.File
114 Hakyll.Core.Util.String
113 Hakyll.Core.Util.String
115 Hakyll.Core.Writable
114 Hakyll.Core.Writable
src/Hakyll.hs−2
@@ -13,7 +13,6 @@ module Hakyll
13#ifdef UNIX_FILTER
13#ifdef UNIX_FILTER
14 , module Hakyll.Core.UnixFilter
14 , module Hakyll.Core.UnixFilter
15#endif
15#endif
16− , module Hakyll.Core.Util.Arrow
17 , module Hakyll.Core.Util.File
16 , module Hakyll.Core.Util.File
18 , module Hakyll.Core.Util.String
17 , module Hakyll.Core.Util.String
19 , module Hakyll.Core.Writable
18 , module Hakyll.Core.Writable
@@ -46,7 +45,6 @@ import Hakyll.Core.Rules
46#ifdef UNIX_FILTER
45#ifdef UNIX_FILTER
47import Hakyll.Core.UnixFilter
46import Hakyll.Core.UnixFilter
48#endif
47#endif
49−import Hakyll.Core.Util.Arrow
50import Hakyll.Core.Util.File
48import Hakyll.Core.Util.File
51import Hakyll.Core.Util.String
49import Hakyll.Core.Util.String
52import Hakyll.Core.Writable
50import Hakyll.Core.Writable
src/Hakyll/Core/UnixFilter.hs+2−2
@@ -26,7 +26,7 @@ import Hakyll.Core.Compiler
26-- as a compiler.
26-- as a compiler.
27--
27--
28-- > rev :: Compiler String
28-- > rev :: Compiler String
29−-- > rev = getResourceString >>= unixFilter "rev" []
29+-- > rev = getResourceString >>= itemM (unixFilter "rev" [])
30--
30--
31-- A more realistic example: one can use this to call, for example, the sass
31-- A more realistic example: one can use this to call, for example, the sass
32-- compiler on CSS files. More information about sass can be found here:
32-- compiler on CSS files. More information about sass can be found here:
@@ -38,7 +38,7 @@ import Hakyll.Core.Compiler
38-- > match "style.scss" $ do
38-- > match "style.scss" $ do
39-- > route $ setExtension "css"
39-- > route $ setExtension "css"
40-- > compile $ getResourceString >>=
40-- > compile $ getResourceString >>=
41−-- > unixFilter "sass" ["-s", "--scss"] >>=
41+-- > itemM (unixFilter "sass" ["-s", "--scss"]) >>=
42-- > compressCssCompiler
42-- > compressCssCompiler
43unixFilter :: String -- ^ Program name
43unixFilter :: String -- ^ Program name
44 -> [String] -- ^ Program args
44 -> [String] -- ^ Program args
src/Hakyll/Core/Util/Arrow.hsdeleted−40
@@ -1,40 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Various arrow utility functions
3−module Hakyll.Core.Util.Arrow
4− ( ArrowMap (..)
5− , constA
6− , sequenceA
7− , unitA
8− ) where
9−
10−
11−--------------------------------------------------------------------------------
12−import Control.Arrow (Arrow, ArrowChoice, arr, (&&&), (>>^))
13−
14−
15−--------------------------------------------------------------------------------
16−-- | Additional arrow typeclass for performance reasons.
17−class ArrowChoice a => ArrowMap a where
18− mapA :: a b c -> a [b] [c]
19−
20−
21−--------------------------------------------------------------------------------
22−instance ArrowMap (->) where
23− mapA = map
24−
25−
26−--------------------------------------------------------------------------------
27−constA :: Arrow a => c -> a b c
28−constA = arr . const
29−
30−
31−--------------------------------------------------------------------------------
32−sequenceA :: Arrow a => [a b c] -> a b [c]
33−sequenceA = foldr reduce $ constA []
34− where
35− reduce xa la = xa &&& la >>^ arr (uncurry (:))
36−
37−
38−--------------------------------------------------------------------------------
39−unitA :: Arrow a => a b ()
40−unitA = constA ()
tests/Hakyll/Core/Compiler/Tests.hsdeleted−36
@@ -1,36 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Hakyll.Core.Compiler.Tests
3− ( tests
4− ) where
5−
6−import qualified Data.Map as M
7−
8−import Test.Framework (Test)
9−import Test.Framework.Providers.HUnit (testCase)
10−import qualified Test.HUnit as H
11−
12−import Hakyll.Core.Compiler
13−import Hakyll.Core.Resource.Provider.Dummy
14−import Hakyll.Core.Util.Arrow
15−import TestSuite.Util
16−
17−tests :: [Test]
18−tests =
19− [ testCase "byExtension" byExtensionTest
20− ]
21−
22−byExtensionTest :: H.Assertion
23−byExtensionTest = do
24− provider <- dummyResourceProvider $ M.empty
25− txt <- runCompilerJobTest compiler "foo.txt" provider uni
26− css <- runCompilerJobTest compiler "bar.css" provider uni
27− html <- runCompilerJobTest compiler "qux.html" provider uni
28− H.assertEqual "byExtension" "txt" txt
29− H.assertEqual "byExtension" "css" css
30− H.assertEqual "byExtension" "unknown" html
31− where
32− uni = ["foo.txt", "bar.css", "qux.html"]
33− compiler = byExtension (constA ("unknown" :: String))
34− [ (".txt", constA "txt")
35− , (".css", constA "css")
36− ]
tests/Hakyll/Core/Dependencies/Tests.hs+8−11
@@ -6,26 +6,23 @@ module Hakyll.Core.Dependencies.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Data.List (delete)
9+import Data.List (delete)
10−import qualified Data.Map as M
10+import qualified Data.Map as M
11−import qualified Data.Set as S
11+import qualified Data.Set as S
12−import Test.Framework (Test, testGroup)
12+import Test.Framework (Test, testGroup)
13−import Test.Framework.Providers.HUnit (testCase)
13+import Test.HUnit (Assertion, (@=?))
14−import Test.HUnit (Assertion, (@=?))
15
14
16
15
17--------------------------------------------------------------------------------
16--------------------------------------------------------------------------------
18import Hakyll.Core.Dependencies
17import Hakyll.Core.Dependencies
19import Hakyll.Core.Identifier
18import Hakyll.Core.Identifier
19+import TestSuite.Util
20
20
21
21
22--------------------------------------------------------------------------------
22--------------------------------------------------------------------------------
23tests :: Test
23tests :: Test
24−tests = testGroup "Hakyll.Core.Dependencies.Tests"
24+tests = testGroup "Hakyll.Core.Dependencies.Tests" $
25− [ testCase "case01" case01
25+ fromAssertions "analyze" [case01, case02, case03]
26− , testCase "case02" case02
27− , testCase "case03" case03
28− ]
29
26
30
27
31--------------------------------------------------------------------------------
28--------------------------------------------------------------------------------
tests/Hakyll/Core/Util/Arrow/Tests.hsdeleted−14
@@ -1,14 +0,0 @@
1−module Hakyll.Core.Util.Arrow.Tests
2− ( tests
3− ) where
4−
5−import Test.Framework (Test)
6−import Test.HUnit ((@=?))
7−
8−import Hakyll.Core.Util.Arrow
9−import TestSuite.Util
10−
11−tests :: [Test]
12−tests = fromAssertions "sequenceA"
13− [ [8, 20, 1] @=? sequenceA [(+ 4), (* 5), signum] (4 :: Int)
14− ]
tests/Hakyll/Web/Urls/Relativize/Tests.hs+28−18
@@ -1,25 +1,35 @@
1+--------------------------------------------------------------------------------
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2module Hakyll.Web.Urls.Relativize.Tests
3module Hakyll.Web.Urls.Relativize.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.Web.Urls.Relativize
8+--------------------------------------------------------------------------------
10−import TestSuite.Util
9+import Test.Framework (Test, testGroup)
10+import Test.HUnit ((@=?))
11
11
12+
13+--------------------------------------------------------------------------------
14+import Hakyll.Web.Urls.Relativize
15+import TestSuite.Util
16+
17+
18+--------------------------------------------------------------------------------
12−tests :: [Test]
19+tests :: Test
20+tests = testGroup "Hakyll.Web.Urls.Relativize.Tests" $
13−tests = fromAssertions "relativizeUrls"
21+ fromAssertions "relativizeUrls"
14− [ "<a href=\"../foo\">bar</a>" @=?
22+ [ "<a href=\"../foo\">bar</a>" @=?
15− relativizeUrls ".." "<a href=\"/foo\">bar</a>"
23+ relativizeUrlsWith ".." "<a href=\"/foo\">bar</a>"
16− , "<img src=\"../../images/lolcat.png\"></img>" @=?
24+ , "<img src=\"../../images/lolcat.png\"></img>" @=?
17− relativizeUrls "../.." "<img src=\"/images/lolcat.png\" />"
25+ relativizeUrlsWith "../.." "<img src=\"/images/lolcat.png\" />"
18− , "<a href=\"http://haskell.org\">Haskell</a>" @=?
26+ , "<a href=\"http://haskell.org\">Haskell</a>" @=?
27+ relativizeUrlsWith "../.."
19− relativizeUrls "../.." "<a href=\"http://haskell.org\">Haskell</a>"
28+ "<a href=\"http://haskell.org\">Haskell</a>"
20− , "<a href=\"http://haskell.org\">Haskell</a>" @=?
29+ , "<a href=\"http://haskell.org\">Haskell</a>" @=?
30+ relativizeUrlsWith "../.."
21− relativizeUrls "../.." "<a href=\"http://haskell.org\">Haskell</a>"
31+ "<a href=\"http://haskell.org\">Haskell</a>"
22− , "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>" @=?
32+ , "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>" @=?
23− relativizeUrls "../.."
33+ relativizeUrlsWith "../.."
24− "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>"
34+ "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>"
25− ]
35+ ]
tests/Hakyll/Web/Urls/Tests.hs+16−7
@@ -1,17 +1,23 @@
1+--------------------------------------------------------------------------------
1module Hakyll.Web.Urls.Tests
2module Hakyll.Web.Urls.Tests
2 ( tests
3 ( tests
3 ) where
4 ) where
4
5
5−import Data.Char (toUpper)
6
6
7+--------------------------------------------------------------------------------
8+import Data.Char (toUpper)
7−import Test.Framework
9+import Test.Framework (Test, testGroup)
8−import Test.HUnit hiding (Test)
10+import Test.HUnit (assert, (@=?))
9
11
10−import Hakyll.Web.Urls
11−import TestSuite.Util
12
12
13+--------------------------------------------------------------------------------
14+import Hakyll.Web.Urls
15+import TestSuite.Util
16+
17+
18+--------------------------------------------------------------------------------
13−tests :: [Test]
19+tests :: Test
14−tests = concat
20+tests = testGroup "Hakyll.Web.Urls.Tests" $ concat
15 [ fromAssertions "withUrls"
21 [ fromAssertions "withUrls"
16 [ "<a href=\"FOO\">bar</a>" @=?
22 [ "<a href=\"FOO\">bar</a>" @=?
17 withUrls (map toUpper) "<a href=\"foo\">bar</a>"
23 withUrls (map toUpper) "<a href=\"foo\">bar</a>"
@@ -26,17 +32,20 @@ tests = concat
26 , "<style>body > p { line-height: 1.3 }</style>" @=?
32 , "<style>body > p { line-height: 1.3 }</style>" @=?
27 withUrls id "<style>body > p { line-height: 1.3 }</style>"
33 withUrls id "<style>body > p { line-height: 1.3 }</style>"
28 ]
34 ]
35+
29 , fromAssertions "toUrl"
36 , fromAssertions "toUrl"
30 [ "/foo/bar.html" @=? toUrl "foo/bar.html"
37 [ "/foo/bar.html" @=? toUrl "foo/bar.html"
31 , "/" @=? toUrl "/"
38 , "/" @=? toUrl "/"
32 , "/funny-pics.html" @=? toUrl "/funny-pics.html"
39 , "/funny-pics.html" @=? toUrl "/funny-pics.html"
33 ]
40 ]
41+
34 , fromAssertions "toSiteRoot"
42 , fromAssertions "toSiteRoot"
35 [ ".." @=? toSiteRoot "/foo/bar.html"
43 [ ".." @=? toSiteRoot "/foo/bar.html"
36 , "." @=? toSiteRoot "index.html"
44 , "." @=? toSiteRoot "index.html"
37 , "." @=? toSiteRoot "/index.html"
45 , "." @=? toSiteRoot "/index.html"
38 , "../.." @=? toSiteRoot "foo/bar/qux"
46 , "../.." @=? toSiteRoot "foo/bar/qux"
39 ]
47 ]
48+
40 , fromAssertions "isExternal"
49 , fromAssertions "isExternal"
41 [ assert (isExternal "http://reddit.com")
50 [ assert (isExternal "http://reddit.com")
42 , assert (isExternal "https://mail.google.com")
51 , assert (isExternal "https://mail.google.com")
tests/TestSuite.hs+4
@@ -15,6 +15,8 @@ import qualified Hakyll.Core.Provider.Tests
15import qualified Hakyll.Core.Store.Tests
15import qualified Hakyll.Core.Store.Tests
16import qualified Hakyll.Core.UnixFilter.Tests
16import qualified Hakyll.Core.UnixFilter.Tests
17import qualified Hakyll.Web.Template.Tests
17import qualified Hakyll.Web.Template.Tests
18+import qualified Hakyll.Web.Urls.Tests
19+import qualified Hakyll.Web.Urls.Relativize.Tests
18
20
19
21
20--------------------------------------------------------------------------------
22--------------------------------------------------------------------------------
@@ -26,4 +28,6 @@ main = defaultMain
26 , Hakyll.Core.Store.Tests.tests
28 , Hakyll.Core.Store.Tests.tests
27 , Hakyll.Core.UnixFilter.Tests.tests
29 , Hakyll.Core.UnixFilter.Tests.tests
28 , Hakyll.Web.Template.Tests.tests
30 , Hakyll.Web.Template.Tests.tests
31+ , Hakyll.Web.Urls.Tests.tests
32+ , Hakyll.Web.Urls.Relativize.Tests.tests
29 ]
33 ]
tests/TestSuite/Util.hs+3−3
@@ -17,6 +17,7 @@ import System.Directory (removeDirectoryRecursive)
17import Test.Framework
17import Test.Framework
18import Test.Framework.Providers.HUnit
18import Test.Framework.Providers.HUnit
19import Test.HUnit hiding (Test)
19import Test.HUnit hiding (Test)
20+import Text.Printf (printf)
20
21
21
22
22--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
@@ -32,9 +33,8 @@ import qualified Hakyll.Core.Store as Store
32fromAssertions :: String -- ^ Name
33fromAssertions :: String -- ^ Name
33 -> [Assertion] -- ^ Cases
34 -> [Assertion] -- ^ Cases
34 -> [Test] -- ^ Result tests
35 -> [Test] -- ^ Result tests
35−fromAssertions name = zipWith testCase names
36+fromAssertions name =
36− where
37+ zipWith testCase [printf "%s [%3d]" name n | n <- [1 :: Int ..]]
37− names = map (\n -> name ++ " [" ++ show n ++ "]") [1 :: Int ..]
38
38
39
39
40--------------------------------------------------------------------------------
40--------------------------------------------------------------------------------