private void Verify(string fileName,
                            ProjectType projectType,
                            Action <IReadOnlyList <SymbolReferenceInfo.Types.SymbolReference> > verifyReference,
                            bool isMessageExpected = true)
        {
            var testRoot = Root + TestContext.TestName;
            UtilityAnalyzerBase analyzer = fileName.EndsWith(".cs")
                ? new TestSymbolReferenceAnalyzer_CS(testRoot, projectType == ProjectType.Test)
                : new TestSymbolReferenceAnalyzer_VB(testRoot, projectType == ProjectType.Test);

            Verifier.VerifyUtilityAnalyzer <SymbolReferenceInfo>(
                new[] { Root + fileName },
                analyzer,
                @$ "{testRoot}\symrefs.pb",
                TestHelper.CreateSonarProjectConfig(testRoot, projectType),
                messages =>
            {
                messages.Should().HaveCount(isMessageExpected ? 1 : 0);

                if (isMessageExpected)
                {
                    var info = messages.Single();
                    info.FilePath.Should().Be(fileName);
                    verifyReference(info.Reference);
                }
            });
        }
Example #2
0
 public static void VerifyUtilityAnalyzer<TMessage>(IEnumerable<string> paths,
                                                    UtilityAnalyzerBase diagnosticAnalyzer,
                                                    string protobufPath,
                                                    Action<IReadOnlyList<TMessage>> verifyProtobuf,
                                                    IEnumerable<ParseOptions> options = null)
     where TMessage : IMessage<TMessage>, new()
 {
     var solutionBuilder = SolutionBuilder.CreateSolutionFromPaths(paths);
     foreach (var compilation in solutionBuilder.Compile(options?.ToArray()))
     {
         DiagnosticVerifier.Verify(compilation, diagnosticAnalyzer, CompilationErrorBehavior.Default);
         verifyProtobuf(ReadProtobuf(protobufPath).ToList());
     }
Example #3
0
        public void GetTextRange()
        {
            var fileLinePositionSpan = new FileLinePositionSpan(
                "path",
                new LinePosition(55, 42),
                new LinePosition(99, 9313));

            // Act
            var result = UtilityAnalyzerBase.GetTextRange(fileLinePositionSpan);

            // Assert
            result.Should().NotBeNull();
            // line number in SQ starts from 1, Roslyn starts from 0
            result.StartLine.Should().Be(55 + 1);
            result.StartOffset.Should().Be(42);
            result.EndLine.Should().Be(99 + 1);
            result.EndOffset.Should().Be(9313);
        }
        public void Verify(string fileName, Action <IReadOnlyList <SymbolReferenceInfo.Types.SymbolReference> > verifyReference)
        {
            var testRoot = Root + TestContext.TestName;
            UtilityAnalyzerBase analyzer = fileName.EndsWith(".cs")
                ? new TestSymbolReferenceAnalyzer_CS(testRoot)
                : new TestSymbolReferenceAnalyzer_VB(testRoot);

            Verifier.VerifyUtilityAnalyzer <SymbolReferenceInfo>(
                new[] { Root + fileName },
                analyzer,
                @$ "{testRoot}\symrefs.pb",
                messages =>
            {
                messages.Should().HaveCount(1);
                var info = messages.Single();
                info.FilePath.Should().Be(fileName);
                verifyReference(info.Reference);
            });
        }
Example #5
0
        public static void VerifyUtilityAnalyzer <TMessage>(IEnumerable <string> paths, UtilityAnalyzerBase diagnosticAnalyzer,
                                                            string protobufPath, Action <IList <TMessage> > verifyProtobuf, CompilationErrorBehavior checkMode = CompilationErrorBehavior.Default)
            where TMessage : IMessage <TMessage>, new()
        {
            var solutionBuilder = SolutionBuilder.CreateSolutionFromPaths(paths);

            foreach (var compilation in solutionBuilder.Compile())
            {
                DiagnosticVerifier.Verify(compilation, diagnosticAnalyzer, checkMode);

                verifyProtobuf(ReadProtobuf(protobufPath).ToList());
            }

            IEnumerable <TMessage> ReadProtobuf(string path)
            {
                using (var input = File.OpenRead(path))
                {
                    var parser = new MessageParser <TMessage>(() => new TMessage());
                    while (input.Position < input.Length)
                    {
                        yield return(parser.ParseDelimitedFrom(input));
                    }
                }
            }
        }
Example #6
0
 public static void VerifyUtilityAnalyzer <TMessage>(IEnumerable <string> paths, UtilityAnalyzerBase diagnosticAnalyzer,
                                                     string protobufPath, Action <IList <TMessage> > verifyProtobuf)
     where TMessage : IMessage <TMessage>, new()
 {
     VerifyAnalyzer(paths, diagnosticAnalyzer, (analyzer, compilation) =>
     {
         verifyProtobuf(ReadProtobuf <TMessage>(protobufPath).ToList());
     });
 }