lib: expectEq', expectParseEq: pretty-print compared values (#812)
This commit is contained in:
parent
e05188831e
commit
dab75d98c8
@ -7,6 +7,7 @@ import Control.Exception
|
||||
import Control.Monad
|
||||
import Control.Monad.State.Strict (StateT)
|
||||
--import Control.Monad.State.Strict (evalStateT)
|
||||
import Data.CallStack
|
||||
import Data.Functor.Identity
|
||||
import Data.List
|
||||
import qualified Data.Text as T
|
||||
@ -102,7 +103,12 @@ runEasyTests args easytests = (do
|
||||
expectParseEq :: (Monoid st, Eq a, Show a) => StateT st (ParsecT CustomErr T.Text Identity) a -> T.Text -> a -> EasyTest.Test ()
|
||||
expectParseEq parser input expected = do
|
||||
let ep = runIdentity $ parseWithState mempty parser input
|
||||
either (fail.("parse error at "++).parseErrorPretty) (flip expectEq expected) ep
|
||||
either (fail.("parse error at "++).parseErrorPretty) (flip expectEq' expected) ep
|
||||
|
||||
-- | Like easytest's expectEq, but pretty-prints the values in failure output.
|
||||
expectEq' :: (Eq a, Show a, HasCallStack) => a -> a -> EasyTest.Test ()
|
||||
expectEq' x y = if x == y then ok else crash $
|
||||
"expected:\n" <> T.pack (pshow x) <> "\nbut got:\n" <> T.pack (pshow y) <> "\n"
|
||||
|
||||
-- | Run some hunit tests, returning True if there was a problem.
|
||||
-- With arguments, runs only tests whose names contain the first argument
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: b52d450888004e007b3689cfe42d916ab8e8af3bc91a6a374ff022a719e86611
|
||||
-- hash: 297d8918f59c94ceae6e61bc5df3a67247c22d5cd135ae9f9ffc8fd84cf144d7
|
||||
|
||||
name: hledger-lib
|
||||
version: 1.10.99
|
||||
@ -111,6 +111,7 @@ library
|
||||
, base-compat-batteries >=0.10.1 && <0.11
|
||||
, blaze-markup >=0.5.1
|
||||
, bytestring
|
||||
, call-stack
|
||||
, cmdargs >=0.10
|
||||
, containers
|
||||
, csv
|
||||
@ -209,6 +210,7 @@ test-suite doctests
|
||||
, base-compat-batteries >=0.10.1 && <0.11
|
||||
, blaze-markup >=0.5.1
|
||||
, bytestring
|
||||
, call-stack
|
||||
, cmdargs >=0.10
|
||||
, containers
|
||||
, csv
|
||||
@ -308,6 +310,7 @@ test-suite easytests
|
||||
, base-compat-batteries >=0.10.1 && <0.11
|
||||
, blaze-markup >=0.5.1
|
||||
, bytestring
|
||||
, call-stack
|
||||
, cmdargs >=0.10
|
||||
, containers
|
||||
, csv
|
||||
@ -407,6 +410,7 @@ test-suite hunittests
|
||||
, base-compat-batteries >=0.10.1 && <0.11
|
||||
, blaze-markup >=0.5.1
|
||||
, bytestring
|
||||
, call-stack
|
||||
, cmdargs >=0.10
|
||||
, containers
|
||||
, csv
|
||||
|
||||
@ -45,6 +45,7 @@ dependencies:
|
||||
- array
|
||||
- blaze-markup >=0.5.1
|
||||
- bytestring
|
||||
- call-stack
|
||||
- cmdargs >=0.10
|
||||
- containers
|
||||
- csv
|
||||
|
||||
Loading…
Reference in New Issue
Block a user