Using Template Haskell to automate QuickCheck testing?

(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/quickcheckhttp://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

Hello Brent, Thursday, June 21, 2007, 5:38:02 AM, you wrote:
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).
i don't know whether it's implemented, but standard workaround is to put entire module body (or at least prop_*) in quotation brackets and explore returned result, like this: $(optimize [d| fib = .... |]) just for case you don't know about this - i've written TH tutorial and doc: http://www.haskell.org/bz/th3.htm http://www.haskell.org/bz/thdoc.htm -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

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).
I don't know template haskell very well yet. To do introspection there is the function reify which returns the type info of a given name. But as far as I've seen it doesn't support whole modules. (Have a look at Haskell.TH.Syntax (type Info) So perhaps you would have to extend ghc th functionality. Marc Weber
participants (3)
-
Brent Yorgey
-
Bulat Ziganshin
-
Marc Weber