Skip to content

Coverage of template-haskell generated values

When testing a library, the things template Haskell are generated are not part of the coverage.

Indeed, imagine you have a simple template Haskell function:

getId :: Q Exp
getId = pure (ConE 'id)

then one could write a file:

f = $(getId)

and test the f with:

f 1 `shouldBe 1`

Now the test includes the generation of f, but getId does not occur in the covered functions. Likely because it runs at "compile time", not runtime.

I think it would make sense that the template Haskell that runs at compile time and produces products tested perhaps are included in the coverage report.

Any thoughts?

Edited by Willem Van Onsem