Skip to content

Commit 6f2eada

Browse files
author
msftbot[bot]
authored
Merge pull request #42954 from sharwell/validate-selector
Improve diagnostics for incorrect test configuration
2 parents a171bdc + 7665c38 commit 6f2eada

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
using System;
88
using System.Collections.Immutable;
9+
using System.Threading;
10+
using System.Threading.Tasks;
911
using Microsoft.CodeAnalysis.CodeFixes;
1012
using Microsoft.CodeAnalysis.CSharp;
1113
using Microsoft.CodeAnalysis.CSharp.Testing;
1214
using Microsoft.CodeAnalysis.Diagnostics;
1315
using Microsoft.CodeAnalysis.Shared.Extensions;
1416
using Microsoft.CodeAnalysis.Testing.Verifiers;
1517
using Roslyn.Utilities;
18+
using Xunit;
1619

1720
namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
1821
{
@@ -98,6 +101,16 @@ private static ImmutableDictionary<string, ReportDiagnostic> GetNullableWarnings
98101

99102
public Func<ImmutableArray<Diagnostic>, Diagnostic?>? DiagnosticSelector { get; set; }
100103

104+
public override async Task RunAsync(CancellationToken cancellationToken = default)
105+
{
106+
if (DiagnosticSelector is object)
107+
{
108+
Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'");
109+
}
110+
111+
await base.RunAsync(cancellationToken);
112+
}
113+
101114
#if !CODE_STYLE
102115
protected override AnalyzerOptions GetAnalyzerOptions(Project project)
103116
=> new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project.Solution);

src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
using System;
88
using System.Collections.Immutable;
9+
using System.Threading;
10+
using System.Threading.Tasks;
911
using Microsoft.CodeAnalysis.CodeFixes;
1012
using Microsoft.CodeAnalysis.Diagnostics;
1113
using Microsoft.CodeAnalysis.Testing.Verifiers;
1214
using Microsoft.CodeAnalysis.VisualBasic;
1315
using Microsoft.CodeAnalysis.VisualBasic.Testing;
1416
using Roslyn.Utilities;
17+
using Xunit;
1518

1619
namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
1720
{
@@ -70,6 +73,16 @@ public Test()
7073

7174
public Func<ImmutableArray<Diagnostic>, Diagnostic?>? DiagnosticSelector { get; set; }
7275

76+
public override async Task RunAsync(CancellationToken cancellationToken = default)
77+
{
78+
if (DiagnosticSelector is object)
79+
{
80+
Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'");
81+
}
82+
83+
await base.RunAsync(cancellationToken);
84+
}
85+
7386
#if !CODE_STYLE
7487
protected override AnalyzerOptions GetAnalyzerOptions(Project project)
7588
=> new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project.Solution);

0 commit comments

Comments
 (0)