-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85a762d
commit fb2433a
Showing
24 changed files
with
977 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 0 additions & 199 deletions
199
.../AvoidPassingTaskWithoutCancellationToken/AvoidPassingTaskWithoutCancellationTokenTest.cs
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
...alyzers.CSharp/tests/UnitTests/Analyzers/AvoidPassingTaskWithoutCancellationTokenTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.