Last active
August 19, 2020 16:51
-
-
Save paolino/fdadced749dedf10c762869291d5b737 to your computer and use it in GitHub Desktop.
pretty report inequality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
dependencies: | |
- base | |
- protolude | |
- tree-diff | |
-} | |
import Data.Typeable (Typeable) | |
import Data.TreeDiff (toExpr, exprDiff, ansiWlEditExpr, ToExpr) | |
import Text.Printf (printf) | |
import Test.HUnit (assertFailure) | |
-- | show a coloured difference of 2 values | |
prettyDifferences :: (ToExpr a) => a -> a -> String | |
prettyDifferences a1 a2 = | |
show $ ansiWlEditExpr $ exprDiff (toExpr a1) (toExpr a2) | |
infixl 4 @?= | |
-- | equality test which show pretty differences on fail | |
(@?=) :: (ToExpr a, Eq a, Typeable a) => a -> a -> IO () | |
a1 @?= a2 = | |
if a1 == a2 | |
then return () | |
else assertFailure $ printf "Expected equality:\n%s" $ | |
prettyDifferences a1 a2 | |
shouldBe :: (ToExpr a, Eq a, Typeable a) => a -> a -> IO () | |
shouldBe = (@?=) |
Author
paolino
commented
Aug 19, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment