1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
module UnitTests.Distribution.Solver.Modular.QuickCheck.Utils (
testPropertyWithSeed
) where
import Data.Tagged (Tagged, retag)
import System.Random (getStdRandom, random)
import Test.Tasty (TestTree)
import Test.Tasty.Options (OptionDescription, lookupOption, setOption)
import Test.Tasty.Providers (IsTest (..), singleTest)
import Test.Tasty.QuickCheck
( QC (..), QuickCheckReplay (..), Testable, property )
import Distribution.Simple.Utils
import Distribution.Verbosity
-- | Create a QuickCheck test that prints the seed before testing the property.
-- The seed can be useful for debugging non-terminating test cases. This is
-- related to https://github.com/feuerbach/tasty/issues/86.
testPropertyWithSeed :: Testable a => String -> a -> TestTree
testPropertyWithSeed name = singleTest name . QCWithSeed . QC . property
newtype QCWithSeed = QCWithSeed QC
instance IsTest QCWithSeed where
testOptions = retag (testOptions :: Tagged QC [OptionDescription])
run options (QCWithSeed test) progress = do
replay <- case lookupOption options of
QuickCheckReplay (Just override) -> return override
QuickCheckReplay Nothing -> getStdRandom random
notice normal $ "Using --quickcheck-replay=" ++ show replay
run (setOption (QuickCheckReplay (Just replay)) options) test progress
|