[IDesigner] Add cref reachability checker unit test though disabled for now.
authorJérémie Laval <jeremie.laval@gmail.com>
Sat, 23 Mar 2013 15:02:19 +0000 (15:02 +0000)
committerJérémie Laval <jeremie.laval@gmail.com>
Sat, 23 Mar 2013 15:02:19 +0000 (15:02 +0000)
Mono documentation has a lot of syntax error in its crefs so it's not good material for a reliable unit test until we can do better on that front.

mcs/class/monodoc/Test/Monodoc/HelpSourceTests.cs

index eabea973634558cb2801d1a5218a5f23867e3681..fdcdb6796951a05281ce08644cb9abf7ee5e9552 100644 (file)
@@ -129,5 +129,57 @@ namespace MonoTests.Monodoc
                        Assert.IsTrue (rootTree.RenderUrl ("T:System.Collections.Generic.Dictionary{TKey,TValue}+ValueCollection", generator, out result), "#5");
                        Assert.IsTrue (rootTree.RenderUrl ("T:System.IComparable{T}", generator, out result), "#6");
                }
+
+               [Test, Ignore ("Mono documentation is full of syntax errors so we can't use it reliably for this test")]
+               public void ReachabilityWithCrefsTest ()
+               {
+                       var rootTree = RootTree.LoadTree (Path.GetFullPath (BaseDir), false);
+                       Node result;
+                       var htmlGenerator = new HtmlGenerator (null);
+                       var crefs = new HashSet<string> ();
+                       var generator = new CheckGenerator ();
+                       int errorCount = 0;
+
+                       foreach (var leaf in GetLeaves (rootTree.RootNode)) {
+                               Dictionary<string, string> context;
+                               string internalId = leaf.Tree.HelpSource.GetInternalIdForUrl (leaf.PublicUrl, out result, out context);
+                               if (leaf.Tree.HelpSource.GetDocumentTypeForId (internalId) != DocumentType.EcmaXml)
+                                       continue;
+
+                               string content = null;
+                               if (string.IsNullOrEmpty (content = rootTree.RenderUrl (leaf.PublicUrl, htmlGenerator, out result)) || leaf != result) {
+                                       Console.WriteLine ("Error: {0} with HelpSource {1} ", leaf.PublicUrl, leaf.Tree.HelpSource.Name);
+                                       continue;
+                               }
+
+                               HtmlDocument doc = new HtmlDocument();
+                               try {
+                                       doc.LoadHtml (content);
+                               } catch {
+                                       Console.WriteLine ("Couldn't load a HTML document for URL {0}", leaf.PublicUrl);
+                                       continue;
+                               }
+
+                               foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]")) {
+                                       var newUrl = link.Attributes["href"].Value;
+                                       var hashIndex = newUrl.IndexOf ('#');
+                                       if (hashIndex != -1)
+                                               newUrl = newUrl.Substring (0, hashIndex);
+                                       if (newUrl.Length > 1 && newUrl[1] == ':' && char.IsLetter (newUrl, 0) && char.ToLowerInvariant (newUrl[0]) != 'c')
+                                               crefs.Add (newUrl);
+                               }
+
+                               foreach (var cref in crefs) {
+                                       if (!rootTree.RenderUrl (cref, generator, out result) || result == null) {
+                                               Console.WriteLine ("Error with cref: `{0}'", cref);
+                                               errorCount++;
+                                       }
+                               }
+
+                               crefs.Clear ();
+                       }
+
+                       Assert.AreEqual (0, errorCount, errorCount + " / " + crefs.Count);
+               }
        }
 }