bash 如何从 lcov 代码覆盖率报告中删除某些目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38438219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove certain directories from lcov code coverage report?
提问by I_love_coding_93
I'm not too strong with using lcov and shell scripting so it's a learning process for me. I understand the basics of making a code coverage report but I don't know the line of code to exclude certain directories. In a shell executable file I wrote the following code:
我不太擅长使用 lcov 和 shell 脚本,所以这对我来说是一个学习过程。我了解制作代码覆盖率报告的基础知识,但我不知道排除某些目录的代码行。在 shell 可执行文件中,我编写了以下代码:
#!/bin/sh
ROOT_DIR=
DEST_DIR=
TARGET_DIR=
TARGET=
#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 &
I'm pretty sure I need to exclude the directories before I capture the coverage after running executable.
我很确定我需要在运行可执行文件后捕获覆盖范围之前排除目录。
回答by Inian
lcov
has an option --remove
to ignore coverage data for specified files.
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.
--remove tracefile pattern
从 中删除数据
tracefile
。如果您想从
tracefile
. 额外的命令行参数将被解释为 shell 通配符模式(请注意,它们可能需要相应地转义以防止 shell 首先扩展它们)。跟踪文件中至少匹配这些模式之一的每个文件条目都将被删除。删除操作的结果将写入 stdout 或
tracefile
指定的-o
.一次 只能指定
-z
、-c
、-a
、-e
、-r
、-l
、--diff
or 之一--summary
。
You can do something like; quoting from the hyper-link below
你可以做类似的事情;引自下面的超链接
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/*' \
Refer to this pagefor more documentation.
有关更多文档,请参阅此页面。