I would like to print the property being tested alongside the argument that caused failure. So, I am trying to solve the second part of the problem by using Debug.Dump from the dump package. This is a minimal working example:
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Debug.Dump
import Test.QuickCheck
import System.Exit
prop_ReverseLengthFail :: [Int] -> Property
prop_ReverseLengthFail xs =
counterexample [d|xs|] (length (reverse xs) === length xs + 1)
return []
main :: IO ()
main = do
passed <- $quickCheckAll
exitWith $ if passed
then ExitSuccess
else ExitFailure
However, I get the following error:
tempCodeRunnerFile.haskell:12:18: error:
• Couldn't match type ‘[template-haskell-2.19.0.0:Language.Haskell.TH.Syntax.Dec]’
with ‘Char’
Expected: String
Actual: [template-haskell-2.19.0.0:Language.Haskell.TH.Lib.Internal.Decs]
• In the first argument of ‘counterexample’, namely
‘[d| |]
pending(rn) [<splice, xs>]’
In the expression:
counterexample
[d| |]
pending(rn) [<splice, xs>]
(length (reverse xs) === length xs + 1)
In an equation for ‘prop_ReverseLengthFail’:
prop_ReverseLengthFail xs
= counterexample
[d| |]
pending(rn) [<splice, xs>]
(length (reverse xs) === length xs + 1)
|
12 | counterexample [d|xs|] (length (reverse xs) === length xs + 1)
I have two questions:
- How can I solve the error and accomplish my second goal (printing the expression) ?
- How can I print the expression being evaluated, i.e, "length (reverse xs) == length xs + 1" ?
A few problems:
Debug.Dumpgives you a quasi-quoter, which needs theQuasiQuotesextension to be used. That extension is not implied byTemplateHaskell, so you need to specify it too.dis the name of Template Haskell's declaration quoter, so you can't use that name as a quasi-quoter in a file where you also need to use Template Haskell (which you do with$quickCheckAll). Use either its full namedumpor its other shorthandddinstead.ExitFailureneeds anIntas an argument, which you didn't supply. (This wasn't causing the error in your question, but you'd get an error about it once the two things above were fixed.)Here's your program with all of those things fixed:
And here's the output when you run the fixed version: