MasterMastic
MasterMastic

Reputation: 21286

How to exclude derivation of Show from HPC's code-coverage?

I have type that derives Show.
It's useful for development & required for testing, but not necessary for my application's logic, so it does not require any testing.

I want to make HPC aware of that to get 100% coverage for my tests. Is there any way to exclude it?
A setting? a pragma? a test to trick it?

I tried seqing show but it didn't work at first (later it did and solved the issue, and I posted an answer, see it).

I also tried extending with CPP to use a macro condition that will exclude the Show just when testing, but quickCheckAll was not fond of that and I didn't even get through compilation (which is actually understandable in case of test-failure).

Upvotes: 3

Views: 278

Answers (1)

MasterMastic
MasterMastic

Reputation: 21286

I eventually seqed all Show has to offer so GHC will see that I've been there, and acknowledge I've covered it.
The following covers it on my type:

prop_fieldShow :: (Show i, Show a) => Field i a -> Bool
prop_fieldShow field = showList [field] `seq` showsPrec 0 field `seq` show field `seq` True

Upvotes: 2

Related Questions