Safe Haskell | None |
---|---|
Language | Haskell98 |
This module includes almost everything you need to get started writing property tests with Hedgehog.
It is designed to be used alongside Hedgehog.Gen and Hedgehog.Range, which should be imported qualified. You also need to enable Template Haskell so the Hedgehog test runner can find your properties.
{-# LANGUAGE TemplateHaskell #-} import Hedgehog import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range
Once you have your imports set up, you can write a simple property:
prop_reverse :: Property prop_reverse = property $ do xs <- forAll $ Gen.list (Range.linear 0 100) Gen.alpha reverse (reverse xs) === xs
And add the Template Haskell splice which will run your properies:
tests :: IO Bool tests = $$(checkConcurrent)
You can then load the module in GHCi, and run it:
>>>
tests
━━━ Test.Example ━━━ ✓ prop_reverse passed 100 tests.
- data Property
- data Test m a
- data TestLimit
- data DiscardLimit
- data ShrinkLimit
- data Gen m a
- data Range a
- newtype Size = Size {}
- data Seed = Seed {}
- property :: Test IO () -> Property
- withTests :: TestLimit -> Property -> Property
- withDiscards :: DiscardLimit -> Property -> Property
- withShrinks :: ShrinkLimit -> Property -> Property
- check :: MonadIO m => Property -> m Bool
- checkSequential :: TExpQ (IO Bool)
- checkConcurrent :: TExpQ (IO Bool)
- recheck :: MonadIO m => Size -> Seed -> Property -> m ()
- forAll :: (Monad m, Show a, Typeable a, HasCallStack) => Gen m a -> Test m a
- info :: Monad m => String -> Test m ()
- success :: Monad m => Test m ()
- discard :: Monad m => Test m a
- failure :: (Monad m, HasCallStack) => Test m a
- assert :: (Monad m, HasCallStack) => Bool -> Test m ()
- (===) :: (Monad m, Eq a, Show a, HasCallStack) => a -> a -> Test m ()
- liftEither :: (Monad m, Show x, HasCallStack) => Either x a -> Test m a
- liftExceptT :: (Monad m, Show x, HasCallStack) => ExceptT x m a -> Test m a
- withResourceT :: MonadResourceBase m => Test (ResourceT m) a -> Test m a
- tripping :: HasCallStack => Applicative f => Monad m => Show (f a) => Eq (f a) => a -> (a -> b) -> (b -> f a) -> Test m ()
Documentation
A property test to check, along with some configurable limits like how many times to run the test.
A property test.
MonadTrans Test Source # | |
MFunctor Test Source # | |
MonadBase b m => MonadBase b (Test m) Source # | |
MonadError e m => MonadError e (Test m) Source # | |
MonadReader r m => MonadReader r (Test m) Source # | |
MonadState s m => MonadState s (Test m) Source # | |
Monad m => Monad (Test m) Source # | |
Functor m => Functor (Test m) Source # | |
Monad m => Applicative (Test m) Source # | |
MonadIO m => MonadIO (Test m) Source # | |
Monad m => Alternative (Test m) Source # | |
Monad m => MonadPlus (Test m) Source # | |
MonadThrow m => MonadThrow (Test m) Source # | |
MonadCatch m => MonadCatch (Test m) Source # | |
PrimMonad m => PrimMonad (Test m) Source # | |
MonadResource m => MonadResource (Test m) Source # | |
type PrimState (Test m) Source # | |
The number of successful tests that need to be run before a property test is considered successful.
data DiscardLimit Source #
The number of discards to allow before giving up.
data ShrinkLimit Source #
The number of shrinks to try before giving up on shrinking.
Generator for random values of a
.
MonadTrans Gen Source # | |
MMonad Gen Source # | |
MFunctor Gen Source # | |
MonadBase b m => MonadBase b (Gen m) Source # | |
MonadError e m => MonadError e (Gen m) Source # | |
MonadReader r m => MonadReader r (Gen m) Source # | |
MonadState s m => MonadState s (Gen m) Source # | |
MonadWriter w m => MonadWriter w (Gen m) Source # | |
Monad m => Monad (Gen m) Source # | |
Functor m => Functor (Gen m) Source # | |
Monad m => Applicative (Gen m) Source # | |
MonadIO m => MonadIO (Gen m) Source # | |
Monad m => Alternative (Gen m) Source # | |
Monad m => MonadPlus (Gen m) Source # | |
MonadThrow m => MonadThrow (Gen m) Source # | |
MonadCatch m => MonadCatch (Gen m) Source # | |
PrimMonad m => PrimMonad (Gen m) Source # | |
MonadResource m => MonadResource (Gen m) Source # | |
type PrimState (Gen m) Source # | |
A range describes the bounds of a number to generate, which may or may not
be dependent on a Size
.
Tests are parameterized by the size of the randomly-generated data, the meaning of which depends on the particular generator used.
A splittable random number generator.
Property
withTests :: TestLimit -> Property -> Property Source #
Set the number times a property should be executed before it is considered successful.
withDiscards :: DiscardLimit -> Property -> Property Source #
Set the number times a property is allowed to discard before the test runner gives up.
withShrinks :: ShrinkLimit -> Property -> Property Source #
Set the number times a property is allowed to shrink before the test runner gives up and prints the counterexample.
checkSequential :: TExpQ (IO Bool) Source #
Check all the properties in a file sequentially.
tests :: IO Bool tests = $$(checkSequential)
checkConcurrent :: TExpQ (IO Bool) Source #
Check all the properties in a file concurrently.
tests :: IO Bool tests = $$(checkConcurrent)
recheck :: MonadIO m => Size -> Seed -> Property -> m () Source #
Check a property using a specific size and seed.
Test
forAll :: (Monad m, Show a, Typeable a, HasCallStack) => Gen m a -> Test m a Source #
Generates a random input for the test by running the provided generator.
info :: Monad m => String -> Test m () Source #
Logs an information message to be displayed if the test fails.
assert :: (Monad m, HasCallStack) => Bool -> Test m () Source #
Fails the test if the condition provided is False
.
(===) :: (Monad m, Eq a, Show a, HasCallStack) => a -> a -> Test m () infix 4 Source #
Fails the test if the two arguments provided are not equal.
liftEither :: (Monad m, Show x, HasCallStack) => Either x a -> Test m a Source #
liftExceptT :: (Monad m, Show x, HasCallStack) => ExceptT x m a -> Test m a Source #
withResourceT :: MonadResourceBase m => Test (ResourceT m) a -> Test m a Source #
tripping :: HasCallStack => Applicative f => Monad m => Show (f a) => Eq (f a) => a -> (a -> b) -> (b -> f a) -> Test m () Source #
Test that a pair of render / parse functions are compatible.