falsify-0.4.0: Property-based testing with internal integrated shrinking
Safe HaskellNone
LanguageHaskell2010

Test.Falsify.Driver

Description

The main falsify driver

The main entrypoint into falsify is the falsify function, which attempts to falsify the Property' it is given. However, most users don't need to use this module directly; it is primarily intended for integration of falsify in test frameworks such as tasty. For the case of tasty specifically, see the tasty-falsify package.

Synopsis

Documentation

falsify :: Options -> Property' e a -> IO (TestOutcome' e a) Source #

Run a test: attempt to falsify the given property

Options

data Options Source #

Options for running a test

Constructors

Options 

Fields

Instances

Instances details
Default Options Source # 
Instance details

Defined in Test.Falsify.Internal.Driver

Methods

def :: Options #

data ReplaySeed Source #

Replay seed

By default, when we falsify a property we start with a PRNG initialized using a random seed (produced using the system entropy; this relies on initSMGen in splitmix). When a property fails, we will report the exact seed used, so that the user can re-run the exact same test again, if desired.

The definition of ReplaySeed is part of falsify's public API, to make it possible to use custom drivers.

Constructors

ReplaySeed 

Fields

data ExpectFailure Source #

Do we expect the property to fail?

If ExpectFailure, the test will fail if the property does not fail. Note that if we expect failure for a property, then we can stop at the first failed test; the number of tests to run for the property becomes a maximum rather than a goal.

data Verbose Source #

Verbose output

Note that if a test fails (and we were not expecting failure) we show the logs independent of verbosity.

Constructors

Verbose 
NotVerbose 

parseReplaySeed :: String -> Either String ReplaySeed Source #

Parse ReplaySeed

Returns Left an error message if parsing failed.

Results

type TestOutcome = TestOutcome' String Source #

TestOutcome specialized to String for errors

This mimicks the Property' vs Property distinction.

data TestOutcome' e a Source #

Result of running falsify

This is an opaque type; see renderTestOutcome and the additional accessors provided in Test.Falsify.Driver.

data RenderedTestOutcome Source #

Test outcome as it should be shown to the user

The rendered test outcome can usually be used directly in test framework integration. For example, the tasty integration uses

toTastyResult :: RenderedTestOutcome -> Tasty.Result
toTastyResult RenderedTestOutcome{testPassed, testOutput}
  | testPassed = Tasty.testPassed testOutput
  | otherwise  = Tasty.testFailed testOutput

Additional accessors

successes :: TestOutcome' e a -> [(ReplaySeed, a)] Source #

Successful test outcomes

NOTE: Normally the a parameter for a top-level property is instantiated to unit (()), in which case it's really only the length of the list of successes that is relevant.

discarded :: TestOutcome' e a -> Word Source #

Number of discarded test

failure :: TestOutcome' e a -> Maybe (ReplaySeed, e) Source #

Failing test, if any

Returns the error after shrinking

failure' :: TestOutcome' e a -> Maybe (ReplaySeed, NonEmpty e) Source #

Generalization of failure that returns the full shrinking history