How to improve debugging of QuickCheck and Parsec?

I use Haskell and Parsec to parse the file format. My parsing function looks something like this:

parseInput :: String -> Model parseInput input = ... data Model = Model { mNumV :: Int, mNumF :: Int, ... } 

To test this, I use QuickCheck. I defined an Arbitrary instance that generates a String representing the contents of the formatted file:

 instance Arbitrary File where arbitrary = ... data File = File { fContents :: String, fNumV :: Int, fNumF :: Int, ... } 

One of my properties can check if mNumV == fNumV after parsing an arbitrary String . It works well - when it works.

But if something does not work, Parsec throws an error similar to:

 *** Failed (after 1 test): Exception: (line 302, column 3): unexpected "\n" expecting space 

This is useful - however, after the test finishes, the contents of the arbitrary file disappear. I can’t login and link 302.

The only alternative I see is to print fContents each arbitrary file after each test, but that seems like a terrible idea. The same goes for routing each arbitrary file to a file on disk for later reference.

Is there a general way?

+7
haskell parsec quickcheck
source share
1 answer

You can use whenFail to print a corrupt line (or dump to a file) after a crash.

+1
source share

All Articles