After seeing how nice HUnit formats the error message on failed 'assertEqual', I think we can do better with ==?. Currently it says (on one line): "Expected equality, but 1 /= 2".
This patch changes the code to format it similar to HUnit: Expected equality, but got mismatch expected: 1 but got: 2 (on three lines). This makes it more clear what is the expected and what is the wrong value. A few tests have been modified to ensure that the expected value is the second argument to ==?. This is different than HUnit, but makes more sense in the operator version (I think). Signed-off-by: Iustin Pop <[email protected]> --- htest/Test/Ganeti/Confd/Utils.hs | 4 ++-- htest/Test/Ganeti/HTools/PeerMap.hs | 4 ++-- htest/Test/Ganeti/TestCommon.hs | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/htest/Test/Ganeti/Confd/Utils.hs b/htest/Test/Ganeti/Confd/Utils.hs index fea3dd9..f596ae3 100644 --- a/htest/Test/Ganeti/Confd/Utils.hs +++ b/htest/Test/Ganeti/Confd/Utils.hs @@ -96,8 +96,8 @@ prop_bad_key salt crq = let signed = Confd.Utils.signMessage key_sign salt (J.encode crq) encoded = J.encode signed in printTestCase ("Accepted message signed with different key" ++ encoded) $ - BasicTypes.Bad "HMAC verification failed" ==? - Confd.Utils.parseRequest key_verify encoded + Confd.Utils.parseRequest key_verify encoded ==? + BasicTypes.Bad "HMAC verification failed" testSuite "Confd/Utils" [ 'prop_req_sign diff --git a/htest/Test/Ganeti/HTools/PeerMap.hs b/htest/Test/Ganeti/HTools/PeerMap.hs index c214271..810c1fd 100644 --- a/htest/Test/Ganeti/HTools/PeerMap.hs +++ b/htest/Test/Ganeti/HTools/PeerMap.hs @@ -39,14 +39,14 @@ import qualified Ganeti.HTools.PeerMap as PeerMap prop_addIdempotent :: PeerMap.PeerMap -> PeerMap.Key -> PeerMap.Elem -> Property prop_addIdempotent pmap key em = - fn puniq ==? fn (fn puniq) + fn (fn puniq) ==? fn puniq where fn = PeerMap.add key em puniq = PeerMap.accumArray const pmap -- | Make sure remove is idempotent. prop_removeIdempotent :: PeerMap.PeerMap -> PeerMap.Key -> Property prop_removeIdempotent pmap key = - fn puniq ==? fn (fn puniq) + fn (fn puniq) ==? fn puniq where fn = PeerMap.remove key puniq = PeerMap.accumArray const pmap diff --git a/htest/Test/Ganeti/TestCommon.hs b/htest/Test/Ganeti/TestCommon.hs index a5f7490..128234e 100644 --- a/htest/Test/Ganeti/TestCommon.hs +++ b/htest/Test/Ganeti/TestCommon.hs @@ -73,11 +73,12 @@ maxOpCodes = 16 -- * Helper functions --- | Checks for equality with proper annotation. +-- | Checks for equality with proper annotation. The first argument is +-- the computed value, the second one the expected value. (==?) :: (Show a, Eq a) => a -> a -> Property (==?) x y = printTestCase - ("Expected equality, but '" ++ - show x ++ "' /= '" ++ show y ++ "'") (x == y) + ("Expected equality, but got mismatch\nexpected: " ++ + show x ++ "\n but got: " ++ show y) (x == y) infix 3 ==? -- | Checks for inequality with proper annotation. -- 1.7.7.3
