Skip to content

Commit

Permalink
Provide some additional introduction to help users avoid a common
Browse files Browse the repository at this point in the history
pitfall
  • Loading branch information
MaximilianAlgehed committed Mar 21, 2024
1 parent 3479a1a commit 4196882
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Test/QuickCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ To use QuickCheck on your own data types you will need to write 'Arbitrary'
instances for those types. See the
<http://www.cse.chalmers.se/~rjmh/QuickCheck/manual.html QuickCheck manual> for
details about how to do that.
When testing fails @quickCheck@ will try to give you a minimal counterexample to
your property:
@
import Test.QuickCheck
prop_reverse_bad :: [Int] -> Bool
prop_reverse_bad xs = reverse xs == xs
>>> quickCheck prop_reverse_bad
*** Failed! Falsified (after 3 tests and 3 shrinks):
[0,1]
@
However, beware because not all properties that ought to fail will fail when you expect
them to:
@
>>> quickCheck $ \ x y -> x == y
+++ Ok, passed 100 tests.
@
That's because GHCi will default any type variables in your property to '()', so in the example
above @quickCheck@ was really testing that '()' is equal to itself. To avoid this behaviour it
is best practise to monomorphise your polymorphic properties when testing:
@
>>> quickCheck $ \ x y -> (x :: Int) == y
*** Failed! Falsified (after 4 tests and 3 shrinks):
0
1
@
-}
{-# LANGUAGE CPP #-}
#ifndef NO_SAFE_HASKELL
Expand Down

0 comments on commit 4196882

Please sign in to comment.