Merge branch 'devel-2.1'
[ganeti-local] / test / docs_unittest.py
index 0ede50b..95d81a8 100755 (executable)
 import unittest
 import re
 
+from ganeti import _autoconf
 from ganeti import utils
 from ganeti import cmdlib
+from ganeti import build
 from ganeti.rapi import connector
 
 import testutils
@@ -115,5 +117,36 @@ class TestDocs(unittest.TestCase):
                      utils.CommaJoin(undocumented)))
 
 
+class TestManpages(unittest.TestCase):
+  """Manpage tests"""
+
+  @staticmethod
+  def _ReadManFile(name):
+    return utils.ReadFile("%s/man/%s.sgml" %
+                          (testutils.GetSourceDir(), name))
+
+  @staticmethod
+  def _LoadScript(name):
+    return build.LoadModule("scripts/%s" % name)
+
+  def test(self):
+    for script in _autoconf.GNT_SCRIPTS:
+      self._CheckManpage(script,
+                         self._ReadManFile(script),
+                         self._LoadScript(script).commands.keys())
+
+  def _CheckManpage(self, script, mantext, commands):
+    missing = []
+
+    for cmd in commands:
+      pattern = "<cmdsynopsis>\s*<command>%s</command>" % re.escape(cmd)
+      if not re.findall(pattern, mantext, re.S):
+        missing.append(cmd)
+
+    self.failIf(missing,
+                msg=("Manpage for '%s' missing documentation for %s" %
+                     (script, utils.CommaJoin(missing))))
+
+
 if __name__ == "__main__":
-  unittest.main()
+  testutils.GanetiTestProgram()