public void GetErrorsAndWarnings()
{
string text = @"class Program
{
static int Main(string[] args)
{
}
}";
SyntaxTree tree = SyntaxTree.ParseText(text);
Compilation compilation = Compilation
.Create("program.exe")
.AddSyntaxTrees(tree)
.AddReferences(new MetadataFileReference(typeof(object).Assembly.Location));
IEnumerable<Diagnostic> errorsAndWarnings = compilation.GetDiagnostics();
Assert.AreEqual(1, errorsAndWarnings.Count());
Diagnostic error = errorsAndWarnings.First();
Assert.AreEqual(
"'Program.Main(string[])': not all code paths return a value",
error.Info.GetMessage(CultureInfo.InvariantCulture));
Location errorLocation = error.Location;
Assert.AreEqual(4, error.Location.SourceSpan.Length);
IText programText = errorLocation.SourceTree.GetText();
Assert.AreEqual("Main", programText.ToString(errorLocation.SourceSpan));
FileLinePositionSpan span = error.Location.GetLineSpan(usePreprocessorDirectives: true);
Assert.AreEqual(15, span.StartLinePosition.Character);
Assert.AreEqual(2, span.StartLinePosition.Line);
}