我发现hpc真的令人困惑,即使在阅读了几个解释和相当多的游玩之后。
我有一个库HML和两个测试套件fileio-test和types-test,使用HTF (我计划迁移到tasty)。我想运行这两个测试,然后在库中看到这两个测试的综合覆盖率。
目前,我使用
cabal configure --enable-coverage
cabal build并使用
cabal configure --enable-coverage --enable-tests
cabal build
cabal test
hpc report --hpc-dir dist/hpc/vanilla/mix/fileio-test dist/hpc/vanilla/tix/fileio-test/fileio-test.tix这向我展示了一些报道,但不是正确的。我认为它显示的是覆盖范围,但仅来自其中一个测试,并且还包括测试本身的覆盖范围。
我试着用
--hpc-dir dist/hpc/vanilla/mix/HML-0.1.0.0但是hpc抱怨它找不到它需要的模块文件。我还试着把两次测试的报道结合在一起,但没有运气。
有什么指示吗?
发布于 2022-05-23 21:02:50
我也试图直接打电话给HPC,并有类似的错误。
阴谋3.6应该能够为您生成您的HPC报告,而不必像您描述的那样调用HPC。它可以绕过那个错误。有一个警告:https://github.com/haskell/cabal/issues/6440#issuecomment-1133542171
添加到cabal.project中
package *
coverage: True
library-coverage: True然后是cabal test。报告应该在dist-newstyle的某个地方。
使用上面的选项从cabal test读取详细日志显示了正确的参数给HPC。解决了模块错误。下面是胡子的一个例子:https://github.com/JustusAdam/mustache
添加到cabal.project中
package *
coverage: True
library-coverage: True然后是cabal test -v all > foo.log。
在foo.log中,应该调用HPC,例如:
~/.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'就这样,将markup替换为report,并删除--destdir,它提供了如下内容:
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'将它粘贴到胡子项目根部的终端中会产生以下结果:
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)https://stackoverflow.com/questions/47343758
复制相似问题