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

Xml serializer test updates prep for reflection work #104173

Conversation

StephenMolloy
Copy link
Member

Shoring up XmlSerializer/Schema tests in preparation for future serializer work.

@@ -149,7 +149,7 @@ private static bool CompareXElements(XElement baselineXElement, XElement actualX
{
// Check whether the XName is the same, this can be done by comparing the two XNames.

if (!baselineXElement.Name.Equals(actualXElement.Name))
if ((baselineXElement == null && actualXElement != null) || !baselineXElement.Name.Equals(actualXElement.Name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you trying to protect against nulls being passed in? If so, this can still throw NRE. If you pass in null for both, the first expression of the OR will be false, and then actualXElement.Name will throw NRE.

@@ -257,6 +257,11 @@ private static bool CompareXElements(XElement baselineXElement, XElement actualX
// Check if they both have the same namespace.
XNamespace deskns = baselineXElement.GetNamespaceOfPrefix(deskPrefix);
XNamespace coreclrns = actualXElement.GetNamespaceOfPrefix(coreCLRPrefix);
if ((deskns == null) || (coreclrns == null))
{
Debug.WriteLine("Either expected {0} or actual {1} attribute value doesn't have namespace :", deskAtrs[i].Value, coreCLRAtrs[i].Value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that they might both not have a namespace. Is this a scenario we care about differentiating in the debug output?

@StephenMolloy StephenMolloy merged commit 3d8b9dd into dotnet:main Aug 22, 2024
84 checks passed
var dClass = new XmlSerializableDerivedClass() { AttributeString = "derivedIXmlSerTest", DateTimeValue = DateTime.Parse("Dec 31, 1999"), BoolValue = true };

var expectedXml = WithXmlHeader(@$"<BaseIXmlSerializable xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:type=""DerivedIXmlSerializable"" AttributeString=""derivedIXmlSerTest"" DateTimeValue=""12/31/1999 12:00:00 AM"" BoolValue=""True"" xmlns=""{XmlSerializableBaseClass.XmlNamespace}"" />");
var fromBase = SerializeAndDeserialize(dClass, expectedXml, () => new XmlSerializer(typeof(XmlSerializableBaseClass), new Type[] { typeof(XmlSerializableDerivedClass) }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing on Alpine Linux:

/root/helix/work/workitem/e /root/helix/work/workitem/e
  Discovering: System.Private.Xml.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Private.Xml.Tests (found 4735 of 4792 test cases)
  Starting:    System.Private.Xml.Tests (parallel test collections = on [2 threads], stop on fail = off)
    XmlSerializerTests.Xml_DerivedIXmlSerializable [FAIL]
      XML comparison is also failing
      Test failed for input: XmlSerializableDerivedClass
      Expected: <?xml version="1.0" encoding="utf-8"?>
      <BaseIXmlSerializable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DerivedIXmlSerializable" AttributeString="derivedIXmlSerTest" DateTimeValue="12/31/1999 12:00:00 AM" BoolValue="True" xmlns="http://example.com/serializer-test-namespace" />
      Actual: <?xml version="1.0" encoding="utf-8"?>
      <BaseIXmlSerializable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DerivedIXmlSerializable" AttributeString="derivedIXmlSerTest" DateTimeValue="12/31/1999 12:00:00 AM" BoolValue="True" xmlns="http://example.com/serializer-test-namespace" />
      Stack Trace:
        /_/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs(2336,0): at XmlSerializerTests.SerializeAndDeserialize[T](T value, String baseline, Func`1 serializerFactory, Boolean skipStringCompare, XmlSerializerNamespaces xns)
        /_/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.Internal.cs(42,0): at XmlSerializerTests.Xml_DerivedIXmlSerializable()
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
        /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(57,0): at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Finished:    System.Private.Xml.Tests

In the actual value 12:00:00 AM, it is getting E2 80 AF character before AM, instead of regular space 20.

https://helixre8s23ayyeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-80154-merge-8c0184342ee64857b4/System.Private.Xml.Tests/1/console.67912d47.log?helixlogtype=result

@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants