首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将测试覆盖范围与hpc结合起来

将测试覆盖范围与hpc结合起来
EN

Stack Overflow用户
提问于 2017-11-17 05:19:54
回答 1查看 154关注 0票数 6

我发现hpc真的令人困惑,即使在阅读了几个解释和相当多的游玩之后。

我有一个库HML和两个测试套件fileio-testtypes-test,使用HTF (我计划迁移到tasty)。我想运行这两个测试,然后在库中看到这两个测试的综合覆盖率。

目前,我使用

代码语言:javascript
复制
cabal configure --enable-coverage
cabal build

并使用

代码语言:javascript
复制
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

这向我展示了一些报道,但不是正确的。我认为它显示的是覆盖范围,但仅来自其中一个测试,并且还包括测试本身的覆盖范围。

我试着用

代码语言:javascript
复制
--hpc-dir dist/hpc/vanilla/mix/HML-0.1.0.0

但是hpc抱怨它找不到它需要的模块文件。我还试着把两次测试的报道结合在一起,但没有运气。

有什么指示吗?

EN

回答 1

Stack Overflow用户

发布于 2022-05-23 21:02:50

我也试图直接打电话给HPC,并有类似的错误。

阴谋3.6应该能够为您生成您的HPC报告,而不必像您描述的那样调用HPC。它可以绕过那个错误。有一个警告:https://github.com/haskell/cabal/issues/6440#issuecomment-1133542171

添加到cabal.project

代码语言:javascript
复制
package *
  coverage: True
  library-coverage: True

然后是cabal test。报告应该在dist-newstyle的某个地方。

使用上面的选项从cabal test读取详细日志显示了正确的参数给HPC。解决了模块错误。下面是胡子的一个例子:https://github.com/JustusAdam/mustache

添加到cabal.project

代码语言:javascript
复制
package *
  coverage: True
  library-coverage: True

然后是cabal test -v all > foo.log

foo.log中,应该调用HPC,例如:

代码语言:javascript
复制
~/.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,它提供了如下内容:

代码语言:javascript
复制
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'

将它粘贴到胡子项目根部的终端中会产生以下结果:

代码语言:javascript
复制
 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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47343758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档