gpt4 book ai didi

bash - 如何从 lcov 代码覆盖率报告中删除某些目录?

转载 作者:行者123 更新时间:2023-11-29 08:54:42 25 4
gpt4 key购买 nike

我不太擅长使用 lcov 和 shell 脚本,所以这对我来说是一个学习过程。我了解制作代码覆盖率报告的基础知识,但我不知道排除某些目录的代码行。在 shell 可执行文件中,我编写了以下代码:

    #!/bin/sh
ROOT_DIR=$1
DEST_DIR=$2
TARGET_DIR=$3
TARGET=$4

#init lcov
lcov -c -i -d $TARGET_DIR/.. -o $TARGET_DIR/cov_init.info

#run unit test executable
"$DEST_DIR/$TARGET"

#capture coverage after running executable
lcov -c -d $TARGET_DIR/.. -o $TARGET_DIR/cov_test.info

#I added this in-generate delta of coverage
lcov -a $TARGET_DIR/cov_init.info -a $TARGET_DIR/cov_test.info -o $TARGET_DIR/cov.info

# I added this in- Excludes some third party code
lcov --remove $TARGET_DIR/cov.info '/opt/*' '/usr/*' '$ROOT_DIR/Common?ExternalLibraries/*'

#I added this in-generate report
genhtml $TARGET_DIR/cov.info --ignore-errors source --output-directory $DEST_DIR/CoverageReport/$TARGET
xdg-open $DEST_DIR/CoverageReport/$TARGET/index.html &

我很确定我需要在运行可执行文件后捕获覆盖范围之前排除目录。

最佳答案

lcov有一个选项 --remove 来忽略指定文件的覆盖率数据。

--remove tracefile pattern

Remove data from tracefile.

Use this switch if you want to remove coverage data for a par- ticular set of files from a tracefile. Additional command line parameters will be interpreted as shell wildcard patterns (note that they may need to be escaped accordingly to prevent the shell from expanding them first). Every file entry in tracefile which matches at least one of those patterns will be removed.

The result of the remove operation will be written to stdout or the tracefile specified with -o.

Only one of -z, -c, -a, -e, -r, -l, --diff or --summary may be specified at a time.

你可以这样做;从下面的超链接引用

lcov --remove /tmp/libreoffice_total.info -o /tmp/libreoffice_filtered.info \
'/usr/include/*' \
'/usr/lib/*' \
'/usr/local/src/libreoffice/*/UnpackedTarball/*' \
'/usr/local/src/libreoffice/workdir/*' \
'/usr/local/src/libreoffice/instdir/*' \
'/usr/local/src/libreoffice/external/*' \

引用this page获取更多文档。

关于bash - 如何从 lcov 代码覆盖率报告中删除某些目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38438219/

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