When a value fails a QuickCheck'd test, I'd like to use it for debugging. Is there any way I can do something like:
let failValue = quickCheck' myTest
in someStuff failValue
If my data was read
able then I could probably hack some way to get it in from IO, but it's not.
I couldn't find anything in the QuickCheck API to do this in a nice way, but here's something I hacked together using the monadic QuickCheck API. It intercepts and logs the inputs to your property in an
IORef
, and assumes that if it failed, the last one was the culprit and returns it in aJust
. If the test passed, the result isNothing
. This can probably be refined a bit but for simple one-argument properties it should do the job.One way would be to use the sample' method, manually run the test and find the values in which it fails. For example, testing a faulty double function:
The only problem is
sample'
only generates 11 test values, that may not be enough to trigger the bug.