Truth be told, the functionality is in the two orphan instances of
Example for PropertyT. You can directly use code in the PropertyTIO type. However, because most Hedgehog functions are abstract in
MonadTest, you might get errors about ambiguous types. The hedgehog
function fixes the type to PropertyTIO(), which works out just
fine.
You can use all of hspec's hooks with this, of course.
spec :: Spec
spec = before (pure "Hello!") $ do
describe "with a string" $ do
it "gets a string" $ \ str ->
hedgehog$ do
wrongLen <- forAll $ Gen.integral (Range.linear 0 3)
length str /== wrongLen
The function before will make all the following spec items a function,
accepting that as a parameter. You should call hedgehog after the
lambda.
This function is only used to fix the type of the PropertyT monad
transformer. The functions in Hedgehog are typically abstract in
a MonadTest, and it's easy to get ambiguous type errors if you leave
this out.
Hspec re-exports
4 declarations
modifyMaxSize isn't re-exported, since
hedgehog has nothing that corresponds to it.
m~IO => Example (PropertyTm ())Defined in hspec-hedgehog-0.3.0.0 · Test.Hspec.Hedgehog · orphan
Warning: Orphan instance! This instance is used to embed a Hedgehog
property seamlessly into the hspec framework. See the other instance
of Example for a function for more details.
m~IO => Example (a -> PropertyTm ())Defined in hspec-hedgehog-0.3.0.0 · Test.Hspec.Hedgehog · orphan
Warning: orphan instance! This instance is used to embed a Hedgehog
property seamlessly into the hspec framework.
The instance will pick things up from the Test.Hspec.QuickCheck
configuration. For example, if the program is supposed to use
a predetermined seed, then the same seed will be used for QuickCheck and
Hedgehog tests.
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
Instances8Enum, Eq, Integral, Num, Ord, Real, …
EnumShrinkRetriesDefined in hedgehog-1.7 · Hedgehog.Internal.Property
EqShrinkRetriesDefined in hedgehog-1.7 · Hedgehog.Internal.Property
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.
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.
Set the number of times a property will be executed for each shrink before
the test runner gives up and tries a different shrink. See ShrinkRetries
for more information.
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.
A range describes the bounds of a number to generate, which may or may not
be dependent on a Size.
The constructor takes an origin between the lower and upper bound, and a
function from Size to bounds. As the size goes towards 0, the values
go towards the origin.
Instances1Functor
FunctorRangeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
Tests are parameterized by the size of the randomly-generated data. The
meaning of a Size value depends on the particular generator used, but
it must always be a number between 0 and 99 inclusive.
Warning: although this check function runs tests faster thancheckSequential, it should be noted that it may cause problems withproperties that are not self-contained. For example, if you have a groupof tests which all use the same database table, you may find that theyinterfere with each other when being run in parallel.
A pre-condition for a command that must be verified before the command
can be executed. This is mainly used during shrinking to ensure that it
is still OK to run a command despite the fact that some previously
executed commands may have been removed from the sequence.
Update (forall (v :: Type -> Type). Ord1v => statev -> inputv -> Varoutputv -> statev)
Updates the model state, given the input and output of the command. Note
that this function is polymorphic in the type of values. This is because
it must work over Symbolic values when we are generating actions, and
Concrete values when we are executing them.
The specification for the expected behaviour of an
Action. These are used to generate sequences of actions to test.
This is the main type you will use when writing state machine
tests. gen is usually an instance of MonadGen, and m is usually
an instance of MonadTest. These constraints appear when you pass
your Command list to sequential or parallel.
Concrete values: At test-execution time, Symbolic values from generation
are replaced with Concrete values from performing actions. This type
gives us something of the same kind as Symbolic to pass as a type
argument to Var.
Symbolic values: Because hedgehog generates actions in a separate phase
before execution, you will sometimes need to refer to the result of a
previous action in a generator without knowing the value of the result
(e.g., to get the ID of a previously-created user).
Symbolic variables provide a token to stand in for the actual variables at
generation time (and in Require/Update callbacks). At execution time,
real values are available, so your execute actions work on Concrete
variables.
Variables are the potential or actual result of executing an action. They
are parameterised by either Symbolic or Concrete depending on the
phase of the test.
Symbolic variables are the potential results of actions. These are used
when generating the sequence of actions to execute. They allow actions
which occur later in the sequence to make use of the result of an action
which came earlier in the sequence.
Concrete variables are the actual results of actions. These are used
during test execution. They provide access to the actual runtime value of
a variable.
The state update Callback for a command needs to be polymorphic in the
type of variable because it is used in both the generation and the
execution phase.
Executes the prefix actions sequentially, then executes the two branches
in parallel, verifying that no exceptions are thrown and that there is at
least one sequential interleaving where all the post-conditions are met.
To generate parallel actions to execute, see the parallel
combinator in the Hedgehog.Gen module.
Test that a pair of encode / decode functions are compatible.
Given a printer from some type a -> b, and a parser with a
potential failure case b -> f a. Ensure that a valid a round
trips through the "print" and "parse" to yield the same a.
For example, types should have tripping Read and Show
instances:
trippingShowRead :: (Show a, Read a, Eq a, MonadTest m) => a -> m ()
trippingShowRead a = tripping a show readEither
Lifting of the Eq class to unary type constructors.
Any instance should be subject to the following law that canonicity
is preserved:
liftEq (==) = (==)
This class therefore represents the generalization of Eq by
decomposing its main method into a canonical lifting on a canonical
inner method, so that the lifting can be reused for other arguments
than the canonical one.
Instances67Lifting2, Lifting, Eq1, …
Eq1ComplexDefined in base-4.20.2.0 · Data.Functor.Classes
This class therefore represents the generalization of Ord by
decomposing its main method into a canonical lifting on a canonical
inner method, so that the lifting can be reused for other arguments
than the canonical one.
Instances65Lifting2, Lifting, Ord1, …
Ord1IntMapDefined in containers-0.7 · Data.IntMap.Internal
Ord1SeqDefined in containers-0.7 · Data.Sequence.Internal
Ord1SetDefined in containers-0.7 · Data.Set.Internal
This class therefore represents the generalization of Show by
decomposing it's methods into a canonical lifting on a canonical
inner method, so that the lifting can be reused for other arguments
than the canonical one.
Instances69Lifting2, Lifting, Show1, …
Show1ComplexDefined in base-4.20.2.0 · Data.Functor.Classes
Warning: Orphan instance! This instance is used to embed a Hedgehog
property seamlessly into the hspec framework. See the other instance
of Example for a function for more details.
Warning: orphan instance! This instance is used to embed a Hedgehog
property seamlessly into the hspec framework.
The instance will pick things up from the Test.Hspec.QuickCheck
configuration. For example, if the program is supposed to use
a predetermined seed, then the same seed will be used for QuickCheck and
Hedgehog tests.