gpt4 book ai didi

haskell - 将测试覆盖率与 hpc 相结合

转载 作者:行者123 更新时间:2023-12-04 18:11:20 26 4
gpt4 key购买 nike

我发现 hpc 真的很令人困惑,即使在阅读了一些解释并玩了很多之后。
我有一个图书馆 HML , 和两个测试套件 fileio-testtypes-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 提示它找不到它需要的模块文件。我还尝试将两个测试的覆盖率结合起来,但没有运气。
任何指针?

最佳答案

我也试图直接调用 HPC 并有类似的错误。
Cabal 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 显示了正确的参数。它解决了模块错误。
以下是 Mustache 的示例: 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'
拿那个,替换 markupreport , 并删除 --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'

将其粘贴到 Mustache 项目根目录中的终端会产生:
 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)

关于haskell - 将测试覆盖率与 hpc 相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47343758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com