D6327: gendoc: guarantee that all commands were processed.

Sietse (Sietse Brouwer) phabricator at mercurial-scm.org
Sun Apr 28 17:17:31 EDT 2019

Sietse created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

  The new logic renders the commands belonging to each category in turn.
  Commands with an unregistered category are at risk of getting skipped
  because their category is not in the list. By comparing the list of all
  commands to a log of processed commands, we can detect commands with
  unregistered categories and fail with an error message.

  rHG Mercurial




diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -196,6 +196,12 @@
             return help.registrar.command.CATEGORY_NONE
         return helpcategory
+    # Keep a log of processed commands. If a command category isn't registered
+    # in help.CATEGORY_ORDER, the command doesn't get processed by
+    # commandprinter. By comparing the list of processed commands to the
+    # original list of commands, we can detect unregistered categories.
+    processedcmds = []
     # Print the help for each command. We present the commands grouped by
     # category, and we use help.CATEGORY_ORDER as a guide for a helpful order
     # in which to present the categories.
@@ -216,6 +222,7 @@
         for f in sorted(categorycmds):
             if f.startswith(b"debug"):
+            processedcmds.append(f)  # log command
             d = get_cmd(h[f], cmdtable)
             # short description
@@ -251,7 +258,17 @@
             # aliases
             if d[b'aliases']:
                 ui.write(_(b"    aliases: %s\n\n") % b" ".join(d[b'aliases']))
+    # Make sure that we left no commands unprocessed.
+    expected = sorted(filter(lambda c: not c.startswith('debug'), cmds))
+    observed = sorted(processedcmds)
+    if not observed == expected:
+        unprocessed = sorted(set(expected) - set(observed))
+        unprocessedinfo = ', '.join(
+            "%s (%s)" % (cmd, helpcategory(cmd))
+            for cmd in unprocessed
+        )
+        raise AssertionError("The following commands did not register their"
+            " (category) in help.CATEGORY_ORDER: %s" % unprocessedinfo)
 def allextensionnames():
     return set(extensions.enabled().keys()) | set(extensions.disabled().keys())

To: Sietse, #hg-reviewers
Cc: mercurial-devel

More information about the Mercurial-devel mailing list