I am also attempting to call HPC directly and have a similar error.
Cabal 3.6 should be able to generate your HPC report for you without needing to call HPC like you describe. It can bypass that error. There is one caveat:
https://github.com/haskell/cabal/issues/6440#issuecomment-1133542171
Add to cabal.project
:
package *
coverage: True
library-coverage: True
then cabal test
. The report should be somewhere in dist-newstyle
.
Reading the verbose log from cabal test
with the options above has shown the correct arguments to HPC. It solves the module error.
Here is an example for Mustache: https://github.com/JustusAdam/mustache
Add to cabal.project
:
package *
coverage: True
library-coverage: True
then cabal test -v all > foo.log
.
In foo.log
there should be a call to HPC such as:
~/.ghcup/ghc/8.10.7/bin/hpc markup \
dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/t/unit-tests/hpc/vanilla/tix/unit-tests/unit-tests.tix \
'--destdir=dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/t/unit-tests/hpc/vanilla/html/unit-tests' \
'--hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/hpc/vanilla/mix/unit-tests' \
'--hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/hpc/vanilla/mix/mustache-2.4.0' \
'--include=Text.Mustache' \
'--include=Text.Mustache.Types' \
'--include=Text.Mustache.Parser' \
'--include=Text.Mustache.Compile' \
'--include=Text.Mustache.Render'
Take that, replace markup
with report
, and remove --destdir
, which gives something like:
hpc report dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/t/unit-tests/hpc/vanilla/tix/unit-tests/unit-tests.tix \
'--hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/hpc/vanilla/mix/unit-tests' \
'--hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.10.7/mustache-2.4.0/hpc/vanilla/mix/mustache-2.4.0' \
'--include=Text.Mustache' \
'--include=Text.Mustache.Types' \
'--include=Text.Mustache.Parser' \
'--include=Text.Mustache.Compile' \
'--include=Text.Mustache.Render'
Pasting that into the terminal in the root of the Mustache project yields:
59% expressions used (635/1069)
28% boolean coverage (4/14)
0% guards (0/6), 1 always True, 5 unevaluated
50% 'if' conditions (4/8), 1 always False, 3 unevaluated
100% qualifiers (0/0)
41% alternatives used (34/82)
56% local declarations used (13/23)
63% top-level declarations used (48/76)