Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.CodeAnalysis.Testing/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
netstandard1.6/net46: Roslyn 2.x
netstandard2.0/net472: Roslyn 3.x
-->
<TestingLibraryTargetFrameworks>netcoreapp3.1;netstandard1.6;netstandard2.0;net452;net46;net472</TestingLibraryTargetFrameworks>
<TestingLibraryTargetFrameworks>net7.0;netcoreapp3.1;netstandard1.6;netstandard2.0;net452;net46;net472</TestingLibraryTargetFrameworks>

<!--
netcoreapp3.1: Ensures full support for nullable reference types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public static ReferenceAssemblies Default
return NetFramework.Net472.Default;
#elif NETCOREAPP3_1
return NetCore.NetCoreApp31;
#elif NET7_0
return Net.Net70;
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Microsoft.CodeAnalysis.CSharp.Testing
{
public class CSharpAnalyzerTest<TAnalyzer, TVerifier> : AnalyzerTest<TVerifier>
public partial class CSharpAnalyzerTest<TAnalyzer, TVerifier> : AnalyzerTest<TVerifier>
where TAnalyzer : DiagnosticAnalyzer, new()
where TVerifier : IVerifier, new()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;

namespace Microsoft.CodeAnalysis.CSharp.Testing;

public partial class CSharpAnalyzerTest<TAnalyzer, TVerifier>
{
// For net9.0 the second parameter could be 'params ReadOnlySpan<DiagnosticResult> expectedDiagnostics'
public static CSharpAnalyzerTest<TAnalyzer, TVerifier> Create([StringSyntax("C#-test")] string source, params DiagnosticResult[] expectedDiagnostics)
{
var test = new CSharpAnalyzerTest<TAnalyzer, TVerifier> { TestCode = source };
test.ExpectedDiagnostics.AddRange(expectedDiagnostics);

return test;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;

namespace Microsoft.CodeAnalysis.CSharp.Testing;

public static class CSharpAnalyzerTestExtensions
{
public static CSharpAnalyzerTest<TAnalyzer, TVerifier> WithSource<TAnalyzer, TVerifier>(this CSharpAnalyzerTest<TAnalyzer, TVerifier> test, [StringSyntax("C#-test")] string source)
where TAnalyzer : DiagnosticAnalyzer, new()
where TVerifier : IVerifier, new()
{
test.TestState.Sources.Add(source);
return test;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
<PackageTags>Roslyn Analyzer Test Framework C# Types</PackageTags>
</PropertyGroup>

<ItemGroup>
<Compile Remove="CSharpAnalyzerTest`2.net7.cs" />
<Compile Remove="Extensions/CSharpAnalyzerTestExtensions.net7.cs" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<Compile Include="CSharpAnalyzerTest`2.net7.cs" />
<Compile Include="Extensions/CSharpAnalyzerTestExtensions.net7.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.0.1" />
</ItemGroup>
Expand Down
Loading