Skip to content

Commit

Permalink
ProcedureNotUsedInspection ignores declarations that have ITestAnnota…
Browse files Browse the repository at this point in the history
…tion annotations.
  • Loading branch information
beachasaurus-rex committed Jan 28, 2020
1 parent 0c4bb18 commit 8781f56
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
Expand Up @@ -6,6 +6,7 @@
using Rubberduck.JunkDrawer.Extensions;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Resources.Inspections;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;

Expand Down Expand Up @@ -99,7 +100,8 @@ private bool IsIgnoredDeclaration(Declaration declaration, IEnumerable<Declarati
|| IsPublicModuleMember(modules, declaration)
|| IsClassLifeCycleHandler(enumerable, declaration)
|| interfaceMembers.Contains(declaration)
|| interfaceImplementingMembers.Contains(declaration);
|| interfaceImplementingMembers.Contains(declaration)
|| declaration.Annotations.Any(x => x.Annotation is ITestAnnotation);

return result;
}
Expand Down
Expand Up @@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
/// <summary>
/// Marks a method that the test engine will execute after all unit tests in a test module have executed.
/// </summary>
public sealed class ModuleCleanupAnnotation : AnnotationBase
public sealed class ModuleCleanupAnnotation : AnnotationBase, ITestAnnotation
{
public ModuleCleanupAnnotation()
: base("ModuleCleanup", AnnotationTarget.Member)
Expand Down
Expand Up @@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
/// <summary>
/// Marks a method that the test engine will execute before executing the first unit test in a test module.
/// </summary>
public sealed class ModuleInitializeAnnotation : AnnotationBase
public sealed class ModuleInitializeAnnotation : AnnotationBase, ITestAnnotation
{
public ModuleInitializeAnnotation()
: base("ModuleInitialize", AnnotationTarget.Member)
Expand Down
Expand Up @@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
/// <summary>
/// Marks a method that the test engine will execute after executing each unit test in a test module.
/// </summary>
public sealed class TestCleanupAnnotation : AnnotationBase
public sealed class TestCleanupAnnotation : AnnotationBase, ITestAnnotation
{
public TestCleanupAnnotation()
: base("TestCleanup", AnnotationTarget.Member)
Expand Down
Expand Up @@ -7,7 +7,7 @@ namespace Rubberduck.Parsing.Annotations
/// <summary>
/// Marks a method that the test engine will execute before executing each unit test in a test module.
/// </summary>
public sealed class TestInitializeAnnotation : AnnotationBase
public sealed class TestInitializeAnnotation : AnnotationBase, ITestAnnotation
{
public TestInitializeAnnotation()
: base("TestInitialize", AnnotationTarget.Member)
Expand Down
Expand Up @@ -10,7 +10,7 @@ namespace Rubberduck.Parsing.Annotations
/// <summary>
/// Marks a method that the test engine will execute as a unit test.
/// </summary>
public sealed class TestMethodAnnotation : AnnotationBase
public sealed class TestMethodAnnotation : AnnotationBase, ITestAnnotation
{
public TestMethodAnnotation()
: base("TestMethod", AnnotationTarget.Member)
Expand Down
12 changes: 12 additions & 0 deletions Rubberduck.Parsing/Annotations/ITestAnnotation.cs
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rubberduck.Parsing.Annotations
{
public interface ITestAnnotation
{
}
}
17 changes: 17 additions & 0 deletions RubberduckTests/Inspections/ProcedureNotUsedInspectionTests.cs
Expand Up @@ -111,6 +111,23 @@ public void ProcedureNotUsed_HandlerIsIgnoredForUnraisedEvent()
Assert.AreEqual(0, InspectionResultsForModules(modules).Count(result => result.Target.DeclarationType == DeclarationType.Procedure));
}

[TestCase("@TestMethod(\"TestCategory\")")]
[TestCase("@ModuleInitialize")]
[TestCase("@ModuleCleanup")]
[TestCase("@TestInitialize")]
[TestCase("@TestCleanup")]
[Category("Inspections")]
public void ProcedureNotUsed_NoResultForTestRelatedMethods(string annotationText)
{
string inputCode =
$@"
'{annotationText}
Private Sub TestRelatedMethod()
End Sub";

Assert.AreEqual(0, InspectionResultsForModules(("TestClass", inputCode, ComponentType.StandardModule)).Count());
}

[TestCase("Class_Initialize")]
[TestCase("class_initialize")]
[TestCase("Class_Terminate")]
Expand Down

0 comments on commit 8781f56

Please sign in to comment.