Skip to content

Commit a9cdee7

Browse files
declarations of ProcedureNotUsedInspection ignore ITestAnnotations
1 parent 0c4bb18 commit a9cdee7

File tree

8 files changed

+37
-6
lines changed

8 files changed

+37
-6
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.JunkDrawer.Extensions;
77
using Rubberduck.Parsing.Inspections.Abstract;
88
using Rubberduck.Resources.Inspections;
9+
using Rubberduck.Parsing.Annotations;
910
using Rubberduck.Parsing.Symbols;
1011
using Rubberduck.Parsing.VBA;
1112

@@ -99,7 +100,8 @@ private bool IsIgnoredDeclaration(Declaration declaration, IEnumerable<Declarati
99100
|| IsPublicModuleMember(modules, declaration)
100101
|| IsClassLifeCycleHandler(enumerable, declaration)
101102
|| interfaceMembers.Contains(declaration)
102-
|| interfaceImplementingMembers.Contains(declaration);
103+
|| interfaceImplementingMembers.Contains(declaration)
104+
|| declaration.Annotations.Any(x => x.Annotation is ITestAnnotation);
103105

104106
return result;
105107
}

Rubberduck.Parsing/Annotations/Concrete/ModuleCleanupAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
77
/// <summary>
88
/// Marks a method that the test engine will execute after all unit tests in a test module have executed.
99
/// </summary>
10-
public sealed class ModuleCleanupAnnotation : AnnotationBase
10+
public sealed class ModuleCleanupAnnotation : AnnotationBase, ITestAnnotation
1111
{
1212
public ModuleCleanupAnnotation()
1313
: base("ModuleCleanup", AnnotationTarget.Member)

Rubberduck.Parsing/Annotations/Concrete/ModuleInitializeAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
77
/// <summary>
88
/// Marks a method that the test engine will execute before executing the first unit test in a test module.
99
/// </summary>
10-
public sealed class ModuleInitializeAnnotation : AnnotationBase
10+
public sealed class ModuleInitializeAnnotation : AnnotationBase, ITestAnnotation
1111
{
1212
public ModuleInitializeAnnotation()
1313
: base("ModuleInitialize", AnnotationTarget.Member)

Rubberduck.Parsing/Annotations/Concrete/TestCleanupAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
77
/// <summary>
88
/// Marks a method that the test engine will execute after executing each unit test in a test module.
99
/// </summary>
10-
public sealed class TestCleanupAnnotation : AnnotationBase
10+
public sealed class TestCleanupAnnotation : AnnotationBase, ITestAnnotation
1111
{
1212
public TestCleanupAnnotation()
1313
: base("TestCleanup", AnnotationTarget.Member)

Rubberduck.Parsing/Annotations/Concrete/TestInitializeAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
77
/// <summary>
88
/// Marks a method that the test engine will execute before executing each unit test in a test module.
99
/// </summary>
10-
public sealed class TestInitializeAnnotation : AnnotationBase
10+
public sealed class TestInitializeAnnotation : AnnotationBase, ITestAnnotation
1111
{
1212
public TestInitializeAnnotation()
1313
: base("TestInitialize", AnnotationTarget.Member)

Rubberduck.Parsing/Annotations/Concrete/TestMethodAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Rubberduck.Parsing.Annotations
1010
/// <summary>
1111
/// Marks a method that the test engine will execute as a unit test.
1212
/// </summary>
13-
public sealed class TestMethodAnnotation : AnnotationBase
13+
public sealed class TestMethodAnnotation : AnnotationBase, ITestAnnotation
1414
{
1515
public TestMethodAnnotation()
1616
: base("TestMethod", AnnotationTarget.Member)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Rubberduck.Parsing.Annotations
8+
{
9+
public interface ITestAnnotation
10+
{
11+
}
12+
}

RubberduckTests/Inspections/ProcedureNotUsedInspectionTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ Private Sub abc_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
111111
Assert.AreEqual(0, InspectionResultsForModules(modules).Count(result => result.Target.DeclarationType == DeclarationType.Procedure));
112112
}
113113

114+
[TestCase("@TestMethod(\"TestCategory\")")]
115+
[TestCase("@ModuleInitialize")]
116+
[TestCase("@ModuleCleanup")]
117+
[TestCase("@TestInitialize")]
118+
[TestCase("@TestCleanup")]
119+
[Category("Inspections")]
120+
public void ProcedureNotUsed_NoResultForTestRelatedMethods(string annotationText)
121+
{
122+
string inputCode =
123+
$@"
124+
'{annotationText}
125+
Private Sub TestRelatedMethod()
126+
End Sub";
127+
128+
Assert.AreEqual(0, InspectionResultsForModules(("TestClass", inputCode, ComponentType.StandardModule)).Count());
129+
}
130+
114131
[TestCase("Class_Initialize")]
115132
[TestCase("class_initialize")]
116133
[TestCase("Class_Terminate")]

0 commit comments

Comments
 (0)