7

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?

James
  • 121
  • 3
  • Were you able to solve it? I'm facing similar issue and unable to solve it. – ecthiender Jul 12 '18 at 12:14
  • I ended up rsyncing my entire codebase to a new directory and running HPC manually. Still within that stack exec environment though. Has worked fine for me since, although I would rather stack worked correctly here. – James Jul 14 '18 at 04:11
  • You mean rsyncing the codebase without built code (without .stack-work directory) in a different directory and running hpc? How did you install hpc in that then? How did you get the .tix files? Can you elaborate it a bit pls? – ecthiender Jul 14 '18 at 06:16
  • 1
    As in I made a new directory inside my stack project folder structure, and rsynced all my source files into that folder. I stack installed hpc (or maybe it comes by default with GHC?) At which point I just followed the HPC wiki to generate the tix files. – James Jul 15 '18 at 08:14

1 Answers1

1

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)

Zhu Jinxuan
  • 406
  • 2
  • 8