Getting a list of object names in a module with a haskell template?

I would like to be able to take a file with ads, for example:

test_1 = assert $ 1 == 1 test_2 = assert $ 2 == 1 

and generate a basic launch function like

 main = runTests [test_1, test2] 

The goal is to get something like Netsetest Python.

Can I do this with a Haskell template? I can not find a lot of documentation on it (there are a lot of broken links in the Wiki).

+6
haskell
source share
2 answers

You might want to look into the test-framework package family. In particular, the test-framework-th package provides the Template Haskell function defaultMainGenerator , which does exactly what you want for the QuickCheck and HUnit tests, for how long in accordance with the convention on the HUnit test case prefixes with the case_ and QuickCheck parameters with prop_ .

 {-# LANGUAGE TemplateHaskell #-} import Test.Framework.Providers.HUnit import Test.Framework.Providers.QuickCheck2 import Test.Framework.TH import Test.HUnit import Test.QuickCheck main = $(defaultMainGenerator) case_checkThatHUnitWorks = assert $ 1 == 1 prop_checkThatQuickCheckWorks = (1 == 1) 
+4
source share

There is another way, you do not need to use the haskell template. haskell-src-exts can analyze Haskell, and you can learn from it.

Or, if your goal is practical, you can do it as quickcheck and make a simple approach, that is, look for identifiers starting with prop_ in column 0. This is a quite adequate solution for real work, although it can be theoretically unsatisfactory.

+4
source share

All Articles