gcovr -v -b -r .^
–xml-pretty^
-o “.\abc\xyz\coverage.xml”^
–sort-percentage^
-s ^
–exclude=“.(abc|dehcjf|SDK_GENERATED).”
This gcov command provides the code coverage results for lines, functions and branches on the console output
Example:
lines: 99.9% (1104 out of 1105)
Functions:100.0% (142 out of 142)
Branches: 96.6% (312 out of 323)
Requirement
But i wanted only the coverage results to be redirected to a different file,(the above example is just the part of whole console) so that i can make the pipeline fail, whenever any of the coverage result (lines,functions,branches) is below 90%
But the same i am unable to do in batch scripting
Trails:
for /f “tokens=2 delims=:” %%a in (‘findstr “lines:” .\reports\publish\coverage.xml’) do set lines_coverage=%%a
for /f “tokens=2 delims=:” %%a in (‘findstr “functions:” .\reports\publish\coverage.xml’) do set functions_coverage=%%a
for /f “tokens=2 delims=:” %%a in (‘findstr “branches:” .\reports\publish\coverage.xml’) do set branches_coverage=%%a
:: Remove whitespace characters and check the values
set lines_coverage=!lines_coverage: =!
set functions_coverage=!functions_coverage: =!
set branches_coverage=!branches_coverage: =!
:: Check if coverage is greater than 90% for lines, functions, and branches
for /f “delims=.” %%a in (“!lines_coverage!”) do set lines_coverage_int=%%a
for /f “delims=.” %%a in (“!functions_coverage!”) do set functions_coverage_int=%%a
for /f “delims=.” %%a in (“!branches_coverage!”) do set branches_coverage_int=%%a
if !lines_coverage_int! geq 90 (
echo Lines coverage is !lines_coverage!%%.
) else (
echo Lines coverage is below 90%%: !lines_coverage!%%
goto :fail
)
output:
Lines coverage is below 90%: !lines_coverage!%
The system cannot find the batch label specified - fail
I am basically trying to fetch the code coverage results of lines,branches and functions from gcovr -v -b -r .^ --xml-pretty^, So that i can integrate those results to make pipeline pass/fail based on coverage results of lines,branches and functions.
Even after trying to fetch & redirect the gcovr -v -b -r .^ --text the coverage file is empty