Skip to content

Commit

Permalink
Improve diagnostics for incorrect test configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Mar 31, 2020
1 parent 75fb12b commit 7665c38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using Roslyn.Utilities;
using Xunit;

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

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

public override async Task RunAsync(CancellationToken cancellationToken = default)
{
if (DiagnosticSelector is object)
{
Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'");
}

await base.RunAsync(cancellationToken);
}

#if !CODE_STYLE
protected override AnalyzerOptions GetAnalyzerOptions(Project project)
=> new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project.Solution);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.CodeAnalysis.VisualBasic.Testing;
using Roslyn.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
Expand Down Expand Up @@ -70,6 +73,16 @@ public Test()

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

public override async Task RunAsync(CancellationToken cancellationToken = default)
{
if (DiagnosticSelector is object)
{
Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'");
}

await base.RunAsync(cancellationToken);
}

#if !CODE_STYLE
protected override AnalyzerOptions GetAnalyzerOptions(Project project)
=> new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project.Solution);
Expand Down

0 comments on commit 7665c38

Please sign in to comment.