Automatically collect all quickChecks

Being a fan of quickCheck, I have a lot

prop_something_something = ... 

in my entire program.

For convenience, to easily run all of them, I define

 runchecks = do quickCheck prop_something_something quickCheck prop_something_different 

but is there a good way to generate runchecks ?

TL DR: I want to easily run all quickChecks in a file. I suppose one way is to prefix running tests with test_ or something similar, but that might be too hacky.

+8
haskell quickcheck
source share
2 answers

You can do this with test-framework-th . Just do:

 import Test.Framework.TH import Test.Framework.Providers.QuickCheck2 runchecks = $(defaultMainGenerator) 

This will use the test-framework method to run the tests, i.e. you’ll get a little more information than what you get by simply running the tests one by one, which is often good.

You will obviously need a TemplateHaskell for this; either add Default-extensions: TemplateHaskell to your Cabal file, or add {-# LANGUAGE TemplateHaskell #-} to the top of the file.

+7
source share

Additional note: this functionality also exists in QuickCheck 2, see the quickCheckAll function, which requires the import of Test.QuickCheck.All , as well as TemplateHaskell . quickCheckAll will check all the functions in your module whose name begins with prop_ .

+8
source share

All Articles