rom-properties/scripts/lcov.sh
David Korth cc4581e429 [scripts] lcov.sh: Correctly exclude extlib/ and tests/ from coverage output.
On some systems, the full path is included in the code coverage data,
so we have to prefix these with '*/'.
2018-01-13 02:45:49 -05:00

38 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# lcov code coverage script.
# Based on: https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
# (commit 59f8ab8dded56b490dec388ac6ad449318de8779)
#
# Parameters:
# - $1: Build configuration.
# - $2: Base name for lcov files.
# - $3: Output directory.
#
if [ "$#" != "3" -o ! -f CMakeCache.txt ]; then
echo "Syntax: $0 config basename output_directory"
echo "Run this script from the top-level CMake build directory."
exit 1
fi
CONFIG="$1"
coverage_info="$2.info"
coverage_cleaned="${coverage_info}.cleaned"
outputname="$3"
# Cleanup lcov.
lcov --directory . --zerocounters
# Run tests.
ctest -C "${CONFIG}"
if [ "$?" != "0" ]; then
echo "*** WARNING: Some tests failed. Generating the lcov report anyway." >&2
fi
# Capturing lcov counters and generating report.
lcov --directory . --capture --output-file ${coverage_info}
lcov --remove ${coverage_info} '*/tests/*' '/usr/*' '*/extlib/*' --output-file ${coverage_cleaned}
genhtml -o ${outputname} ${coverage_cleaned}
rm -f ${coverage_info} ${coverage_cleaned}
exit 0