HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehedgehog-1.7Haskell2010

Hedgehog.Internal.Property

  • 30 types
  • 1 class
  • 62 values
  • Packagehedgehog-1.7
  • Exports93
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceProperty.hs

Property

30 declarations
newtypenewtype PropertyT (m :: Type -> Type) a
#

The property monad transformer allows both the generation of test inputs and the assertion of expectations.

Constructors

Instances23MonadTrans, MonadTransDistributive, MFunctor, MonadError, MonadReader, MonadState, …
newtypenewtype PropertyName
#

The name of a property.

Should be constructed using OverloadedStrings:

  "apples" :: PropertyName
Instances6Eq, Ord, Show, IsString, Semigroup, Lift
datadata PropertyConfig
#

Configuration for a property test.

Instances4Eq, Ord, Show, Lift
newtypenewtype TestLimit
#

The number of successful tests that need to be run before a property test is considered successful.

Can be constructed using numeric literals:

  200 :: TestLimit

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Real, …
  • Enum TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Eq TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Integral TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Num TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Ord TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Real TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Lift TestLimitDefined in hedgehog-1.7 · Hedgehog.Internal.Property
newtypenewtype TestCount
#

The number of tests a property ran successfully.

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Real, …
  • Enum TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Eq TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Integral TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Num TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Ord TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Real TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Lift TestCountDefined in hedgehog-1.7 · Hedgehog.Internal.Property
newtypenewtype DiscardLimit
#

The number of discards to allow before giving up.

Can be constructed using numeric literals:

  10000 :: DiscardLimit

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Real, …
newtypenewtype DiscardCount
#

The number of tests a property had to discard.

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Real, …
newtypenewtype ShrinkLimit
#

The number of shrinks to try before giving up on shrinking.

Can be constructed using numeric literals:

  1000 :: ShrinkLimit

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Real, …
newtypenewtype ShrinkCount
#

The numbers of times a property was able to shrink after a failing test.

Constructors

Instances7Enum, Eq, Integral, Num, Ord, Real, …
datadata Skip
#

Where to start running a property's tests.

Constructors

  • SkipNothing

    Don't skip anything.

  • SkipToTest TestCount DiscardCount

    Skip to a specific test number. If it fails, shrink as normal. If it passes, move on to the next test. Coverage checks are disabled.

    We also need to count discards, since failing "after 7 tests" points at a different generated value than failing "after 7 tests and 5 discards".

  • SkipToShrink TestCount DiscardCount ShrinkPath

    Skip to a specific test number and shrink state. If it fails, stop without shrinking further. If it passes, the property will pass without running any more tests.

    Due to implementation details, all intermediate shrink states - those on the direct path from the original test input to the target state - will be tested too, and their results discarded.

Instances5Eq, Ord, Show, IsString, Lift
  • Eq SkipDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Ord SkipDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show SkipDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • IsString SkipDefined in hedgehog-1.7 · Hedgehog.Internal.Property

    We use this instance to support usage like

      withSkip "3:aB"
    

    It throws an error if the input is not a valid compressed Skip.

  • Lift SkipDefined in hedgehog-1.7 · Hedgehog.Internal.Property
newtypenewtype ShrinkPath
#

The path taken to reach a shrink state.

Constructors

Instances4Eq, Ord, Show, Lift
  • Eq ShrinkPathDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Ord ShrinkPathDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show ShrinkPathDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Lift ShrinkPathDefined in hedgehog-1.7 · Hedgehog.Internal.Property
newtypenewtype ShrinkRetries
#

The number of times to re-run a test during shrinking. This is useful if you are testing something which fails non-deterministically and you want to increase the change of getting a good shrink.

If you are doing parallel state machine testing, you should probably set shrink retries to something like 10. This will mean that during shrinking, a parallel test case requires 10 successful runs before it is passes and we try a different shrink.

Can be constructed using numeric literals:

  0 :: ShrinkRetries

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Real, …

Set the number of times a property should be executed before it is considered successful.

