Commit b5334d80 authored by Michele Tartara's avatar Michele Tartara
Browse files

Add function testing parsers with QuickCheck



Parsing a string automatically generated by QuickCheck can be useful in many
cases. A function for doing this is added to the common test functions.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 688f35e6
......@@ -62,6 +62,7 @@ module Test.Ganeti.TestCommon
, readTestData
, genSample
, testParser
, genPropParser
, genNonNegative
) where
......@@ -377,6 +378,13 @@ testParser parser fileName expectedContent = do
Left msg -> HUnit.assertFailure $ "Parsing failed: " ++ msg
Right obtained -> HUnit.assertEqual fileName expectedContent obtained
-- | Generate a property test for parsers.
genPropParser :: (Show a, Eq a) => Parser a -> String -> a -> Property
genPropParser parser s expected =
case parseOnly parser $ pack s of
Left msg -> failTest $ "Parsing failed: " ++ msg
Right obtained -> expected ==? obtained
-- | Generate an arbitrary non negative integer number
genNonNegative :: Gen Int
genNonNegative =
......
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