I am using Haskell and Parsec to parse a file format. My parsing function looks something like:
parseInput :: String -> Model
parseInput input = ...
data Model = Model { mNumV :: Int, mNumF :: Int, ... }
In order to test this, I am using QuickCheck. I have defined an Arbitrary
instance that generates a String
representing the contents of a formatted file:
instance Arbitrary File where
arbitrary = ...
data File = File { fContents :: String, fNumV :: Int, fNumF :: Int, ... }
One of my properties might check to determine if mNumV == fNumV
after parsing the arbitrary String
. This works well - when it works.
But if something fails, 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 fails the contents of the arbitrary file disappear. I can't go in and reference line 302.
The only alternative that I can see is to print the fContents
of each arbitrary file after each test - but that seems like a terrible idea. The same goes for routing every arbitrary file to a file on disk for later reference.
Is there a common way around this?
Either ParseError a
and you can get the sourcepos fromLeft err
– Teepee