{-# LANGUAGE RankNTypes #-}
module Test.Lawful.QuickCheck
(
testLaws,
testLawsWith,
toProperty,
)
where
import Test.Lawful.Types (Law, Laws)
import Test.QuickCheck (Property, discard)
import Test.QuickCheck.Monadic (PropertyM, assert, monadicIO)
import Test.Tasty (TestName, TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
toProperty :: (forall a. m a -> PropertyM IO a) -> Law m -> Property
toProperty :: forall (m :: * -> *).
(forall a. m a -> PropertyM IO a) -> Law m -> Property
toProperty forall a. m a -> PropertyM IO a
run Law m
law = forall a. Testable a => PropertyM IO a -> Property
monadicIO forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a
discard forall (m :: * -> *). Monad m => Bool -> PropertyM m ()
assert forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. m a -> PropertyM IO a
run Law m
law
testLaws :: TestName -> (forall a. m a -> PropertyM IO a) -> Laws m -> TestTree
testLaws :: forall (m :: * -> *).
TestName -> (forall a. m a -> PropertyM IO a) -> Laws m -> TestTree
testLaws = forall (m :: * -> *).
(Property -> Property)
-> TestName
-> (forall a. m a -> PropertyM IO a)
-> Laws m
-> TestTree
testLawsWith forall a. a -> a
id
testLawsWith :: (Property -> Property) -> TestName -> (forall a. m a -> PropertyM IO a) -> Laws m -> TestTree
testLawsWith :: forall (m :: * -> *).
(Property -> Property)
-> TestName
-> (forall a. m a -> PropertyM IO a)
-> Laws m
-> TestTree
testLawsWith Property -> Property
fn TestName
name forall a. m a -> PropertyM IO a
run Laws m
laws = TestName -> [TestTree] -> TestTree
testGroup TestName
name [forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
n (Property -> Property
fn forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
(forall a. m a -> PropertyM IO a) -> Law m -> Property
toProperty forall a. m a -> PropertyM IO a
run Law m
l) | (TestName
n, Law m
l) <- Laws m
laws]