public void CorrectTestModuleAnnotation_NoResult()
        {
            const string inputCode = @"
Option Explicit
Option Private Module

'@TestModule
'@Folder(""Tests"")

Private Assert As Object
Private Fakes As Object

Public Sub Test1()
End Sub
";
            var          vbe       = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IllegalAnnotationInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.IsFalse(inspectionResults.Any());
            }
        }
Esempio n. 2
0
        public void MultipleResults()
        {
            const string inputcode =
                @"Sub Foo()
    Dim d As Boolean
    If True Then
        d = True
    Else
        d = False
    EndIf

    If True Then
        d = False
    Else
        d = True
    EndIf
End Sub";
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputcode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection = new BooleanAssignedInIfElseInspection(state);
                var inspector  = InspectionsHelper.GetInspector(inspection);
                var results    = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(2, results.Count());
            }
        }
        public void RedundantByRefModifier_ReturnsResult_InterfaceImplementation()
        {
            const string inputCode1 =
                @"Sub Foo(ByRef arg1 As Integer)
End Sub";

            const string inputCode2 =
                @"Implements IClass1

Sub IClass1_Foo(ByRef arg1 As Integer)
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputCode1)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode2)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection = new RedundantByRefModifierInspection(state)
                {
                    Severity = CodeInspectionSeverity.Hint
                };
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
        public void NoResultGivenMemberDescriptionAttribute_NoAnnotation()
        {
            const string testModuleName = "Test";
            const string inputCode      = @"
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = """ + testModuleName + @"""   ' (ignored)
Attribute VB_GlobalNameSpace = False              ' (ignored)
Attribute VB_Creatable = False                    ' (ignored)
Attribute VB_PredeclaredId = False                ' Must be False
Attribute VB_Exposed = False                      ' Must be False
Option Explicit

Sub DoSomething()
Attribute DoSomething.VB_Description = ""Does something""
End Sub
";

            var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, testModuleName, ComponentType.ClassModule, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new MissingAttributeInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.IsFalse(inspectionResults.Any());
            }
        }
        public void HasResultGivenPredeclaredIdAnnotation_WithoutAttribute()
        {
            const string testModuleName = "Test";
            const string inputCode      = @"
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = """ + testModuleName + @"""   ' (ignored)
Attribute VB_GlobalNameSpace = False              ' (ignored)
Attribute VB_Creatable = False                    ' (ignored)
Attribute VB_PredeclaredId = False                ' Must be False
Attribute VB_Exposed = False                      ' Must be False
Option Explicit
'@PredeclaredId
";

            var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, testModuleName, ComponentType.ClassModule, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new MissingAttributeInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Esempio n. 6
0
        public void ProcedureShouldBeFunction_DoesNotReturnResult_EventImplementation()
        {
            //Input
            const string inputCode1 =
                @"Public Event Foo(ByRef arg1 As Integer)";
            const string inputCode2 =
                @"Private WithEvents abc As Class1

Private Sub abc_Foo(ByRef arg1 As Integer)
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode1)
                          .AddComponent("Class2", ComponentType.ClassModule, inputCode2)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new ProcedureCanBeWrittenAsFunctionInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(0, inspectionResults.Count());
            }
        }
        public void GivenOneIlegalModuleAnnotationAcrossModules_OneResult()
        {
            const string inputCode1 = @"
Option Explicit
'@Folder(""Legal"")

Sub DoSomething()
'@Folder(""Illegal"")
End Sub
";
            const string inputCode2 = @"
Option Explicit
'@Folder(""Legal"")
";
            var          vbe        = MockVbeBuilder.BuildFromStdModules(("Module1", inputCode1), ("Module2", inputCode2));

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IllegalAnnotationInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Esempio n. 8
0
        public void StopKeywords_Ignored_ReturnsCorrectResults()
        {
            var inputCode =
                @"Sub Foo()
    Dim d As Integer
    d = 0
    Stop

    d = 1

    '@Ignore StopKeyword
    Stop
End Sub";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new StopKeywordInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
                Assert.AreEqual(4, inspectionResults.First().QualifiedSelection.Selection.StartLine);
            }
        }
        private void CheckActualEmptyBlockCountEqualsExpected(string inputCode, int expectedCount)
        {
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection    = new EmptyCaseBlockInspection(state);
            var inspector     = InspectionsHelper.GetInspector(inspection);
            var actualResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(expectedCount, actualResults.Count());
        }
        private IEnumerable <IInspectionResult> GetInspectionResults(string code, bool includeLibraries = false)
        {
            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(code, out _, referenceStdLibs: includeLibraries);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection = new AssignmentNotUsedInspection(state, new Walker());
                var inspector  = InspectionsHelper.GetInspector(inspection);
                return(inspector.FindIssuesAsync(state, CancellationToken.None).Result);
            }
        }
        public void ObsoleteCommentSyntax_DoesNotReturnResult_QuoteComment()
        {
            const string inputCode = @"' test";
            var          vbe       = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var          state     = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ObsoleteCommentSyntaxInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void ModuleScopeDimKeyword_ReturnsResult()
        {
            const string inputCode =
                @"Dim foo As String";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ModuleScopeDimKeywordInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(1, inspectionResults.Count());
        }
        public void ModuleScopeDimKeyword_DoesNotReturnResult()
        {
            const string inputCode =
                @"Private foo";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ModuleScopeDimKeywordInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.IsFalse(inspectionResults.Any());
        }
Esempio n. 14
0
        public void OptionBaseOneStatement_NoResult()
        {
            var inputCode = "Option Base 1";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new RedundantOptionInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.IsFalse(inspectionResults.Any());
        }
Esempio n. 15
0
        public void OptionBaseZeroSpecified_DoesNotReturnResult()
        {
            const string inputCode = @"Option Base 0";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new OptionBaseInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void ImplicitByRefModifier_ReturnsResult_SomePassedByRefImplicitly()
        {
            const string inputCode =
                @"Sub Foo(arg1 As Integer, ByRef arg2 As Date)
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ImplicitByRefModifierInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(1, inspectionResults.Count());
        }
        public void MalformedAnnotation_DoesNotReturnResult_Ignore()
        {
            const string inputCode =
                @"'@Ignore ProcedureNotUsedInspection";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new MissingAnnotationArgumentInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
Esempio n. 18
0
        public void MultilineParameter_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo(ByVal Var1 As Integer)
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new MultilineParameterInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
Esempio n. 19
0
        private void TestStepNotSpecifiedInspection(string inputCode, int expectedResultCount)
        {
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection = new StepIsNotSpecifiedInspection(state)
            {
                Severity = CodeInspectionSeverity.Warning
            };
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(expectedResultCount, inspectionResults.Count());
        }
        public void GivenTestModule_NoResult()
        {
            const string inputCode = @"
Option Explicit

Option Private Module

'@TestModule
'@Folder(""Tests"")

Private Assert As Object
Private Fakes As Object

'@ModuleInitialize
Public Sub ModuleInitialize()
    'this method runs once per module.
    Set Assert = CreateObject(""Rubberduck.AssertClass"")
    Set Fakes = CreateObject(""Rubberduck.FakesProvider"")
End Sub

'@ModuleCleanup
Public Sub ModuleCleanup()
    'this method runs once per module.
    Set Assert = Nothing
    Set Fakes = Nothing
End Sub

'@TestInitialize
Public Sub TestInitialize()
    'this method runs before every test in the module.
End Sub

'@TestCleanup
Public Sub TestCleanup()
    'this method runs after every test in the module.
End Sub
";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new IllegalAnnotationInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.IsFalse(inspectionResults.Any());
            }
        }
        public void ObsoleteErrorSyntax_ReturnsResult()
        {
            const string inputCode =
                @"Sub Foo()
    Error 91
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ObsoleteErrorSyntaxInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 22
0
        public void NotEmptyStringLiteral_DoesNotReturnResult()
        {
            const string inputCode =
                @"Public Sub Foo(ByRef arg1 As String)
    arg1 = ""test""
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new EmptyStringLiteralInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void NoStopKeyword_NoResult()
        {
            var inputCode =
                @"Sub Foo()
End Sub";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new StopKeywordInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.IsFalse(inspectionResults.Any());
        }
Esempio n. 24
0
        public void OptionBaseZeroStatement_Ignored_DoesNotReturnResult()
        {
            var inputCode =
                @"'@Ignore OptionBaseZero
Option Base 0";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ObsoleteCallStatementInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.IsFalse(inspectionResults.Any());
        }
        public void ModuleScopeDimKeyword_IgnoreModule_OtherAnnotationName_YieldsResults()
        {
            const string inputCode =
                @"'@IgnoreModule VariableNotUsed

Dim foo";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ModuleScopeDimKeywordInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.IsTrue(inspectionResults.Any());
        }
        public void ImplicitByRefModifier_Ignored_DoesNotReturnResult()
        {
            const string inputCode =
                @"'@Ignore ImplicitByRefModifier
Sub Foo(arg1 As Integer)
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ImplicitByRefModifierInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.IsFalse(inspectionResults.Any());
        }
        public void MultipleDeclarations_ReturnsResult_StaticVariables()
        {
            const string inputCode =
                @"Public Sub Foo()
    Static var1 As Integer, var2 As String
End Sub";
            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new MultipleDeclarationsInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(1, inspectionResults.Count());
        }
Esempio n. 28
0
        public void ProcedureShouldBeFunction_DoesNotReturnsResult_MultipleByValParams()
        {
            const string inputCode =
                @"Private Sub Foo(ByVal foo As Integer, ByVal goo As Integer)
End Sub";

            var vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
            var state = MockParser.CreateAndParse(vbe.Object);

            var inspection        = new ProcedureCanBeWrittenAsFunctionInspection(state);
            var inspector         = InspectionsHelper.GetInspector(inspection);
            var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

            Assert.AreEqual(0, inspectionResults.Count());
        }
        public void NotAlreadySpecified_ReturnsResult()
        {
            const string inputCode = @"";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new OptionExplicitInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
Esempio n. 30
0
        public void MalformedAnnotation_ReturnsResult_Folder()
        {
            const string inputCode =
                @"'@Folder";

            var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new MissingAnnotationArgumentInspection(state);
                var inspector         = InspectionsHelper.GetInspector(inspection);
                var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }