Skip to content

Commit

Permalink
Add 'DiagnosticSuppressorTests'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 25, 2024
1 parent f01ea62 commit b797de6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/Tests/SourceGeneratorTest/DiagnosticSuppressorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading.Tasks;
using Generator;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SourceGeneratorTest.Helpers;

namespace SourceGeneratorTest;

[TestClass]
public sealed class DiagnosticSuppressorTests
{
public static readonly DiagnosticResult IDE0300 = DiagnosticResult.CompilerWarning("IDE0300");

[TestMethod]
public async Task CollectionExpression_IDE0300_ArrayInitializer_TargetingArray_NotSuppressed()
{
await new CSharpSuppressorTest<CollectionExpressionIDE0300Suppressor>(
"""
class TestClass
{
private int[] f = {|IDE0300:{|} 1, 2, 3 };

void TestMethod()
{
int[] a = {|IDE0300:{|} 1, 2, 3 };
}

public int[] P { get; } = {|IDE0300:{|} 1, 2, 3 };
}
""")
.WithAnalyzer("Microsoft.CodeAnalysis.CSharp.UseCollectionExpression.CSharpUseCollectionExpressionForArrayDiagnosticAnalyzer, Microsoft.CodeAnalysis.CSharp.CodeStyle")
.WithSpecificDiagnostics(IDE0300)
.RunAsync();
}
}
11 changes: 9 additions & 2 deletions src/Tests/SourceGeneratorTest/SourceGeneratorTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-3.final" />
</ItemGroup>

<!-- Directly reference these two analyzers as direct references, so we can instantiate the analyzers we need for the tests -->
<ItemGroup>
<ProjectReference Include="..\..\Authoring\WinRT.SourceGenerator.Roslyn4080\WinRT.SourceGenerator.Roslyn4080.csproj" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.11.0" IncludeAssets="none" PrivateAssets="all" GeneratePathProperty="true" />
<Reference Include="$(PkgMicrosoft_CodeAnalysis_CSharp_CodeStyle)\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CodeStyle.dll" />
<Reference Include="$(PkgMicrosoft_CodeAnalysis_CSharp_CodeStyle)\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Authoring\WinRT.SourceGenerator.Roslyn4120\WinRT.SourceGenerator.Roslyn4120.csproj" />
<ProjectReference Include="..\..\WinRT.Runtime\WinRT.Runtime.csproj" />
</ItemGroup>
</Project>

0 comments on commit b797de6

Please sign in to comment.