Skip to content

Commit

Permalink
[3.7] Don't report diagnostic for DeploymentItem on abstract class (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Jan 7, 2025
1 parent d4dba98 commit b656ff1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public override void Initialize(AnalysisContext context)

private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbol testMethodAttributeSymbol, INamedTypeSymbol testClassAttributeSymbol, INamedTypeSymbol deploymentItemAttributeSymbol)
{
if (context.Symbol is INamedTypeSymbol { IsAbstract: true })
{
// As [DeploymentItem] attribute is inherited, it's okay to be present on an abstract class that is not a test class.
// See https://github.com/microsoft/testfx/issues/2683 for information.
// For now, we do the IsAbstract check specifically for classes and not methods.
// If we got a convincing feedback around a false positive for the attribute on an abstract method, we can adjust the check.
return;
}

bool hasDeploymentItemAttribute = false;
bool isTestMethodOrTestClass = false;
foreach (AttributeData attribute in context.Symbol.GetAttributes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ public void MyTestMethod()
await VerifyCS.VerifyAnalyzerAsync(code);
}

public async Task WhenAnAbstractClassHasDeploymentItem_NoDiagnostic()
{
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;
[DeploymentItem("")]
public abstract class MyTestClass
{
}
""";

await VerifyCS.VerifyAnalyzerAsync(code);
}

public async Task WhenAClassHasDeploymentItem_Diagnostic()
{
string code = """
Expand Down

0 comments on commit b656ff1

Please sign in to comment.