[Haskell-cafe] Using Template Haskell to automate QuickCheck testing?

Brent Yorgey byorgey at gmail.com
Wed Jun 20 21:38:02 EDT 2007


(I originally tried to send this on Jun 8, but it seems that due to various
issues it did not actually get sent over the list.  Apologies if anyone gets
multiple copies.)

Hi all,

Following some recent discussions in #haskell, I've decided to try my
hand at a module to allow automation of QuickCheck testing.  I'm
aware that there are already various "homegrown" solutions out there,
(e.g. [1],[2]) as well as idiomatic boilerplate to do this (e.g. [3]),
but it feels like there ought to be a more elegant/DRY-style solution.

In my ideal vision, you'd be able to do something like this:

import ModuleToBeTested
import Test.AutoQuickCheck   -- the library module I want to write

prop_foo = blah                       -- some QuickCheck tests
prop_bar = blah blah

main = $(runChecks)

...where runChecks would use TH to reflect on the current module, find
any top-level function declarations beginning with "prop_", and
generate code to run them all through QuickCheck, printing the
results.  I think the attractions of such a system (if it could
actually work) should be obvious.

However, after reading all about TH it doesn't seem like there's a way
to do this (reflecting on the current module to pull out the names of
certain top-level declarations).  Since I don't know much about how TH
is implemented, I'm not sure whether (1) there's a good reason this is
pretty much impossible with TH; (2) it would be possible but it's
currently unimplemented; or (3) there actually is a way to do what I
want, but I'm not clever enough in the ways of TH to figure it out.
(Or (4) none of the above?)

Any thoughts or advice would be greatly appreciated!

thanks,
-Brent

[1] http://www.cs.chalmers.se/~rjmh/QuickCheck/quickcheck<http://www.cs.chalmers.se/%7Erjmh/QuickCheck/quickcheck>
[2] http://blog.codersbase.com/2006/09/01/simple-unit-testing-in-haskell/
[3] http://www.haskell.org/haskell
wiki/How_to_write_a_Haskell_program#Add_some_automated_testing:_QuickCheck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070620/eaa67431/attachment-0001.htm


More information about the Haskell-Cafe mailing list