Skip to content

Commit

Permalink
Skip bash autocomplete tests on bash < 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kx-chen committed Jul 17, 2020
1 parent 5e78c64 commit 9abd538
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,26 @@ def get_completion_source(shell):
completion_source = shell_source
# BashComplete only supports versions >= 4.4
if shell == "bash":
output = run(["bash", "--version"], stdout=PIPE)
match = re.search(r"\d\.\d\.\d", output.stdout.decode())
if match:
bash_version = match.group().split(".")
if (
bash_version[0] < "4"
or bash_version[0] == "4"
and bash_version[1] < "4"
):
raise Exception(
"Shell completion is not supported"
"for bash versions older than 4.4"
)
if bash_version_not_usable():
raise Exception(
"Shell completion is not supported"
"for bash versions older than 4.4"
)
break

return completion_source


def bash_version_not_usable():
output = run(["bash", "--version"], stdout=PIPE)
match = re.search(r"\d\.\d\.\d", output.stdout.decode())
if match:
bash_version = match.group().split(".")
if bash_version[0] < "4" or bash_version[0] == "4" and bash_version[1] < "4":
return True
return False


def is_incomplete_argument(current_params, cmd_param):
"""
:param current_params: the current params and values for this
Expand Down
5 changes: 5 additions & 0 deletions tests/test_shellcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
from click.core import Command
from click.core import MultiCommand
from click.core import Parameter
from click.shell_completion import bash_version_not_usable
from click.shell_completion import get_completion_source
from click.shell_completion import resolve_ctx
from click.shell_completion import resolve_partial_value

# TODO: change ``do_completion`` interface so it can be directly
# tested rather than having to create these helper functions

pytestmark = pytest.mark.skipif(
bash_version_not_usable(), reason="Autocomplete not supported on bash < 4.4"
)


def create_cmpl_obj(cli, shell):
prog_name = cli.name
Expand Down

0 comments on commit 9abd538

Please sign in to comment.