Commit 8a1b6f9b authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add a stable version of cover



Work around the limitation of QuickChecks `cover` to ignore
all coverage labels that do not occur in the actual sample.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarNiklas Hambuechen <niklash@google.com>
parent ce44ba6a
......@@ -47,6 +47,7 @@ module Test.Ganeti.TestCommon
, (/=?)
, failTest
, passTest
, stableCover
, pythonCmd
, runPython
, checkPythonResult
......@@ -182,6 +183,18 @@ failTest msg = printTestCase msg False
passTest :: Property
passTest = property True
-- | A stable version of QuickCheck's `cover`. In its current implementation,
-- cover will not detect insufficient coverage if the actual coverage in the
-- sample is 0. Work around this by lifting the probability to at least
-- 10 percent.
-- The underlying issue is tracked at
-- https://github.com/nick8325/quickcheck/issues/26
stableCover :: Testable prop => Bool -> Int -> String -> prop -> Property
stableCover pred percent label prop =
let newlabel = "(stabilized to at least 10%) " ++ label
in forAll (frequency [(1, return True), (9, return False)]) $ \ basechance ->
cover (basechance || pred) (10 + (percent * 9 `div` 10)) newlabel prop
-- | Return the python binary to use. If the PYTHON environment
-- variable is defined, use its value, otherwise use just \"python\".
pythonCmd :: IO String
......
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