on master help sign in
Update more tests
commitb5adcb69d1cd26e613c5c56c85307050bb8297cf authorJasper Van der Jeugt <m@jaspervdj.be> dateTue 20 Nov 2012, 11:50 (14 years ago) parentbfa1056
11 files changed+61−134
hakyll.cabal−1 src/Hakyll.hs−2 src/Hakyll/Core/UnixFilter.hs+2−2 src/Hakyll/Core/Util/Arrow.hs−40 tests/Hakyll/Core/Compiler/Tests.hs−36 tests/Hakyll/Core/Dependencies/Tests.hs+8−11 tests/Hakyll/Core/Util/Arrow/Tests.hs−14 tests/Hakyll/Web/Urls/Relativize/Tests.hs+28−18 tests/Hakyll/Web/Urls/Tests.hs+16−7 tests/TestSuite.hs+4 tests/TestSuite/Util.hs+3−3
hakyll.cabal−1
@@ -109,7 +109,6 @@ Library
109109 Hakyll.Core.Rules
110110 Hakyll.Core.Runtime
111111 Hakyll.Core.Store
112− Hakyll.Core.Util.Arrow
113112 Hakyll.Core.Util.File
114113 Hakyll.Core.Util.String
115114 Hakyll.Core.Writable
src/Hakyll.hs−2
@@ -13,7 +13,6 @@ module Hakyll
1313#ifdef UNIX_FILTER
1414 , module Hakyll.Core.UnixFilter
1515#endif
16− , module Hakyll.Core.Util.Arrow
1716 , module Hakyll.Core.Util.File
1817 , module Hakyll.Core.Util.String
1918 , module Hakyll.Core.Writable
@@ -46,7 +45,6 @@ import Hakyll.Core.Rules
4645#ifdef UNIX_FILTER
4746import Hakyll.Core.UnixFilter
4847#endif
49−import Hakyll.Core.Util.Arrow
5048import Hakyll.Core.Util.File
5149import Hakyll.Core.Util.String
5250import Hakyll.Core.Writable
src/Hakyll/Core/UnixFilter.hs+2−2
@@ -26,7 +26,7 @@ import Hakyll.Core.Compiler
2626-- as a compiler.
2727--
2828-- > rev :: Compiler String
29−-- > rev = getResourceString >>= unixFilter "rev" []
29+-- > rev = getResourceString >>= itemM (unixFilter "rev" [])
3030--
3131-- A more realistic example: one can use this to call, for example, the sass
3232-- compiler on CSS files. More information about sass can be found here:
@@ -38,7 +38,7 @@ import Hakyll.Core.Compiler
3838-- > match "style.scss" $ do
3939-- > route $ setExtension "css"
4040-- > compile $ getResourceString >>=
41−-- > unixFilter "sass" ["-s", "--scss"] >>=
41+-- > itemM (unixFilter "sass" ["-s", "--scss"]) >>=
4242-- > compressCssCompiler
4343unixFilter :: String -- ^ Program name
4444 -> [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
66
77
88--------------------------------------------------------------------------------
9−import Data.List (delete)
10−import qualified Data.Map as M
11−import qualified Data.Set as S
12−import Test.Framework (Test, testGroup)
13−import Test.Framework.Providers.HUnit (testCase)
14−import Test.HUnit (Assertion, (@=?))
9+import Data.List (delete)
10+import qualified Data.Map as M
11+import qualified Data.Set as S
12+import Test.Framework (Test, testGroup)
13+import Test.HUnit (Assertion, (@=?))
1514
1615
1716--------------------------------------------------------------------------------
1817import Hakyll.Core.Dependencies
1918import Hakyll.Core.Identifier
19+import TestSuite.Util
2020
2121
2222--------------------------------------------------------------------------------
2323tests :: Test
24−tests = testGroup "Hakyll.Core.Dependencies.Tests"
25− [ testCase "case01" case01
26− , testCase "case02" case02
27− , testCase "case03" case03
28− ]
24+tests = testGroup "Hakyll.Core.Dependencies.Tests" $
25+ fromAssertions "analyze" [case01, case02, case03]
2926
3027
3128--------------------------------------------------------------------------------
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+--------------------------------------------------------------------------------
12{-# LANGUAGE OverloadedStrings #-}
23module Hakyll.Web.Urls.Relativize.Tests
34 ( tests
45 ) where
56
6−import Test.Framework
7−import Test.HUnit hiding (Test)
87
9−import Hakyll.Web.Urls.Relativize
10−import TestSuite.Util
8+--------------------------------------------------------------------------------
9+import Test.Framework (Test, testGroup)
10+import Test.HUnit ((@=?))
1111
12−tests :: [Test]
13−tests = fromAssertions "relativizeUrls"
14− [ "<a href=\"../foo\">bar</a>" @=?
15− relativizeUrls ".." "<a href=\"/foo\">bar</a>"
16− , "<img src=\"../../images/lolcat.png\"></img>" @=?
17− relativizeUrls "../.." "<img src=\"/images/lolcat.png\" />"
18− , "<a href=\"http://haskell.org\">Haskell</a>" @=?
19− relativizeUrls "../.." "<a href=\"http://haskell.org\">Haskell</a>"
20− , "<a href=\"http://haskell.org\">Haskell</a>" @=?
21− relativizeUrls "../.." "<a href=\"http://haskell.org\">Haskell</a>"
22− , "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>" @=?
23− relativizeUrls "../.."
24− "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>"
25− ]
12+
13+--------------------------------------------------------------------------------
14+import Hakyll.Web.Urls.Relativize
15+import TestSuite.Util
16+
17+
18+--------------------------------------------------------------------------------
19+tests :: Test
20+tests = testGroup "Hakyll.Web.Urls.Relativize.Tests" $
21+ fromAssertions "relativizeUrls"
22+ [ "<a href=\"../foo\">bar</a>" @=?
23+ relativizeUrlsWith ".." "<a href=\"/foo\">bar</a>"
24+ , "<img src=\"../../images/lolcat.png\"></img>" @=?
25+ relativizeUrlsWith "../.." "<img src=\"/images/lolcat.png\" />"
26+ , "<a href=\"http://haskell.org\">Haskell</a>" @=?
27+ relativizeUrlsWith "../.."
28+ "<a href=\"http://haskell.org\">Haskell</a>"
29+ , "<a href=\"http://haskell.org\">Haskell</a>" @=?
30+ relativizeUrlsWith "../.."
31+ "<a href=\"http://haskell.org\">Haskell</a>"
32+ , "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>" @=?
33+ relativizeUrlsWith "../.."
34+ "<script src=\"//ajax.googleapis.com/jquery.min.js\"></script>"
35+ ]
tests/Hakyll/Web/Urls/Tests.hs+16−7
@@ -1,17 +1,23 @@
1+--------------------------------------------------------------------------------
12module Hakyll.Web.Urls.Tests
23 ( tests
34 ) where
45
5−import Data.Char (toUpper)
66
7−import Test.Framework
8−import Test.HUnit hiding (Test)
7+--------------------------------------------------------------------------------
8+import Data.Char (toUpper)
9+import Test.Framework (Test, testGroup)
10+import Test.HUnit (assert, (@=?))
911
10−import Hakyll.Web.Urls
11−import TestSuite.Util
1212
13−tests :: [Test]
14−tests = concat
13+--------------------------------------------------------------------------------
14+import Hakyll.Web.Urls
15+import TestSuite.Util
16+
17+
18+--------------------------------------------------------------------------------
19+tests :: Test
20+tests = testGroup "Hakyll.Web.Urls.Tests" $ concat
1521 [ fromAssertions "withUrls"
1622 [ "<a href=\"FOO\">bar</a>" @=?
1723 withUrls (map toUpper) "<a href=\"foo\">bar</a>"
@@ -26,17 +32,20 @@ tests = concat
2632 , "<style>body > p { line-height: 1.3 }</style>" @=?
2733 withUrls id "<style>body > p { line-height: 1.3 }</style>"
2834 ]
35+
2936 , fromAssertions "toUrl"
3037 [ "/foo/bar.html" @=? toUrl "foo/bar.html"
3138 , "/" @=? toUrl "/"
3239 , "/funny-pics.html" @=? toUrl "/funny-pics.html"
3340 ]
41+
3442 , fromAssertions "toSiteRoot"
3543 [ ".." @=? toSiteRoot "/foo/bar.html"
3644 , "." @=? toSiteRoot "index.html"
3745 , "." @=? toSiteRoot "/index.html"
3846 , "../.." @=? toSiteRoot "foo/bar/qux"
3947 ]
48+
4049 , fromAssertions "isExternal"
4150 [ assert (isExternal "http://reddit.com")
4251 , assert (isExternal "https://mail.google.com")
tests/TestSuite.hs+4
@@ -15,6 +15,8 @@ import qualified Hakyll.Core.Provider.Tests
1515import qualified Hakyll.Core.Store.Tests
1616import qualified Hakyll.Core.UnixFilter.Tests
1717import qualified Hakyll.Web.Template.Tests
18+import qualified Hakyll.Web.Urls.Tests
19+import qualified Hakyll.Web.Urls.Relativize.Tests
1820
1921
2022--------------------------------------------------------------------------------
@@ -26,4 +28,6 @@ main = defaultMain
2628 , Hakyll.Core.Store.Tests.tests
2729 , Hakyll.Core.UnixFilter.Tests.tests
2830 , Hakyll.Web.Template.Tests.tests
31+ , Hakyll.Web.Urls.Tests.tests
32+ , Hakyll.Web.Urls.Relativize.Tests.tests
2933 ]
tests/TestSuite/Util.hs+3−3
@@ -17,6 +17,7 @@ import System.Directory (removeDirectoryRecursive)
1717import Test.Framework
1818import Test.Framework.Providers.HUnit
1919import Test.HUnit hiding (Test)
20+import Text.Printf (printf)
2021
2122
2223--------------------------------------------------------------------------------
@@ -32,9 +33,8 @@ import qualified Hakyll.Core.Store as Store
3233fromAssertions :: String -- ^ Name
3334 -> [Assertion] -- ^ Cases
3435 -> [Test] -- ^ Result tests
35−fromAssertions name = zipWith testCase names
36− where
37− names = map (\n -> name ++ " [" ++ show n ++ "]") [1 :: Int ..]
36+fromAssertions name =
37+ zipWith testCase [printf "%s [%3d]" name n | n <- [1 :: Int ..]]
3838
3939
4040--------------------------------------------------------------------------------