Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically gather all quickChecks

Being a fan of quickCheck, I have a lot of

prop_something_something = ...

throughout my 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 nice way to generate runchecks?

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

like image 838
Christian Neverdal Avatar asked Apr 26 '12 18:04

Christian Neverdal


2 Answers

An extra note: this functionality exists out of the box in QuickCheck 2 as well, see the function quickCheckAll, which requires an import of Test.QuickCheck.All as well as TemplateHaskell. quickCheckAll will test all functions in your module whose name starts with prop_.

like image 80
danr Avatar answered Nov 03 '22 21:11

danr


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

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

This will use the test-framework way of running tests, i.e. you'll get slightly more information than what you'd get by simply running the tests one after the other, which oftentimes is a good thing.

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

like image 25
dflemstr Avatar answered Nov 03 '22 21:11

dflemstr