Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staircase in logger #4756

Merged
merged 4 commits into from Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,7 @@ internal class HtmlTransformer : IHtmlTransformer
public HtmlTransformer()
{
_xslTransform = new XslCompiledTransform();
_xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException()));
_xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException(), new XmlReaderSettings { CheckCharacters = false }));
}

/// <summary>
Expand All @@ -33,7 +33,9 @@ public void Transform(string xmlFile, string htmlFile)
// for example &#xFFFF;. DCS will load them, but for XSL to load them here we need to pass it
// a reader that we've configured to be tolerant of such references.
using XmlReader xr = XmlReader.Create(xmlFile, new XmlReaderSettings() { CheckCharacters = false });
using XmlWriter xw = XmlWriter.Create(htmlFile, new XmlWriterSettings() { CheckCharacters = false });

// Use output settings from the xslt, especially the output method, which is HTML, which avoids outputting broken <div /> tags.
using XmlWriter xw = XmlWriter.Create(htmlFile, _xslTransform.OutputSettings);

_xslTransform.Transform(xr, xw);
}
Expand Down
Expand Up @@ -69,12 +69,21 @@ public void HtmlLoggerWithFriendlyNameContainsExpectedContent(RunnerInfo runnerI
InvokeVsTest(arguments);

var htmlLogFilePath = Path.Combine(TempDirectory.Path, htmlFileName);
XmlDocument report = new();
report.Load(htmlLogFilePath);
XmlDocument report = LoadReport(htmlLogFilePath);

AssertExpectedHtml(report.DocumentElement!);
}

private static XmlDocument LoadReport(string htmlLogFilePath)
{
// XML reader cannot handle <br> tags because they are not closed, and hence are not valid XML.
// They are correct HTML though, so we patch it here.
var text = File.ReadAllText(htmlLogFilePath).Replace("<br>", "<br/>");
var report = new XmlDocument();
report.Load(new StringReader(text));
return report;
}

[TestMethod]
[NetCoreTargetFrameworkDataSource]
public void TrxLoggerWithExecutorUriShouldProperlyOverwriteFile(RunnerInfo runnerInfo)
Expand Down