If you have a test that does not involve any generators and thus does not need to run repeatedly, you can use withTests 1 to define a property that will only be checked once.

valuetest :: Monad m => TestT m a -> PropertyT m a
#

Lift a test in to a property.

Because both TestT and PropertyT have MonadTest instances, this function is not often required. It can however be useful for writing functions directly in TestT and thus gaining a MonadTransControl instance at the expense of not being able to generate additional inputs using forAll.

An example where this is useful is parallel state machine testing, as executeParallel requires MonadBaseControl IO in order to be able to spawn threads in MonadTest.

valueforAllWith
  1. :: (Monad m, HasCallStack)
  2. => a -> String
  3. -> Gen a
  4. -> PropertyT m a
#

Generates a random input for the test by running the provided generator.

This is a the same as forAll but allows the user to provide a custom rendering function. This is useful for values which don't have a Show instance.

valueforAllWithT
  1. :: (Monad m, HasCallStack)
  2. => a -> String
  3. -> GenT m a
  4. -> PropertyT m a
#

Generates a random input for the test by running the provided generator.

This is a the same as forAllT but allows the user to provide a custom rendering function. This is useful for values which don't have a Show instance.

valueskipCompress :: Skip -> String
#

Compress a Skip into a hopefully-short alphanumeric string.

The bit that might be long is the ShrinkPath in SkipToShrink. For that, we encode the path components in base 26, alternating between uppercase and lowercase alphabets to distinguish list elements. Additionally when we have runs of equal components, we use the normal base 10 encoding to indicate the length.

This gives something which is hopefully quite short, but a human can roughly interpret it by eyeball.

Compress a ShrinkPath into a hopefully-short alphanumeric string.

We encode the path components in base 26, alternating between uppercase and lowercase alphabets to distinguish list elements. Additionally when we have runs of equal components, we use the normal base 10 encoding to indicate the length.

Group

3 declarations
newtypenewtype GroupName
#

The name of a group of properties.

Should be constructed using OverloadedStrings:

  "fruit" :: GroupName
Instances6Eq, Ord, Show, IsString, Semigroup, Lift
newtypenewtype PropertyCount
#

The number of properties in a group.

Constructors

Instances7Enum, Eq, Integral, Num, Ord, Real, …

TestT

26 declarations
classclass Monad m => MonadTest (m :: Type -> Type) where
#

Methods

Instances14MonadTest, …
newtypenewtype TestT (m :: Type -> Type) a
#

A test monad transformer allows the assertion of expectations.

Instances23MonadTrans, MonadTransControl, MonadTransDistributive, MFunctor, MonadError, MonadReader, …
newtypenewtype Journal
#

A record containing the details of a test run.

Constructors

Instances4Eq, Show, Semigroup, Monoid
  • Eq JournalDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show JournalDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Semigroup JournalDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Monoid JournalDefined in hedgehog-1.7 · Hedgehog.Internal.Property
valuefootnote :: MonadTest m => String -> m ()
#

Logs a message to be displayed as additional information in the footer of the failure report.

valuefootnoteShow :: (MonadTest m, Show a) => a -> m ()
#

Logs a value to be displayed as additional information in the footer of the failure report.

valuediff
  1. :: (MonadTest m, Show a, Show b, HasCallStack)
  2. => a
  3. -> a -> b -> Bool
  4. -> b
  5. -> m ()
#

Fails the test and shows a git-like diff if the comparison operation evaluates to False when applied to its arguments.

The comparison function is the second argument, which may be counter-intuitive to Haskell programmers. However, it allows operators to be written infix for easy reading:

  diff y (<) 87
  diff x (<=) r

This function behaves like the unix diff tool, which gives a 0 exit code if the compared files are identical, or a 1 exit code code otherwise. Like unix diff, if the arguments fail the comparison, a /diff is shown.

valueeval :: (MonadTest m, HasCallStack) => a -> m a
#

Fails the test if the value throws an exception when evaluated to weak head normal form (WHNF).

valueevalM :: (MonadTest m, MonadCatch m, HasCallStack) => m a -> m a
#

