protected sealed override void Check() { var path = (string)Arguments[0]; var file = File.ReadAllText(path); var syntaxTree = SyntaxFactory.ParseSyntaxTree(file, path: path, encoding: Encoding.UTF8); var compilation = Tests.CreateCompilation(false, syntaxTree); compilation = Normalizer.ApplyNormalizers(compilation); _root = compilation.SyntaxTrees.First().GetRoot(); Output.Trace("{0}", _root.ToFullString()); CheckLines(); }
private void CheckDiagnostics <T>(string file) where T : Analyzer, new() { var analyzer = new T(); var code = ParseFile(file); var compilation = CreateCompilation(code).WithAnalyzers(ImmutableArray.Create((DiagnosticAnalyzer)analyzer)); var expectedDiagnostics = GetExpectedDiagnostics(analyzer, compilation.Compilation).ToArray(); var actualDiagnostics = compilation.GetAllDiagnosticsAsync().Result.Where(d => !d.Descriptor.Id.StartsWith("CS")).ToArray(); var commonDiagnostics = expectedDiagnostics.Intersect(actualDiagnostics, new DiagnosticComparer()); if (expectedDiagnostics.Length != actualDiagnostics.Length || expectedDiagnostics.Length != commonDiagnostics.Count()) { var builder = new StringBuilder(); builder.AppendLine(); builder.AppendLine(); builder.AppendLine("Actual Diagnostics:"); builder.AppendLine("==================="); foreach (var diagnostic in actualDiagnostics.OrderBy(d => d.Location.SourceSpan.Start)) { Write(builder, diagnostic); } builder.AppendLine("Expected Diagnostics:"); builder.AppendLine("====================="); foreach (var diagnostic in expectedDiagnostics.OrderBy(d => d.Location.SourceSpan.Start)) { Write(builder, diagnostic); } throw new TestException(builder.ToString()); } foreach (var diagnostic in actualDiagnostics) { Output.Trace("{0}\n", diagnostic); } }