samba-tool: --help test, ensuring help tree coverage
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Mon, 18 Dec 2017 03:54:07 +0000 (16:54 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Dec 2017 02:30:12 +0000 (03:30 +0100)
`samba-tool [COMMAND] --help` will list sub-commands of COMMAND
(or top-level commands if COMMAND is omitted). This ensures that
`samba-tool COMMAND SUBCOMMAND --help` works for all the commands
found in the help tree.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/help.py [new file with mode: 0644]
source4/selftest/tests.py

diff --git a/python/samba/tests/samba_tool/help.py b/python/samba/tests/samba_tool/help.py
new file mode 100644 (file)
index 0000000..4c12eef
--- /dev/null
@@ -0,0 +1,62 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Catalyst IT Ltd 2017.
+#
+# Originally written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import re
+from samba.tests.samba_tool.base import SambaToolCmdTest
+from samba.tests import BlackboxProcessError
+
+
+class HelpTestCase(SambaToolCmdTest):
+    """Tests for samba-tool --help
+
+    We test for consistency and lack of crashes."""
+
+    def _find_sub_commands(self, args):
+        self.runcmd(*args)
+
+    def test_help_tree(self):
+        # we call actual subprocesses, because we are probing the
+        # actual help output where there is no sub-command. Don't copy
+        # this if you have an actual command: for that use
+        # self.runcmd() or self.runsubcmd().
+        known_commands = [[]]
+        failed_commands = []
+
+        for i in range(4):
+            new_commands = []
+            for c in known_commands:
+                line = ' '.join(['samba-tool'] + c + ['--help'])
+                try:
+                    output = self.check_output(line)
+                except BlackboxProcessError as e:
+                    output = e.stdout
+                    failed_commands.append(c)
+
+                output = output.partition('Available subcommands:')[2]
+                subcommands = re.findall(r'^\s*([\w-]+)\s+-', output,
+                                         re.MULTILINE)
+                for s in subcommands:
+                    new_commands.append(c + [s])
+
+            if not new_commands:
+                break
+
+            known_commands = new_commands
+
+        self.assertEqual(failed_commands, [])
index 0a0bc9319089139265f08551c42da7377a5ec888..755f0c9a41131a6fc5dfc79cdad7a2b09e4a0b43 100755 (executable)
@@ -607,6 +607,7 @@ planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_passwo
 planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group")
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl")
 planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check")
 planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group")
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl")
 planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check")
+planpythontestsuite("none", "samba.tests.samba_tool.help")
 
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.sites")
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.dnscmd")
 
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.sites")
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.dnscmd")