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" ?