Skip to content

Commit

Permalink
Added assertEq, deprecated assertEqual
Browse files Browse the repository at this point in the history
use assertEq instead
  • Loading branch information
bitemyapp committed Aug 10, 2016
1 parent 9ce2770 commit 13d9f58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
20 changes: 18 additions & 2 deletions yesod-test/Yesod/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}

{-|
Yesod.Test is a pragmatic framework for testing web applications built
using wai and persistent.
Expand Down Expand Up @@ -84,6 +85,9 @@ module Yesod.Test

-- * Assertions
, assertEqual
, assertEqualNoShow
, assertEq

, assertHeader
, assertNoHeader
, statusIs
Expand Down Expand Up @@ -139,6 +143,7 @@ import qualified Web.Cookie as Cookie
import qualified Blaze.ByteString.Builder as Builder
import Data.Time.Clock (getCurrentTime)
import Control.Applicative ((<$>))
import Text.Show.Pretty (ppShow)

-- | The state used in a single test case defined using 'yit'
--
Expand Down Expand Up @@ -314,9 +319,20 @@ htmlQuery' getter errTrace query = withResponse' getter ("Tried to invoke htmlQu
htmlQuery :: Query -> YesodExample site [HtmlLBS]
htmlQuery = htmlQuery' yedResponse []

-- | Asserts that the two given values are equal.
assertEq :: (Eq a, Show a) => String -> a -> a -> YesodExample site ()
assertEq m a b =
liftIO $ HUnit.assertBool msg (a == b)
where msg = "Assertion: " ++ m ++ "\n" ++
"First argument: " ++ ppShow a ++ "\n" ++
"Second argument: " ++ ppShow b ++ "\n"

{-# DEPRECATED assertEqual "Use assertEq instead" #-}
assertEqual :: (Eq a) => String -> a -> a -> YesodExample site ()
assertEqual msg a b = liftIO $ HUnit.assertBool msg (a == b)
assertEqual = assertEqualNoShow

-- | Asserts that the two given values are equal.
assertEqualNoShow :: (Eq a) => String -> a -> a -> YesodExample site ()
assertEqualNoShow msg a b = liftIO $ HUnit.assertBool msg (a == b)

-- | Assert the last response status is as expected.
statusIs :: Int -> YesodExample site ()
Expand Down
33 changes: 17 additions & 16 deletions yesod-test/yesod-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@ description: API docs and the README are available at <http://www.stackage.o
extra-source-files: README.md, LICENSE, test/main.hs, ChangeLog.md

library
build-depends: base >= 4.3 && < 5
build-depends: HUnit >= 1.2
, attoparsec >= 0.10
, persistent >= 1.0
, transformers >= 0.2.2
, wai >= 3.0
, wai-extra
, network >= 2.2
, http-types >= 0.7
, HUnit >= 1.2
, hspec-core == 2.*
, base >= 4.3 && < 5
, blaze-builder
, blaze-html >= 0.5
, blaze-markup >= 0.5.1
, bytestring >= 0.9
, case-insensitive >= 0.2
, text
, xml-conduit >= 1.0
, xml-types >= 0.3
, containers
, cookie
, hspec-core == 2.*
, html-conduit >= 0.1
, blaze-html >= 0.5
, blaze-markup >= 0.5.1
, http-types >= 0.7
, monad-control
, network >= 2.2
, persistent >= 1.0
, pretty-show >= 1.6
, text
, time
, blaze-builder
, cookie
, transformers >= 0.2.2
, wai >= 3.0
, wai-extra
, xml-conduit >= 1.0
, xml-types >= 0.3
, yesod-core >= 1.4.14

exposed-modules: Yesod.Test
Expand Down

0 comments on commit 13d9f58

Please sign in to comment.