简体   繁体   中英

How to configure QuickCheck with cabal?

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?

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM