From dddb2bc9db777eb546b5bfd302c8637e539016cd Mon Sep 17 00:00:00 2001 From: Helga Velroyen Date: Mon, 22 Oct 2012 13:08:46 +0200 Subject: [PATCH] Annotated inequality operator for unit test properties This includes: * The operator (/=?), which checks for inequality and prints an error message if it encounters equality. (Basically the negation of the (==?) operator). * Application of this operator in the test property prop_addPri_NoN1Fail. Signed-off-by: Helga Velroyen Reviewed-by: Iustin Pop --- htest/Test/Ganeti/HTools/Node.hs | 4 +--- htest/Test/Ganeti/TestCommon.hs | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/htest/Test/Ganeti/HTools/Node.hs b/htest/Test/Ganeti/HTools/Node.hs index 3e4ea8b..2dd9c21 100644 --- a/htest/Test/Ganeti/HTools/Node.hs +++ b/htest/Test/Ganeti/HTools/Node.hs @@ -138,9 +138,7 @@ prop_addPri_NoN1Fail = forAll genOnlineNode $ \node -> forAll (genInstanceSmallerThanNode node) $ \inst -> let inst' = inst { Instance.mem = Node.fMem node - Node.rMem node } - in case Node.addPri node inst' of - Bad Types.FailN1 -> False - _ -> True + in (Node.addPri node inst' /=? Bad Types.FailN1) -- | Check that an instance add with too high memory or disk will be -- rejected. diff --git a/htest/Test/Ganeti/TestCommon.hs b/htest/Test/Ganeti/TestCommon.hs index d61cfb8..a5f7490 100644 --- a/htest/Test/Ganeti/TestCommon.hs +++ b/htest/Test/Ganeti/TestCommon.hs @@ -80,6 +80,13 @@ maxOpCodes = 16 show x ++ "' /= '" ++ show y ++ "'") (x == y) infix 3 ==? +-- | Checks for inequality with proper annotation. +(/=?) :: (Show a, Eq a) => a -> a -> Property +(/=?) x y = printTestCase + ("Expected inequality, but got equality: '" ++ + show x ++ "'.") (x /= y) +infix 3 /=? + -- | Show a message and fail the test. failTest :: String -> Property failTest msg = printTestCase msg False -- 1.7.10.4