Fails the test if the action throws an exception.

The benefit of using this over simply letting the exception bubble up is that the location of the closest evalM will be shown in the output.

valueevalIO :: (MonadTest m, MonadIO m, HasCallStack) => IO a -> m a
#

Fails the test if the IO action throws an exception.

The benefit of using this over liftIO is that the location of the exception will be shown in the output.

Coverage

16 declarations
newtypenewtype Coverage a
#

The extent to which all classifiers cover a test.

When a given classification's coverage does not exceed the required minimum, the test will be failed.

Instances7Functor, Foldable, Traversable, Eq, Show, Semigroup, …
datadata Label a
#

The extent to which a test is covered by a classifier.

When a classifier's coverage does not exceed the required minimum, the test will be failed.

Instances6Functor, Foldable, Traversable, Eq, Show, Semigroup
  • Functor LabelDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Foldable LabelDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Traversable LabelDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Eq a => Eq (Label a)Defined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show a => Show (Label a)Defined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Semigroup a => Semigroup (Label a)Defined in hedgehog-1.7 · Hedgehog.Internal.Property

    This semigroup is right biased. The name, location and percentage from the rightmost Label will be kept. This shouldn't be a problem since the library doesn't allow setting multiple classes with the same ClassifierName.

newtypenewtype LabelName
#

The name of a classifier.

Should be constructed using OverloadedStrings:

  "apples" :: LabelName
Instances6Eq, Ord, Show, IsString, Semigroup, Monoid

Require a certain percentage of the tests to be covered by the classifier.

   prop_with_coverage :: Property
   prop_with_coverage =
     property $ do
       match <- forAll Gen.bool
       cover 30 "True" $ match
       cover 30 "False" $ not match

The example above requires a minimum of 30% coverage for both classifiers. If these requirements are not met, it will fail the test.

valueclassify :: (MonadTest m, HasCallStack) => LabelName -> Bool -> m ()
#

Records the proportion of tests which satisfy a given condition.

   prop_with_classifier :: Property
   prop_with_classifier =
     property $ do
       xs <- forAll $ Gen.list (Range.linear 0 100) Gen.alpha
       for_ xs $ \x -> do
         classify "newborns" $ x == 0
         classify "children" $ x > 0 && x < 13
         classify "teens" $ x > 12 && x < 20
valuelabel :: (MonadTest m, HasCallStack) => LabelName -> m ()
#

Add a label for each test run. It produces a table showing the percentage of test runs that produced each label.

datadata Cover
#

Whether a test is covered by a classifier, and therefore belongs to a Class.

Instances5Eq, Ord, Show, Semigroup, Monoid
  • Eq CoverDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Ord CoverDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show CoverDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Semigroup CoverDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Monoid CoverDefined in hedgehog-1.7 · Hedgehog.Internal.Property
newtypenewtype CoverCount
#

The total number of tests which are covered by a classifier.

Can be constructed using numeric literals:

  30 :: CoverCount
Instances6Eq, Num, Ord, Show, Semigroup, Monoid
newtypenewtype CoverPercentage
#

The relative number of tests which are covered by a classifier.

Can be constructed using numeric literals:

  30 :: CoverPercentage
Instances5Eq, Fractional, Num, Ord, Show

Confidence

7 declarations
newtypenewtype Confidence
#

The acceptable occurrence of false positives

Example, Confidence 10^9 would mean that you'd accept a false positive for 1 in 10^9 tests.

Instances5Eq, Num, Ord, Show, Lift
  • Eq ConfidenceDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Num ConfidenceDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Ord ConfidenceDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Show ConfidenceDefined in hedgehog-1.7 · Hedgehog.Internal.Property
  • Lift ConfidenceDefined in hedgehog-1.7 · Hedgehog.Internal.Property

Internal

11 declarations

These functions are exported in case you need them in a pinch, but are not part of the public API and may change at any time, even as part of a minor update.

valuewriteLog :: MonadTest m => Log -> m ()
#

Log some information which might be relevant to a potential test failure.