1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
import pytest
from conftest import TestUnitBase, assert_bash_exec, assert_complete
@pytest.mark.bashcomp(
cmd=None,
ignore_env=r"^[+-](COMP(_(WORDS|CWORD|LINE|POINT)|REPLY)|"
r"cur|prev|cword|words)=|^\+declare -f _cmd1$",
)
class TestUnitInitialize(TestUnitBase):
def test_1(self, bash):
"""Test environment non-pollution, detected at teardown."""
assert_bash_exec(
bash,
"foo() { "
"local cur prev words cword comp_args "
"COMP_WORDS=() COMP_CWORD=0 COMP_LINE= COMP_POINT=0; "
"_comp_initialize; }; "
"foo; unset -f foo",
)
def test_2(self, bash):
output = self._test_unit(
"_comp_initialize %s; echo $cur,${prev-}", bash, "(a)", 0, "a", 0
)
assert output == ","
@pytest.mark.parametrize("redirect", "> >> 2> < &>".split())
def test_redirect(self, bash, redirect):
completion = assert_complete(
bash, "%s " % redirect, cwd="shared/default"
)
assert all(x in completion for x in "foo bar".split())
@pytest.fixture(scope="class")
def cmd1_empty_completion_setup(self, bash):
assert_bash_exec(
bash,
'_cmd1() { local cur prev words cword comp_args; _comp_initialize -- "$@"; } && '
"complete -F _cmd1 cmd1",
)
@pytest.mark.parametrize("redirect", "> >> 2> {fd1}> < &> &>> >|".split())
def test_redirect_2(self, bash, cmd1_empty_completion_setup, redirect):
# Note: Bash 4.3 and below cannot properly extract the redirection ">|"
if redirect == ">|":
skipif = "((BASH_VERSINFO[0] * 100 + BASH_VERSINFO[1] < 404))"
try:
assert_bash_exec(bash, skipif, want_output=None)
except AssertionError:
pass
else:
pytest.skip(skipif)
completion = assert_complete(
bash, "cmd1 %s f" % redirect, cwd="shared/default"
)
assert "foo" in completion
@pytest.mark.parametrize("redirect", "> >> 2> < &>".split())
def test_redirect_3(self, bash, redirect):
completion = assert_complete(
bash, "cmd1 %sf" % redirect, cwd="shared/default"
)
assert "foo" in completion
|