我使用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 &
我很确定在运行可执行文件后捕获coverage之前我需要排除目录。
答案 0 :(得分:11)
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。