Skip to content

Commit

Permalink
Refactor Analyzer tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausLoeffelmann committed Jan 23, 2025
1 parent 85a762d commit fb2433a
Show file tree
Hide file tree
Showing 24 changed files with 977 additions and 440 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<CSharpIsNullAnalyzersVersion>0.1.495</CSharpIsNullAnalyzersVersion>
<DotNetAnalyzersDocumentationAnalyzersVersion>1.0.0-beta.59</DotNetAnalyzersDocumentationAnalyzersVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.12.0-beta1.24559.1</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.10.0-3.final</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.12.0</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>$(MicrosoftCodeAnalysisCommonPackageVersion)</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisVisualBasicPackageVersion>$(MicrosoftCodeAnalysisCommonPackageVersion)</MicrosoftCodeAnalysisVisualBasicPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>$(MicrosoftCodeAnalysisCommonPackageVersion)</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Windows.Forms.Analyzers.Diagnostics;
using System.Windows.Forms.CSharp.Analyzers.AvoidPassingTaskWithoutCancellationToken;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;

namespace System.Windows.Forms.Analyzers.Test;

public class AvoidPassingTaskWithoutCancellationTokenTests
{
// Currently, we do not have Control.InvokeAsync in the .NET 9.0 Windows reference assemblies.
// That's why we need to add this Async Control. Once it's there, this test will fail.
// We can then remove the AsyncControl and the test will pass, replace AsyncControl with
// Control, and the test will pass.
private const string AsyncControl = """
""";

private const string TestCode = """
""";

public static IEnumerable<object[]> GetReferenceAssemblies()
{
yield return [ReferenceAssemblies.Net.Net90Windows];
}

[Theory]
[MemberData(nameof(GetReferenceAssemblies))]
public async Task AvoidPassingTaskWithoutCancellationAnalyzer(ReferenceAssemblies referenceAssemblies)
{
// If the API does not exist, we need to add it to the test.
string customControlSource = AsyncControl;
string diagnosticId = DiagnosticIDs.AvoidPassingFuncReturningTaskWithoutCancellationToken;

var context = new CSharpAnalyzerTest
<AvoidPassingTaskWithoutCancellationTokenAnalyzer,
DefaultVerifier>
{
TestCode = TestCode,
TestState =
{
OutputKind = OutputKind.WindowsApplication,
Sources = { customControlSource },
ExpectedDiagnostics =
{
DiagnosticResult.CompilerWarning(diagnosticId).WithSpan(41, 21, 41, 97),
DiagnosticResult.CompilerWarning(diagnosticId).WithSpan(44, 21, 44, 97),
DiagnosticResult.CompilerWarning(diagnosticId).WithSpan(47, 21, 47, 98),
},
},
ReferenceAssemblies = referenceAssemblies
};

await context.RunAsync();
}
}
Loading

0 comments on commit fb2433a

Please sign in to comment.