quickCheckAll always return "True"
Asked Answered
L

2

8

I'm trying to use QuickCheck following another answer. I test like this:

{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import Test.QuickCheck.All


last' :: [a] -> a
last' [x] = x
last' (_:xs) = last' xs

prop_test x = last' x == last x

check = do
        putStrLn "quickCheck"
        quickCheck (prop_test :: [Char]-> Bool)

check2 = do
        putStrLn "quickCheckAll"
        $quickCheckAll

Then I load it in winGHCI and call check and check2. I get

quickCheck
*** Failed! (after 1 test): 
Exception:
  list.hs:(7,1)-(8,23): Non-exhaustive patterns in function last'
""

which I think it's reasonable. However, I get this from check2

quickCheckAll
True

I'm confused because no matter how I change the last' function, even wrong, quickCheckAll always return True.

What's wrong with my code? How can I fix this?

Languorous answered 6/2, 2015 at 4:25 Comment(1)
For what it's worth, when I try, I get a warning, too: "Name prop_test found in source file but was not in scope" (with a line number pointing at the call to quickCheckAll). Very mysterious.Seraphic
W
12

From the Test.QuickCheck.All docs:

To use quickCheckAll, add a definition to your module along the lines of

return []
runTests = $quickCheckAll

and then execute runTests.

Note: the bizarre return [] in the example above is needed on GHC 7.8; without it, quickCheckAll will not be able to find any of the properties.

Adding return [] before your check makes it work for me.

Warram answered 6/2, 2015 at 5:2 Comment(0)
P
1

To use quickCheckAll, you need a function which reads:

return [] runTests = $quickCheckAll

The other comment mentions this, but doesn't point out that it will still always return true unless the function is located below all of your quickCheck functions!

Pietje answered 15/1, 2017 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.