module Test.Amazonka.Assert where
import Control.Monad
import Test.Amazonka.Diff
import Test.Amazonka.Orphans ()
import Test.Tasty.HUnit
assertDiff :: (Eq a, Show a) => String -> a -> Either String a -> Assertion
assertDiff :: String -> a -> Either String a -> Assertion
assertDiff String
_ a
_ (Left String
m) = String -> Assertion
forall a. HasCallStack => String -> IO a
assertFailure String
m
assertDiff String
n a
e (Right a
a) = Bool -> Assertion -> Assertion
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (a
e a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a) (IO String
msg IO String -> (String -> Assertion) -> Assertion
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Assertion
forall a. HasCallStack => String -> IO a
assertFailure)
where
msg :: IO String
msg = do
String
d <- a -> a -> IO String
forall a b. (Show a, Show b) => a -> b -> IO String
diff a
e a
a
String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> IO String) -> String -> IO String
forall a b. (a -> b) -> a -> b
$! String
"[Expected]:\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
e
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n["
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]:\n"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
a
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
d