-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add project with .Net 8 unit tests #8236
Conversation
90692f3
to
c25e5ba
Compare
[TestMethod] | ||
public void SelfAssignment() => | ||
builderCS.AddPaths("SelfAssignment.cs").WithOptions(ParseOptionsHelper.FromCSharp12).Verify(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to demonstrate that we can add .Net 8 unit tests on this project.
c25e5ba
to
6831983
Compare
azure-pipelines.yml
Outdated
@@ -203,13 +209,19 @@ stages: | |||
|
|||
- powershell: | | |||
cd analyzers | |||
& dotnet test -f $(FrameworkMoniker) -c $(BuildConfiguration) -l trx /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter='Moq|Humanizer|AltCover|Microsoft.VisualStudio.TestPlatform.*|.*Test',AltCoverPathFilter='SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration',AltCoverAttributeFilter='ExcludeFromCodeCoverage',AltCoverReport=coverage/coverage.xml | |||
if ("$(FrameworkMoniker)" -eq "net8.0-windows") { | |||
& dotnet test "tests\SonarAnalyzer.Net8.UnitTest\SonarAnalyzer.Net8.UnitTest.csproj" -f $(FrameworkMoniker) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter='Moq|Humanizer|AltCover|Microsoft.VisualStudio.TestPlatform.*|.*Test',AltCoverPathFilter='SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration',AltCoverAttributeFilter='ExcludeFromCodeCoverage',AltCoverReport=$(CoveragePath)/coverage.$(FrameworkMoniker).xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the target framework parameter is provided, all projects need to support that version. Since this is not possible with .net 8, we have to specify the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may miss context here, but I'm not sure if we should really do this. What is the future prospect of this change? Are we going to revert it or is this permanent? If we are going to revert it, how do we make sure the new UTs written here are easily movable to the main UT project when we revert? We need to keep a couple of things in sync to do so:
- namespaces
- global using
We also need some follow-up issues that describe how we want to evolve this solution in the future.
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<!-- `-windows` is required in order to be able to reference SonarAnalyzer.UnitTests --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- `-windows` is required in order to be able to reference SonarAnalyzer.UnitTests --> | |
<!-- `-windows` is required in order to be able to reference SonarAnalyzer.UnitTests to resolve e.g. WinForms references --> |
analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/ParseOptionsHelper.cs
Show resolved
Hide resolved
azure-pipelines.yml
Outdated
& dotnet test "tests\SonarAnalyzer.Net8.UnitTest\SonarAnalyzer.Net8.UnitTest.csproj" -f $(FrameworkMoniker) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter='Moq|Humanizer|AltCover|Microsoft.VisualStudio.TestPlatform.*|.*Test',AltCoverPathFilter='SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration',AltCoverAttributeFilter='ExcludeFromCodeCoverage',AltCoverReport=$(CoveragePath)/coverage.$(FrameworkMoniker).xml | ||
} | ||
else | ||
{ | ||
& dotnet test "tests\SonarAnalyzer.UnitTest\SonarAnalyzer.UnitTest.csproj" -f $(FrameworkMoniker) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter='Moq|Humanizer|AltCover|Microsoft.VisualStudio.TestPlatform.*|.*Test',AltCoverPathFilter='SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration',AltCoverAttributeFilter='ExcludeFromCodeCoverage',AltCoverReport=$(CoveragePath)/coverage.xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two cmd lines only differ in the csproj and the "Report" parameters. Consider using a variable for the common parts.
azure-pipelines.yml
Outdated
if ("$(FrameworkMoniker)" -eq "net8.0-windows") { | ||
& dotnet test "tests\SonarAnalyzer.Net8.UnitTest\SonarAnalyzer.Net8.UnitTest.csproj" -f $(FrameworkMoniker) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter='Moq|Humanizer|AltCover|Microsoft.VisualStudio.TestPlatform.*|.*Test',AltCoverPathFilter='SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration',AltCoverAttributeFilter='ExcludeFromCodeCoverage',AltCoverReport=$(CoveragePath)/coverage.$(FrameworkMoniker).xml | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also run the "normal" tests in .Net 8.
else |
analyzers/tests/SonarAnalyzer.Net8.UnitTest/SonarAnalyzer.Net8.UnitTest.csproj
Show resolved
Hide resolved
Hi @martin-strecker-sonarsource, I've clearly mentioned in the readme file that this is a temporary change.
In the same document I've mentioned that the plan is to extract the validation framework. There is no mention about a revert. The problem in the dotnet APIs appeared so many times that we might want to separate some of the tests until they change their design to not use nuget libraries. This is a way to have progress until 14 November when the new version is released and depending on the fixes they do we might adapt. |
4184ac1
to
0c2d013
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Situation in VS without .Net 8 SDK support (non "preview"):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. See my last comment for the impact for non-preview VS devs.
Fixes #8171
I've tested the coverage import with a separate PR that I had to remove. Here is how it looks on sonarcloud:
and this is the build: https://dev.azure.com/sonarsource/DotNetTeam%20Project/_build/results?buildId=79428