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?
您可以使用whenFail
在失败时打印有问题的字符串(或将其转储到文件中)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.