Skip to content

Commit 2850ac5

Browse files
authored
Fix staircase in logger (#4756)
1 parent 56d1d0b commit 2850ac5

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class HtmlTransformer : IHtmlTransformer
2020
public HtmlTransformer()
2121
{
2222
_xslTransform = new XslCompiledTransform();
23-
_xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException()));
23+
_xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException(), new XmlReaderSettings { CheckCharacters = false }));
2424
}
2525

2626
/// <summary>
@@ -33,7 +33,9 @@ public void Transform(string xmlFile, string htmlFile)
3333
// for example &#xFFFF;. DCS will load them, but for XSL to load them here we need to pass it
3434
// a reader that we've configured to be tolerant of such references.
3535
using XmlReader xr = XmlReader.Create(xmlFile, new XmlReaderSettings() { CheckCharacters = false });
36-
using XmlWriter xw = XmlWriter.Create(htmlFile, new XmlWriterSettings() { CheckCharacters = false });
36+
37+
// Use output settings from the xslt, especially the output method, which is HTML, which avoids outputting broken <div /> tags.
38+
using XmlWriter xw = XmlWriter.Create(htmlFile, _xslTransform.OutputSettings);
3739

3840
_xslTransform.Transform(xr, xw);
3941
}

test/Microsoft.TestPlatform.Acceptance.IntegrationTests/LoggerTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,21 @@ public void HtmlLoggerWithFriendlyNameContainsExpectedContent(RunnerInfo runnerI
6969
InvokeVsTest(arguments);
7070

7171
var htmlLogFilePath = Path.Combine(TempDirectory.Path, htmlFileName);
72-
XmlDocument report = new();
73-
report.Load(htmlLogFilePath);
72+
XmlDocument report = LoadReport(htmlLogFilePath);
7473

7574
AssertExpectedHtml(report.DocumentElement!);
7675
}
7776

77+
private static XmlDocument LoadReport(string htmlLogFilePath)
78+
{
79+
// XML reader cannot handle <br> tags because they are not closed, and hence are not valid XML.
80+
// They are correct HTML though, so we patch it here.
81+
var text = File.ReadAllText(htmlLogFilePath).Replace("<br>", "<br/>");
82+
var report = new XmlDocument();
83+
report.Load(new StringReader(text));
84+
return report;
85+
}
86+
7887
[TestMethod]
7988
[NetCoreTargetFrameworkDataSource]
8089
public void TrxLoggerWithExecutorUriShouldProperlyOverwriteFile(RunnerInfo runnerInfo)

0 commit comments

Comments
 (0)