Commit 41eb900e authored by Iustin Pop's avatar Iustin Pop
Browse files

Improve message for (==?) operator



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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 37519c09
......@@ -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
......
......@@ -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
......
......@@ -73,14 +73,17 @@ 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.
-- | Checks for inequality with proper annotation. The first argument
-- is the computed value, the second one the expected (not equal)
-- value.
(/=?) :: (Show a, Eq a) => a -> a -> Property
(/=?) x y = printTestCase
("Expected inequality, but got equality: '" ++
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment