I am trying to make Jenkins show the test coverage stats for all my codebase.
I am compiling with the -g -O0 --coverage flags, executing the tests and correctly generating an xml file for each of my C++ library.
For the coverage I am using this script:
# Check if the exclude_test_paths argument is provided and set to 1
exclude_test_paths=0
if [ $# -eq 1 ] && [ "$1" -eq 1 ]; then
exclude_test_paths=1
fi
for OUTPUT in $(find ../.. -type d -name 'src')
do
source="$OUTPUT"
echo "source is: $OUTPUT"
library_name=$(basename $(dirname "$source")) # Extract the library name
echo "library_name is: $library_name"
build=${source/src/build}
coverage_file_path="${build}/${library_name}_cov.xml" # Customize the coverage report name
echo "coverage_file_path is: $coverage_file_path"
echo "build is: $build"
# Check if the path should be excluded based on the exclude_test_paths flag
if [ $exclude_test_paths -eq 1 ] && { [[ "$source" == */tests/* ]] || [[ "$source" == */test/* ]]; }; then
continue
fi
if [ -d "$source" ] && [ -d "$build" ]
then
gcovr -r "$build" --object-directory "$source" -x -o "$coverage_file_path"
echo "Coverage report generated for $library_name"
fi
done
echo "OK coverage files generated"
While on Jenkins's pipeline I am using cobertura in this way:
cobertura (
autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: '**/*coverage.xml',
conditionalCoverageTargets: '70, 0, 0',
failUnhealthy: false,
failUnstable: false,
lineCoverageTargets: '80, 0, 0',
maxNumberOfBuilds: 0,
methodCoverageTargets: '80, 0, 0',
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: true
)
I correctly get coverage stats about all my source code. Different XML files are correctly generated, but Jenkins just shows me the stats like if there was only one library (I see packages: 1), while I'd like to visualize different stats for each library (many packages).
I know for sure that it is possible using Java, but what about C++? Am I doing something wrong? is that a limitation of the Jenkins plugin? I have tried to change both the pipeline configuration, the bash script and the gcovr options in many ways, but still no improvement.
Thank you in advance for any hints you would like to share.