From 1cbfa87ead06914e40ff75ea05ce537c1bfc8898 Mon Sep 17 00:00:00 2001 From: Andrei Epure Date: Wed, 20 Jul 2022 16:49:01 +0200 Subject: [PATCH] Add coverlet connector - Update VSTest to minimum supported version - Use the coverlet connector Due to known issues, the datacollector integration is suggested See https://github.com/coverlet-coverage/coverlet/issues/1278#issuecomment-1125696912 And https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md --- analyzers/runsettings.xml | 20 ++++++ .../SonarAnalyzer.UnitTest.csproj | 12 +++- .../SonarAnalyzer.UnitTest/packages.lock.json | 63 +++++++++++++------ azure-pipelines.yml | 30 ++++++++- 4 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 analyzers/runsettings.xml diff --git a/analyzers/runsettings.xml b/analyzers/runsettings.xml new file mode 100644 index 00000000000..f58efc1e0d4 --- /dev/null +++ b/analyzers/runsettings.xml @@ -0,0 +1,20 @@ + + + + + + + opencover + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/SonarAnalyzer.UnitTest.csproj b/analyzers/tests/SonarAnalyzer.UnitTest/SonarAnalyzer.UnitTest.csproj index fada11fa895..4df8a118321 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/SonarAnalyzer.UnitTest.csproj +++ b/analyzers/tests/SonarAnalyzer.UnitTest/SonarAnalyzer.UnitTest.csproj @@ -15,6 +15,7 @@ --> $(AssetTargetFallback);net40-client;portable-net45+win8+wp8+wpa81; {e11606ca-a186-4fee-ba30-b1688747cd1a} + true @@ -27,7 +28,16 @@ - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/packages.lock.json b/analyzers/tests/SonarAnalyzer.UnitTest/packages.lock.json index e0e509c5351..ed2d0b11529 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/packages.lock.json +++ b/analyzers/tests/SonarAnalyzer.UnitTest/packages.lock.json @@ -2,6 +2,18 @@ "version": 1, "dependencies": { ".NETFramework,Version=v4.8": { + "coverlet.collector": { + "type": "Direct", + "requested": "[3.1.2, )", + "resolved": "3.1.2", + "contentHash": "wuLDIDKD5XMt0A7lE31JPenT7QQwZPFkP5rRpdJeblyXZ9MGLI8rYjvm5fvAKln+2/X+4IxxQDxBtwdrqKNLZw==" + }, + "coverlet.msbuild": { + "type": "Direct", + "requested": "[3.1.2, )", + "resolved": "3.1.2", + "contentHash": "QhM0fnDtmIMImY7oxyQ/kh1VYtRxPyRVeLwRUGuUvI6Xp83pSYG9gerK8WgJj4TzUl7ISziADUGtIWKhtlbkbQ==" + }, "FluentAssertions": { "type": "Direct", "requested": "[5.10.3, )", @@ -58,11 +70,11 @@ }, "Microsoft.NET.Test.Sdk": { "type": "Direct", - "requested": "[16.4.0, )", - "resolved": "16.4.0", - "contentHash": "gjjqS3rCzg4DrSQq4YwJwUUvc49HtXpXrZkW9fu5VG+K4X+Ztn4+UzolyML7wPnl/EAIufk4hu628bJB4WtpFg==", + "requested": "[16.11.0, )", + "resolved": "16.11.0", + "contentHash": "f4mbG1SUSkNWF5p7B3Y8ZxMsvKhxCmpZhdl+w6tMtLSUGE7Izi1syU6TkmKOvB2BV66pdbENConFAISOix4ohQ==", "dependencies": { - "Microsoft.CodeCoverage": "16.4.0" + "Microsoft.CodeCoverage": "16.11.0" } }, "Moq": { @@ -185,8 +197,8 @@ }, "Microsoft.CodeCoverage": { "type": "Transitive", - "resolved": "16.4.0", - "contentHash": "qb7PMVZMAY5iUCvB/kDUEt9xqazWKZoKY/sGpAJO4VtwgN5IcEgipCu3n0i1GPCwGbWVL6k4a8a9F+FqmADJng==" + "resolved": "16.11.0", + "contentHash": "wf6lpAeCqP0KFfbDVtfL50lr7jY1gq0+0oSphyksfLOEygMDXqnaxHK5LPFtMEhYSEtgXdNyXNnEddOqQQUdlQ==" }, "Newtonsoft.Json": { "type": "Transitive", @@ -431,6 +443,18 @@ } }, "net6.0": { + "coverlet.collector": { + "type": "Direct", + "requested": "[3.1.2, )", + "resolved": "3.1.2", + "contentHash": "wuLDIDKD5XMt0A7lE31JPenT7QQwZPFkP5rRpdJeblyXZ9MGLI8rYjvm5fvAKln+2/X+4IxxQDxBtwdrqKNLZw==" + }, + "coverlet.msbuild": { + "type": "Direct", + "requested": "[3.1.2, )", + "resolved": "3.1.2", + "contentHash": "QhM0fnDtmIMImY7oxyQ/kh1VYtRxPyRVeLwRUGuUvI6Xp83pSYG9gerK8WgJj4TzUl7ISziADUGtIWKhtlbkbQ==" + }, "FluentAssertions": { "type": "Direct", "requested": "[5.10.3, )", @@ -490,12 +514,12 @@ }, "Microsoft.NET.Test.Sdk": { "type": "Direct", - "requested": "[16.4.0, )", - "resolved": "16.4.0", - "contentHash": "gjjqS3rCzg4DrSQq4YwJwUUvc49HtXpXrZkW9fu5VG+K4X+Ztn4+UzolyML7wPnl/EAIufk4hu628bJB4WtpFg==", + "requested": "[16.11.0, )", + "resolved": "16.11.0", + "contentHash": "f4mbG1SUSkNWF5p7B3Y8ZxMsvKhxCmpZhdl+w6tMtLSUGE7Izi1syU6TkmKOvB2BV66pdbENConFAISOix4ohQ==", "dependencies": { - "Microsoft.CodeCoverage": "16.4.0", - "Microsoft.TestPlatform.TestHost": "16.4.0" + "Microsoft.CodeCoverage": "16.11.0", + "Microsoft.TestPlatform.TestHost": "16.11.0" } }, "Moq": { @@ -666,8 +690,8 @@ }, "Microsoft.CodeCoverage": { "type": "Transitive", - "resolved": "16.4.0", - "contentHash": "qb7PMVZMAY5iUCvB/kDUEt9xqazWKZoKY/sGpAJO4VtwgN5IcEgipCu3n0i1GPCwGbWVL6k4a8a9F+FqmADJng==" + "resolved": "16.11.0", + "contentHash": "wf6lpAeCqP0KFfbDVtfL50lr7jY1gq0+0oSphyksfLOEygMDXqnaxHK5LPFtMEhYSEtgXdNyXNnEddOqQQUdlQ==" }, "Microsoft.CSharp": { "type": "Transitive", @@ -704,18 +728,19 @@ }, "Microsoft.TestPlatform.ObjectModel": { "type": "Transitive", - "resolved": "16.4.0", - "contentHash": "4geKywSUJHHrfBTr1wJXUVWP0Vx1X03oFQAdZdGa8jK8p5MSwsJ4Vd0/mqN0dB2YXaIXIhDT94ti5WQ1KZ4jdw==", + "resolved": "16.11.0", + "contentHash": "EiknJx9N9Z30gs7R+HHhki7fA8EiiM3pwD1vkw3bFsBC8kdVq/O7mHf1hrg5aJp+ASO6BoOzQueD2ysfTOy/Bg==", "dependencies": { - "NuGet.Frameworks": "5.0.0" + "NuGet.Frameworks": "5.0.0", + "System.Reflection.Metadata": "1.6.0" } }, "Microsoft.TestPlatform.TestHost": { "type": "Transitive", - "resolved": "16.4.0", - "contentHash": "tMlz3uc7VUZSYYslyVOVXH40KexTptZMAi8gIE+5w+SIt8I0qLPObpqX6QVLWszPr7sxX4WAKTiFgqgBB1MxjA==", + "resolved": "16.11.0", + "contentHash": "/Q+R0EcCJE8JaYCk+bGReicw/xrB0HhecrYrUcLbn95BnAlaTJrZhoLkUhvtKTAVtqX/AIKWXYtutiU/Q6QUgg==", "dependencies": { - "Microsoft.TestPlatform.ObjectModel": "16.4.0", + "Microsoft.TestPlatform.ObjectModel": "16.11.0", "Newtonsoft.Json": "9.0.1" } }, diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3ca088d2bc7..c29c5de56e4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -162,11 +162,24 @@ stages: - powershell: | . .\scripts\utils.ps1 + $TestResultsDir = "analyzers\tests\SonarAnalyzer.UnitTest\TestResults\" + if (Test-Path $TestResultsDir) { Remove-Item -Path $TestResultsDir -Recurse -Verbose } + CreateFolder("coverage") CreateFolder("TestResults") - & OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net48.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute + gci analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48 + + dotnet test .\analyzers\SonarAnalyzer.sln --no-build --collect:"XPlat Code Coverage" --settings .\analyzers\runsettings.xml -l "trx;logfilename=net48.trx" -l "console;verbosity=diagnostic" -c $(BuildConfiguration) -f net48 -v diag Test-ExitCode "ERROR: Unit tests for net48 FAILED." + + gci -Path $TestResultsDir -Recurse + + Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter coverage.opencover.xml | Copy-Item -Verbose -Destination .\coverage\net48.xml + Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter net48.trx | Copy-Item -Verbose -Destination .\TestResults\ + + ### & OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net48.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute + ### Test-ExitCode "ERROR: Unit tests for net48 FAILED." displayName: '.Net UTs' - task: PublishPipelineArtifact@1 @@ -194,11 +207,24 @@ stages: - powershell: | . .\scripts\utils.ps1 + $TestResultsDir = "analyzers\tests\SonarAnalyzer.UnitTest\TestResults\" + if (Test-Path $TestResultsDir) { Remove-Item -Path $TestResultsDir -Recurse -Verbose } + CreateFolder("coverage") CreateFolder("TestResults") - & OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net6.0.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute + gci "analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0" + + dotnet test .\analyzers\SonarAnalyzer.sln --no-build --collect:"XPlat Code Coverage" --settings .\analyzers\runsettings.xml -l "trx;logfilename=net6.0.trx" -l "console;verbosity=diagnostic" -c $(BuildConfiguration) -f "net6.0" -v diag Test-ExitCode "ERROR: Unit tests for net6.0 FAILED." + + gci -Path $TestResultsDir -Recurse + + Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter coverage.opencover.xml | Copy-Item -Verbose -Destination .\coverage\net6.0.xml + Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter net6.0.trx | Copy-Item -Verbose -Destination .\TestResults\ + + ## & OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net6.0.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute + ## Test-ExitCode "ERROR: Unit tests for net6.0 FAILED." displayName: '.Net UTs' - task: PublishPipelineArtifact@1