From fc41d86b275ba4bbd2dbd76c766dbc2abc138021 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Mon, 6 May 2019 00:36:39 -0400 Subject: Exceptions occurring in tab completion functions are now printed to stderr before returning control back to readline --- tests/test_completion.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/test_completion.py') diff --git a/tests/test_completion.py b/tests/test_completion.py index 23843012..158856ec 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -77,6 +77,12 @@ class CompletionsExample(cmd2.Cmd): num_strs = ['2', '11', '1'] return self.basic_complete(text, line, begidx, endidx, num_strs) + def do_test_raise_exception(self, args): + pass + + def complete_test_raise_exception(self, text, line, begidx, endidx): + raise IndexError("You are out of bounds!!") + @pytest.fixture def cmd2_app(): @@ -120,6 +126,18 @@ def test_complete_bogus_command(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is None +def test_complete_exception(cmd2_app, capsys): + text = '' + line = 'test_raise_exception {}'.format(text) + endidx = len(line) + begidx = endidx - len(text) + + first_match = complete_tester(text, line, begidx, endidx, cmd2_app) + out, err = capsys.readouterr() + + assert first_match is None + assert "IndexError" in err + def test_complete_macro(base_app, request): # Create the macro out, err = run_cmd(base_app, 'macro create fake pyscript {1}') -- cgit v1.2.1