From 1ab330780ebd4ee128cab6ed4f81b38653c1c458 Mon Sep 17 00:00:00 2001 From: Josef Svenningsson Date: Thu, 14 Nov 2024 05:13:50 -0800 Subject: [PATCH] More set tests Summary: I've added sets to the test predicate in our test DB. That in itself is a good test and found a couple of bugs. I've also added a test. Also added a round-tripping test to exercise the JSON encoding. Reviewed By: simonmar Differential Revision: D63611597 fbshipit-source-id: cdaf19383fdfc72f3290d51b8c6c5c88a95e48cb --- common/util/Util/Testing.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/util/Util/Testing.hs b/common/util/Util/Testing.hs index ff2f0b61..bb2cda41 100644 --- a/common/util/Util/Testing.hs +++ b/common/util/Util/Testing.hs @@ -9,6 +9,9 @@ {-# LANGUAGE NamedFieldPuns #-} module Util.Testing ( assertProperty + , assertPropertyWithArgs + , QC.stdArgs + , QC.Args(..) , skip , skipTest , skipTestIf @@ -44,12 +47,17 @@ skipTestIfRtsIsProfiled = skipTestIf $ const (rtsIsProfiled /= 0) assertProperty :: (HasCallStack, QC.Testable prop) => String -> prop -> Assertion -assertProperty msg prop = do - size <- maybe (QC.maxSize QC.stdArgs) read <$> lookupEnv "QUICKCHECK_SIZE" +assertProperty msg prop = + assertPropertyWithArgs msg QC.stdArgs prop + +assertPropertyWithArgs + :: (HasCallStack, QC.Testable prop) => String -> QC.Args -> prop -> Assertion +assertPropertyWithArgs msg qcArgs prop = do + size <- maybe (QC.maxSize qcArgs) read <$> lookupEnv "QUICKCHECK_SIZE" success <- - maybe (QC.maxSuccess QC.stdArgs )read <$> lookupEnv "QUICKCHECK_RUNS" + maybe (QC.maxSuccess qcArgs) read <$> lookupEnv "QUICKCHECK_RUNS" mbSeed <- lookupEnv "QUICKCHECK_SEED" - let args = QC.stdArgs { + let args = qcArgs { QC.maxSize = size, QC.maxSuccess = success, QC.replay = (,size) . read <$> mbSeed