on master help sign in
Fix test failure
f905856Jasper Van der Jeugt
tests/Hakyll/Core/Provider/Metadata/Tests.hs+11−3
@@ -11,7 +11,7 @@ import qualified Data.Yaml as Yaml
11import Hakyll.Core.Metadata
11import Hakyll.Core.Metadata
12import Hakyll.Core.Provider.Metadata
12import Hakyll.Core.Provider.Metadata
13import Test.Framework (Test, testGroup)
13import Test.Framework (Test, testGroup)
14−import Test.HUnit (Assertion, (@=?))
14+import Test.HUnit (Assertion, (@=?), assertFailure)
15import TestSuite.Util
15import TestSuite.Util
16
16
17
17
@@ -25,7 +25,7 @@ tests = testGroup "Hakyll.Core.Provider.Metadata.Tests" $
25--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
26testPage01 :: Assertion
26testPage01 :: Assertion
27testPage01 =
27testPage01 =
28− Right (meta [("foo", "bar")], "qux\n") @=? parsePage
28+ (meta [("foo", "bar")], "qux\n") `expectRight` parsePage
29 "---\n\
29 "---\n\
30 \foo: bar\n\
30 \foo: bar\n\
31 \---\n\
31 \---\n\
@@ -35,7 +35,7 @@ testPage01 =
35--------------------------------------------------------------------------------
35--------------------------------------------------------------------------------
36testPage02 :: Assertion
36testPage02 :: Assertion
37testPage02 =
37testPage02 =
38− Right (meta [("description", descr)], "Hello I am dog\n") @=?
38+ (meta [("description", descr)], "Hello I am dog\n") `expectRight`
39 parsePage
39 parsePage
40 "---\n\
40 "---\n\
41 \description: A long description that would look better if it\n\
41 \description: A long description that would look better if it\n\
@@ -52,3 +52,11 @@ testPage02 =
52--------------------------------------------------------------------------------
52--------------------------------------------------------------------------------
53meta :: Yaml.ToJSON a => [(String, a)] -> Metadata
53meta :: Yaml.ToJSON a => [(String, a)] -> Metadata
54meta pairs = HMS.fromList [(T.pack k, Yaml.toJSON v) | (k, v) <- pairs]
54meta pairs = HMS.fromList [(T.pack k, Yaml.toJSON v) | (k, v) <- pairs]
55+
56+
57+--------------------------------------------------------------------------------
58+-- | This is useful when the 'Left' side of 'Either' doesn't have an 'Eq'
59+-- instance.
60+expectRight :: (Eq b, Show a, Show b) => b -> Either a b -> Assertion
61+expectRight _ (Left err) = assertFailure (show err)
62+expectRight expected (Right res) = expected @=? res