summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-28 20:51:56 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-28 20:51:56 -0400
commit46bd94acbd10eced821827555a0ffd49a2f9cd92 (patch)
tree5b7f4893f7edfa60435946f1027b07933fe1b3cf
parentc2b1f611be7589ac2bdae34897d0140f5df75c9f (diff)
downloadcmd2-git-46bd94acbd10eced821827555a0ffd49a2f9cd92.tar.gz
Added more code coverage with unit tests
-rw-r--r--cmd2/cmd2.py4
-rw-r--r--tests/test_completion.py17
2 files changed, 21 insertions, 0 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 7a544850..dec0a04d 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2573,6 +2573,10 @@ class Cmd(cmd.Cmd):
if not tokens:
return []
+ # Must have at least 3 args for 'help command subcommand'
+ if len(tokens) < 3:
+ return []
+
# Find where the command is by skipping past any flags
cmd_index = 1
for cur_token in tokens[cmd_index:]:
diff --git a/tests/test_completion.py b/tests/test_completion.py
index e26b8a2f..1b7b65d2 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -948,6 +948,23 @@ def test_cmd2_help_subcommand_completion_with_flags_before_command(scu_app):
first_match = complete_tester(text, line, begidx, endidx, scu_app)
assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport']
+def test_complete_help_subcommand_with_no_command(scu_app):
+ # No command because not enough tokens
+ text = ''
+ line = 'help '
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ assert not scu_app.complete_help_subcommand(text, line, begidx, endidx)
+
+ # No command because everything is a flag
+ text = '-v'
+ line = 'help -f -v'
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ assert not scu_app.complete_help_subcommand(text, line, begidx, endidx)
+
def test_cmd2_help_subcommand_completion_nomatch_scu(scu_app):
text = 'z'