FuzzCheck interface

There are just three special details introduced by FuzzCheck, the ?>
operator, and the arg, rand and gen combinators.

"label" ?> action

This runs a Fuzz action. If an exception occurs, the label is printed
along with the exception.

let x = "Hello"
"label" ?> f <$> arg x

This executes a monadic function f, passing it the argument x. This is
equivalent to using f x in the surrounding monad, except that if an
exception is generated, the error report looks like this:

f "Hello": <text of actual exception here>

You may also use rand, which is just a shorter synonym for QuickCheck’s
arbitrary, for generating a type-appropriate random value automatically:

"label" ?> f <$> rand

Another option is to use gen, which takes for its argument any combinator
from QuickCheck that generates an appropriately typed Gen value. For
example:

"label" ?> f <$> gen (choose (1,10))

This tests f by passing it a randomly chosen integer from the given range.
If an exception occurs, the actual integer that caused the problem is shown:

f 9: <text of actual exception here>

That’s it. To run the test, call fuzzCheck on the property:

>>> fuzzCheck prop_bs_ffi2
+++ OK, passed 100 tests.

You can use fuzzCheck' if you want to change the number of tests executed,
or if you want to associate cleanup code with the test after it runs, whether
or not it succeeds.

Simplifying tests

The role of ?> is to assign a label to each operation (to assist with error
reporting in case of failure), and to execute the Fuzz action in its
enclosing Monad. A fuzz test may occur within any monad supporting MonadIO
and MonadBaseControl IO (for the purpose of catching exceptions), which
means that if we’re testing code in IO, we can limit the use of ?> to only
those cases we expect might fail:

NOTE: Using gen does not mean that that specific function is invoked 100
times at that point in the monadic block. Instead, the entire block passed to
fuzzCheck is executed 100 times, with each occurence of gen producing a
new value at each run.

Integration with Hspec and HUnit

This all integrates quite nicely with Hspec and Hunit. For example, this is
from the smoke tests for this library: