Home > Net >  How to configure QuickCheck with cabal?
How to configure QuickCheck with cabal?

Time:05-30

I'm learning to build a Haskell package. One thing I'm stuck with is running tests with QuickCheck.

Specifically, how can I configure the number of trials to run?

Here is my test file (Test.hs) with a dummy test:

module Main where

import System.Exit (exitFailure)
import Test.QuickCheck

prop_PermInvariant xs = length xs == length (reverse xs)
  where types = xs :: [Int]

main :: IO ()
main = quickCheck prop_PermInvariant

And here is my .cabal file:

Test-Suite tests
  type: exitcode-stdio-1.0
  main-is: Test.hs
  default-language: Haskell2010
  build-depends:
    base ^>= 4.14.3.0,
    QuickCheck > 2.14,
  hs-source-dirs: tests

After building the package, I can do cabal test, which will run 100 trials on my dummy test. But how to change that to run 10000?

CodePudding user response:

The documentation for quickCheck says "To run more tests, use withMaxSuccess." In your case specifically, you'd change main = quickCheck prop_PermInvariant to main = quickCheck (withMaxSuccess 10000 prop_PermInvariant). There's no reason to configure anything in Cabal at all.

  • Related