我使用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 &
我相信在执行可执行文件后捕获覆盖率之前,我需要排除这些目录。