예제 #1
0
        public void DiagnosticRunnerTest_NoAnalyzer()
        {
            var runner = new DiagnosticsRunner(ImmutableArray.Create <DiagnosticAnalyzer>());

            var solution = CompilationHelper.GetSolutionFromText("");

            var compilation = solution.Projects.First().GetCompilationAsync().Result;

            var diagnosticsResult = runner.GetDiagnostics(compilation);

            diagnosticsResult.Should().HaveCount(0);
        }
        public void DiagnosticRunnerTest_NoAnalyzer_VbNet()
        {
            var tempInputFilePath = Path.Combine(TestContext.DeploymentDirectory, ParameterLoader.ParameterConfigurationFileName);

            File.Copy("TestResources\\ConfigurationTest.Empty.VbNet.xml", tempInputFilePath, true);

            var runner = new DiagnosticsRunner(new Configuration(tempInputFilePath, Common.AnalyzerLanguage.VisualBasic));

            var solution = CompilationHelper.GetSolutionWithEmptyFile(Common.AnalyzerLanguage.VisualBasic);

            var compilation = solution.Projects.First().GetCompilationAsync().Result;

            var diagnosticsResult = runner.GetDiagnostics(compilation);

            diagnosticsResult.Should().HaveCount(0);
        }
예제 #3
0
        public static void Verify(string path, IDiagnosticAnalyzer diagnosticAnalyzer)
        {
            var runner = new DiagnosticsRunner(ImmutableArray.Create(diagnosticAnalyzer));

            SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(File.ReadAllText(path, Encoding.UTF8));

            List <int> expected = new List <int>(ExpectedIssues(syntaxTree));

            foreach (var diagnostic in runner.GetDiagnostics(syntaxTree))
            {
                if (diagnostic.Id == diagnosticAnalyzer.SupportedDiagnostics.Single().Id)
                {
                    int line = diagnostic.Location.GetLineSpan().StartLinePosition.Line + 1;
                    expected.Should().Contain(line);
                    expected.Remove(line);
                }
            }

            expected.Should().BeEquivalentTo(Enumerable.Empty <int>());
        }
        public static void Verify(Solution solution, DiagnosticAnalyzer diagnosticAnalyzer)
        {
            var runner = new DiagnosticsRunner(ImmutableArray.Create(diagnosticAnalyzer));

            var compilation = solution.Projects.First().GetCompilationAsync().Result;
            var syntaxTree  = compilation.SyntaxTrees.First();

            var expected = new List <int>(ExpectedIssues(syntaxTree));

            foreach (var diagnostic in runner.GetDiagnostics(compilation))
            {
                if (diagnostic.Id != diagnosticAnalyzer.SupportedDiagnostics.Single().Id)
                {
                    continue;
                }

                var line = diagnostic.GetLineNumberToReport();
                expected.Should().Contain(line);
                expected.Remove(line);
            }

            expected.Should().BeEquivalentTo(Enumerable.Empty <int>());
        }