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

Illegal xml char #46

Merged
merged 9 commits into from
Jul 5, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<MSTestVersion>1.3.2</MSTestVersion>
<NETTestSdkVersion>15.7.2</NETTestSdkVersion>
<MoqVersion>4.9.0</MoqVersion>
<TestLoggerVersion>3.0.86</TestLoggerVersion>
<TestLoggerVersion>3.0.122</TestLoggerVersion>

<!-- Test Assets use the minimum supported versions -->
<NETTestSdkMinimumVersion>15.5.0</NETTestSdkMinimumVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
<PackageReference Include="Spekt.TestLogger" Version="$(TestLoggerVersion)" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
</ItemGroup>

</Project>
24 changes: 13 additions & 11 deletions src/Xunit.Xml.TestLogger/XunitXmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class XunitXmlSerializer : ITestResultSerializer
{ "Test Method Cleanup Failure", "test-method-cleanup" }
};

public IInputSanitizer InputSanitizer { get; } = new InputSanitizerXml();

public string Serialize(
LoggerConfiguration loggerConfiguration,
TestRunConfiguration runConfiguration,
Expand Down Expand Up @@ -167,8 +169,8 @@ private static XElement CreateErrorElement(TestResultInfo result)
private static XElement CreateFailureElement(string exceptionType, string message, string stackTrace)
{
XElement failureElement = new XElement("failure", new XAttribute("exception-type", exceptionType));
failureElement.Add(new XElement("message", message.ReplaceInvalidXmlChar()));
failureElement.Add(new XElement("stack-trace", stackTrace.ReplaceInvalidXmlChar()));
failureElement.Add(new XElement("message", message));
failureElement.Add(new XElement("stack-trace", stackTrace));

return failureElement;
}
Expand Down Expand Up @@ -249,7 +251,7 @@ private static XElement CreateTestElement(TestResultInfo result)
{
var element = new XElement(
"test",
new XAttribute("name", result.TestCase.DisplayName.ReplaceInvalidXmlChar()),
new XAttribute("name", result.DisplayName),
new XAttribute("type", result.FullTypeName),
new XAttribute("method", result.Method),
new XAttribute("time", result.Duration.TotalSeconds.ToString("F7", CultureInfo.InvariantCulture)),
Expand All @@ -265,33 +267,33 @@ private static XElement CreateTestElement(TestResultInfo result)
else if (m.Category == "skipReason")
{
// Using the self-defined category skipReason for now
element.Add(new XElement("reason", new XCData(m.Text.ReplaceInvalidXmlChar())));
element.Add(new XElement("reason", new XCData(m.Text)));
}
}

if (!string.IsNullOrWhiteSpace(stdOut.ToString()))
{
element.Add(new XElement("output", stdOut.ToString().ReplaceInvalidXmlChar()));
element.Add(new XElement("output", stdOut.ToString()));
}

var fileName = result.TestCase.CodeFilePath;
var fileName = result.CodeFilePath;
if (!string.IsNullOrWhiteSpace(fileName))
{
element.Add(new XElement("source-file", fileName));
element.Add(new XElement("source-line", result.TestCase.LineNumber));
element.Add(new XElement("source-line", result.LineNumber));
}

if (result.Outcome == TestOutcome.Failed)
{
element.Add(new XElement(
"failure",
new XElement("message", result.ErrorMessage.ReplaceInvalidXmlChar()),
new XElement("stack-trace", result.ErrorStackTrace.ReplaceInvalidXmlChar())));
new XElement("message", result.ErrorMessage),
new XElement("stack-trace", result.ErrorStackTrace)));
}

if (result.TestCase.Traits != null)
if (result.Traits != null)
{
var traits = from trait in result.TestCase.Traits
var traits = from trait in result.Traits
select new XElement("trait", new XAttribute("name", trait.Name), new XAttribute("value", trait.Value));
element.Add(new XElement("traits", traits));
}
Expand Down