I have a small/medium sized Haskell codebase for which I'd like to generate a coverage report. By default the coverage report that HPC provides is filled with false negatives (e.g. I use lenses to access most of my record fields, rather than the auto generated ones, which HPC then reports as not covered).
The typical solution to this is to generate some overlay as specified here: https://wiki.haskell.org/Haskell_program_coverage#Hpc_toolkit
When I try to do this with Stack I run into an issue.
$ stack new --resolver=lts-9.5 hpcTest
If we edit src/Lib.hs
to be:
module Lib
( someFunc, otherFunc
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"
otherFunc :: IO ()
otherFunc = putStrLn "otherFunc"
and test/spec.hs
to be:
import Lib
main :: IO ()
main = someFunc
and run stack test --coverage
We get a coverage report which is not 100% covered, so if we follow the instructions of the wiki page we get: stack exec hpc -- draft --hpcdir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/hpc/ --srcdir=. .stack-work/install/x86_64-linux/lts-9.5/8.0.2/hpc/hpcTest/hpcTest-test/hpcTest-test.tix > myDraft.txt
which when we run results in the following in myDraft.txt
:
module "hpcTest-0.1.0.0-HnYRxRg1qoiyMKwsCMtby:Lib" {
tick function "otherFunc" on line 9;
}
when we then do the next step and try to generate the overlay stack exec hpc -- overlay --hpcdir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/hpc/ --srcdir=. myDraft.txt
the process falls over and we get the following error:
hpc: can not find hpcTest-0.1.0.0-HnYRxRg1qoiyMKwsCMtby:Lib in ./.hpc, ./.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/hpc/
CallStack (from HasCallStack):
error, called at libraries/hpc/Trace/Hpc/Mix.hs:122:15 in hpc-0.6.0.3:Trace.Hpc.Mix
What am I doing wrong in this process and how can I get this to work?
Replace :
with /
. The draft code shall be
module "hpcTest-0.1.0.0-HnYRxRg1qoiyMKwsCMtby/Lib" {
tick function "otherFunc" on line 9;
}
I find that by looking into the tix file stack hpc
creates. (lol)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With