-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Xml serializer test updates prep for reflection work #104173
Conversation
@@ -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)) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.Internal.cs
Outdated
Show resolved
Hide resolved
...System.Runtime.Serialization.Schema/tests/System/Runtime/Serialization/Schema/SchemaUtils.cs
Outdated
Show resolved
Hide resolved
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) })); |
There was a problem hiding this comment.
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
.
Shoring up XmlSerializer/Schema tests in preparation for future serializer work.