[System.Runtime.Serialization.Formatters.Soap] Make test output deterministic
[mono.git] / mcs / tools / corcompare / mono-api-html / MemberComparer.cs
index 3c08fed184f5741af2b08c8a388256406d6ac108..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,22 +199,28 @@ namespace Xamarin.ApiDiff {
                public virtual void BeforeAdding (IEnumerable<XElement> list)
                {
                        first = true;
+                       Output.WriteLine ("<div>");
                        Output.WriteLine ("<p>Added {0}:</p>", list.Count () > 1 ? GroupName : ElementName);
-                       Output.WriteLine (State.Colorize ? "<pre style='color: green'>" : "<pre>");
+                       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 ()
                {
-                       Output.WriteLine ("</pre>");;
+                       Output.WriteLine ("</pre>");
+                       Output.WriteLine ("</div>");
                }
 
                public override void Modified (XElement source, XElement target, ApiChanges change)
@@ -208,7 +231,7 @@ namespace Xamarin.ApiDiff {
                {
                        first = true;
                        Output.WriteLine ("<p>Removed {0}:</p>\n", list.Count () > 1 ? GroupName : ElementName);
-                       Output.WriteLine (State.Colorize ? "<pre style='color: red'>" : "<pre>");
+                       Output.WriteLine ("<pre>");
                }
 
                public override void Removed (XElement source)
@@ -216,7 +239,13 @@ 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;
                }
 
@@ -546,15 +575,13 @@ namespace Xamarin.ApiDiff {
                                        return; // neither is obsolete
                                var change = new ApiChange ();
                                change.Header = "Obsoleted " + GroupName;
-                               if (State.Colorize)
-                                       change.Append ("<span style='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 (GetDescription (target));
-                               if (State.Colorize)
-                                       change.Append ("</span>");
+                               change.Append ("</span>");
                                change.AnyChange = true;
                                changes.Add (source, target, change);
                        } else if (tgtObsolete == null) {