public void ParseAndValidate(string text, CSharpParseOptions options, ErrorDescription[] errors = null) { var parsedTree = ParseTree(text, options); var parsedText = parsedTree.GetCompilationUnitRoot(); // we validate the text roundtrips Assert.Equal(text, parsedText.ToFullString()); // get all errors var actualErrors = parsedTree.GetDiagnostics(parsedText); if (errors == null || errors.Length == 0) { Assert.Empty(actualErrors); } else { DiagnosticsUtils.VerifyErrorCodes(actualErrors, errors); } }
private static CSharpCompilation CompileAndVerifyDiagnostics(string text1, string text2, ErrorDescription[] expectedErrors1, ErrorDescription[] expectedErrors2) { var comp1 = CompileAndVerifyDiagnostics(text1, expectedErrors1); var comp2 = CompileAndVerifyDiagnostics(text2, expectedErrors2, comp1); return comp2; }
private static CSharpCompilation CompileAndVerifyDiagnostics(string text, ErrorDescription[] expectedErrors, params CSharpCompilation[] baseCompilations) { var refs = new List<MetadataReference>(baseCompilations.Select(c => new CSharpCompilationReference(c))); var comp = CreateCompilationWithMscorlib(text, refs); var actualErrors = comp.GetDiagnostics(); //ostensibly, we could just pass exactMatch: true to VerifyErrorCodes, but that method is short-circuited when 0 errors are expected Assert.Equal(expectedErrors.Length, actualErrors.Count()); DiagnosticsUtils.VerifyErrorCodes(actualErrors, expectedErrors); return comp; }