Support test for XML documentation errors

- can't be done as a unit test because `k.cmd test` doesn't write assemblies for referenced projects
- instead support extending the "test" target in builds

To enable this in a repo, add the following to the makefile.shade file:
```
#xml-docs-test target='test'
  k-xml-docs-test
```

Example output with one syntax error and one invalid reference:
```
info: Target xml-docs-test
warn: Invalid documentation syntax in src\Microsoft.AspNet.Mvc.Core\bin\debug\net45\Microsoft.AspNet.Mvc.Core.xml
warn:  3170: <!-- Badly formed XML comment ignored for member "T:Microsoft.AspNet.Mvc.Rendering.HtmlHelper" -->
warn:  3203: If the object is already an <see cref="!:IDictionaries&lt;string, object&gt;"/> instance, then it is
```
This commit is contained in:
dougbu 2014-08-11 11:25:14 -07:00
parent c3daa5c8c0
commit 6f7e62201b
1 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,48 @@
use namespace="System"
use namespace="System.Collections.Generic"
use namespace="System.IO"
use import="Files"
default BASE_DIR='${Directory.GetCurrentDirectory()}'
@{
var srcDir = Path.Combine(BASE_DIR, "src");
foreach (var xmlFilePath in Files.Include(Path.Combine(srcDir, "**/*.xml")))
{
var errors = 0;
var xmlLines = File.ReadAllLines(xmlFilePath);
for (var linesIndex = 0; linesIndex < xmlLines.Length; ++linesIndex)
{
var xmlLine = xmlLines[linesIndex].Trim();
if (xmlLine.StartsWith("<!--"))
{
// Compiler only emits comments for syntax errors.
if (errors == 0)
{
Log.Warn(string.Format("Invalid documentation syntax in {0}:", xmlFilePath));
}
++errors;
Log.Warn(string.Format(" {0}: {1}", linesIndex + 1, xmlLine));
}
else if (xmlLine.Contains("\"!:"))
{
// '!' is reference string error token.
if (errors == 0)
{
Log.Warn(string.Format("Invalid documentation syntax in {0}:", xmlFilePath));
}
++errors;
Log.Warn(string.Format(" {0}: {1}", linesIndex + 1, xmlLine));
}
}
if (errors != 0)
{
Environment.Exit(errors);
return;
}
}
}