0

I want to use test-framework-th for generating test groups.

I have this main test module:

module Main where

import           Test.Framework.TH

import           Foo.Test

main = $(defaultMainGenerator)

And this module containing the test:

module Foo.Test where

import           Test.HUnit

case_1 = do 1 @=? 2

However, defaultMainGenerator does not detect the test in the Foo.Test module. It only detects tests in the module in which it is called (in this case Main).

How can I split my tests across modules without duplicating boilerplate for every test?

1 Answer 1

0

Use testGroupGenerator in each module to generate a test group for that module, then use those from main, e.g.

Foo.hs:

module Foo where
import Test.Framework.TH
tests = $(testGroupGenerator)
...

Bar.hs:

module Bar where
import Test.Framework.TH
tests = $(testGroupGenerator)
...

Main.hs:

import Test.Framework

import Foo
import Bar

main = defaultMain [Foo.tests, Bar.tests]
Sign up to request clarification or add additional context in comments.

1 Comment

Seems like the only option. :[ I think I'll just use a custom preprocessor to generate main then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.