Hello,
I have a full C++ code that is tested with Google test.
I generate a code coverage with VS 2022 with the Microsoft.CodeCoverage.Console.exe
.
The converage works well but I don't manage how to use the runsettings file to filter namespace that I don't want.
In me case, I don't want to cover the testing
namespace of Google Test.
Here is the command I launch to instrument and collect coverage:
Start-Process -FilePath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console\Microsoft.CodeCoverage.Console.exe" -ArgumentList "instrument .\target\test\Debug\test_core.exe -s .\target\test\code_coverage.runsettings" -NoNewWindow -Wait
The input file has been instrumented.
Start-Process -FilePath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console\Microsoft.CodeCoverage.Console.exe" -ArgumentList "collect .\target\test\Debug\test_core.exe -s .\target\test\code_coverage.runsettings -o .\target\test\Debug\coverage -f xml" -NoNewWindow -Wait
Code coverage results : .\target\test\Debug\coverage.xml
When I import the file in VS 2022 I see that it export everything:
but I explicitly ask to not export testing in many ways in the code_coverage.runsettings:
<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacolsdsector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<!-- Match fully qualified names of functions: -->
<!-- (Use "\." to delimit namespaces in C# or Visual Basic, "::" in C++.) -->
<Functions>
<Exclude>
<Function>^std::.*</Function>
<Function>.*testing::.*</Function>
<Function>^testing::.*</Function>
<Function>.*testing.*</Function>
<Function>.*testing\..*</Function>
</Exclude>
</Functions>
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<EnableStaticNativeInstrumentation>True</EnableStaticNativeInstrumentation>
<EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
<EnableStaticNativeInstrumentationRestore>True</EnableStaticNativeInstrumentationRestore>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>