Skip to content

Commit

Permalink
Fix S2187: Rule should not raise an issue when class is abstract (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaury Levé authored Nov 14, 2017
1 parent 97ef069 commit 6f70b5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SonarAnalyzer for .NET
* Copyright (C) 2015-2017 SonarSource SA
* mailto: contact AT sonarsource DOT com
Expand Down Expand Up @@ -61,8 +61,10 @@ protected override void Initialize(SonarAnalysisContext context)
}
var classDeclaration = (ClassDeclarationSyntax)c.Node;
var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration);
var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration);
if (classSymbol == null ||
classSymbol.IsAbstract ||
!classSymbol.GetAttributes().Any(a => a.AttributeClass.IsAny(HandledTestClassAttributes)))
{
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -58,4 +58,32 @@ class ClassTest9
[TestMethod]
public void Foo() { }
}

[TestClass]
public abstract class MyCommonCode1
{
}

[TestClass]
public class MySubCommonCode1 : MyCommonCode1 // Noncompliant
{
}

public class MySubCommonCode11 : MyCommonCode1 // Compliant
{
}

[TestFixture]
public abstract class MyCommonCode2
{
}

[TestFixture]
public class MySubCommonCode2 : MyCommonCode2 // Noncompliant
{
}

public class MySubCommonCode22 : MyCommonCode2 // Compliant
{
}
}

0 comments on commit 6f70b5e

Please sign in to comment.