[System.Runtime.Serialization.Formatters.Soap] Make test output deterministic
[mono.git] / mcs / tools / corcompare / mono-api-html / MemberComparer.cs
index a3a0e57d8c9490aa189890c621c24c29d902a826..d12d86625c2ea7a0af1b5d4bbb8067bd32ed04e1 100644 (file)
@@ -41,6 +41,11 @@ namespace Xamarin.ApiDiff {
                public abstract string GroupName { get; }
                public abstract string ElementName { get; }
 
+               protected virtual bool IsBreakingRemoval (XElement e)
+               {
+                       return true;
+               }
+
                public void Compare (XElement source, XElement target)
                {
                        var s = source.Element (GroupName);
@@ -61,6 +66,16 @@ namespace Xamarin.ApiDiff {
                {
                }
 
+               string GetContainingType (XElement el)
+               {
+                       return el.Ancestors ("class").First ().Attribute ("type").Value;
+               }
+
+               bool IsInInterface (XElement el)
+               {
+                       return GetContainingType (el) == "interface";
+               }
+
                public XElement Source { get; set; }
 
                public virtual bool Find (XElement e)
@@ -114,7 +129,7 @@ namespace Xamarin.ApiDiff {
                                        BeforeAdding (elements);
                                        a = true;
                                }
-                               Added (item);
+                               Added (item, false);
                        }
                        if (a)
                                AfterAdding ();
@@ -126,8 +141,10 @@ namespace Xamarin.ApiDiff {
                                Output.WriteLine ("<p>{0}:</p>", changes.Key);
                                Output.WriteLine ("<pre>");
                                foreach (var element in changes.Value) {
+                                       Output.Write ("<div {0}>", element.Breaking ? "data-is-breaking" : "data-is-non-breaking");
                                        foreach (var line in element.Member.ToString ().Split ('\n'))
                                                Output.WriteLine ("\t{0}", line);
+                                       Output.Write ("</div>");
 
                                }
                                Output.WriteLine ("</pre>");
@@ -182,25 +199,28 @@ namespace Xamarin.ApiDiff {
                public virtual void BeforeAdding (IEnumerable<XElement> list)
                {
                        first = true;
-                       Output.WriteLine ("<p>Added {0}:</p><pre>", list.Count () > 1 ? GroupName : ElementName);
-                       if (State.Colorize)
-                               Output.Write ("<font color='green'>");
+                       Output.WriteLine ("<div>");
+                       Output.WriteLine ("<p>Added {0}:</p>", list.Count () > 1 ? GroupName : ElementName);
+                       Output.WriteLine ("<pre>");
                }
 
-               public override void Added (XElement target)
+               public override void Added (XElement target, bool wasParentAdded)
                {
                        var o = GetObsoleteMessage (target);
                        if (!first && (o.Length > 0))
                                Output.WriteLine ();
-                       Indent ().WriteLine ("\t{0}{1}", o, GetDescription (target));
+                       Indent ();
+                       bool isInterfaceBreakingChange = !wasParentAdded && IsInInterface (target);
+                       Output.Write ("\t<span class='added added-{0} {1}' {2}>", ElementName, isInterfaceBreakingChange ? "breaking" : string.Empty, isInterfaceBreakingChange ? "data-is-breaking" : "data-is-non-breaking");
+                       Output.Write ("{0}{1}", o, GetDescription (target));
+                       Output.WriteLine ("</span>");
                        first = false;
                }
 
                public virtual void AfterAdding ()
                {
-                       if (State.Colorize)
-                               Output.Write ("</font>");
                        Output.WriteLine ("</pre>");
+                       Output.WriteLine ("</div>");
                }
 
                public override void Modified (XElement source, XElement target, ApiChanges change)
@@ -210,9 +230,8 @@ namespace Xamarin.ApiDiff {
                public virtual void BeforeRemoving (IEnumerable<XElement> list)
                {
                        first = true;
-                       Output.WriteLine ("<p>Removed {0}:</p>\n<pre>", list.Count () > 1 ? GroupName : ElementName);
-                       if (State.Colorize)
-                               Output.Write ("<font color='red'>");
+                       Output.WriteLine ("<p>Removed {0}:</p>\n", list.Count () > 1 ? GroupName : ElementName);
+                       Output.WriteLine ("<pre>");
                }
 
                public override void Removed (XElement source)
@@ -220,15 +239,19 @@ namespace Xamarin.ApiDiff {
                        var o = GetObsoleteMessage (source);
                        if (!first && (o.Length > 0))
                                Output.WriteLine ();
-                       Indent ().WriteLine ("\t{0}{1}", o, GetDescription (source));
+
+                       bool is_breaking = IsBreakingRemoval (source);
+
+                       Indent ();
+                       Output.Write ("\t<span class='removed removed-{0} {2}' {1}>", ElementName, is_breaking ? "data-is-breaking" : "data-is-non-breaking", is_breaking ? "breaking" : string.Empty);
+                       Output.Write ("{0}{1}", o, GetDescription (source));
+                       Output.WriteLine ("</span>");
                        first = false;
                }
 
                public virtual void AfterRemoving ()
                {
-                       if (State.Colorize)
-                               Output.Write ("</font>");
-                       Output.WriteLine ("</pre>");
+                       Output.WriteLine ("</pre>");;
                }
 
                string RenderGenericParameter (XElement gp)
@@ -427,6 +450,17 @@ namespace Xamarin.ApiDiff {
                                change.AnyChange = false;
                                change.HasIgnoredChanges = true;
                        }
+
+                       var tgtSecurity = (source & MethodAttributes.HasSecurity) == MethodAttributes.HasSecurity;
+                       var srcSecurity = (target & MethodAttributes.HasSecurity) == MethodAttributes.HasSecurity;
+
+                       if (tgtSecurity != srcSecurity)
+                               change.HasIgnoredChanges = true;
+
+                       var srcPInvoke = (source & MethodAttributes.PinvokeImpl) == MethodAttributes.PinvokeImpl;
+                       var tgtPInvoke = (target & MethodAttributes.PinvokeImpl) == MethodAttributes.PinvokeImpl;
+                       if (srcPInvoke != tgtPInvoke)
+                               change.HasIgnoredChanges = true;
                }
 
                protected string GetVisibility (MethodAttributes attr)
@@ -541,15 +575,13 @@ namespace Xamarin.ApiDiff {
                                        return; // neither is obsolete
                                var change = new ApiChange ();
                                change.Header = "Obsoleted " + GroupName;
-                               if (State.Colorize)
-                                       change.Append ("<font color='gray'>");
+                               change.Append (string.Format ("<span class='obsolete obsolete-{0}' data-is-non-breaking>", ElementName));
                                change.Append ("[Obsolete (");
                                if (tgtObsolete != string.Empty)
                                        change.Append ("\"").Append (tgtObsolete).Append ("\"");
-                               change.Append ("]\n");
+                               change.Append (")]\n");
                                change.Append (GetDescription (target));
-                               if (State.Colorize)
-                                       change.Append ("</font>");
+                               change.Append ("</span>");
                                change.AnyChange = true;
                                changes.Add (source, target, change);
                        } else if (tgtObsolete == null) {