module Test.QuickCheck.Property.Monad
( PropM()
, assert
, failWith
, generate
, logMessage
, logMessageLn
) where
import Control.Applicative
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.Trans.Either
import Control.Monad.Trans.Writer
import Test.QuickCheck.Gen
import Test.QuickCheck.Property
newtype PropM a = PropM (EitherT String (WriterT String Gen) a) deriving (Functor, Applicative, Alternative, Monad, MonadPlus)
instance Testable a => Testable (PropM a) where
property (PropM m) = property $ do
(r,w) <- runWriterT $ runEitherT m
case r of
Right r' -> return $ property r'
Left err -> return $ printTestCase (w ++ "\n" ++ err) $ property False
assert :: String -> Bool -> PropM ()
assert err cond = unless cond $ failWith $ "Assertion failed: " ++ err
failWith :: String -> PropM ()
failWith err = PropM $ left err
generate :: Gen a -> PropM a
generate = PropM . lift . lift
logMessage :: String -> PropM ()
logMessage = PropM . lift . tell
logMessageLn :: String -> PropM ()
logMessageLn = logMessage . (++ "\n")