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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
import pytest
from conftest import (
assert_bash_exec,
assert_complete,
is_bash_type,
prepare_fixture_dir,
)
@pytest.mark.bashcomp(
ignore_env=r"^[+-]((BASHOPTS|MANPATH|manpath)=|shopt -. failglob)"
)
class TestMan:
manpath = "$PWD/man"
assumed_present = "man"
@pytest.fixture
def colonpath(self, request, bash):
try:
assert_bash_exec(bash, "uname -s 2>&1 | grep -qiF cygwin")
except AssertionError:
pass
else:
pytest.skip("Cygwin doesn't like paths with colons")
return
tmpdir, _, _ = prepare_fixture_dir(
request,
files=["man/man3/Bash::Completion.3pm.gz"],
dirs=["man", "man/man3"],
)
return tmpdir
@pytest.mark.complete(
"man bash-completion-testcas",
env=dict(MANPATH=manpath),
require_cmd=True,
)
def test_1(self, completion):
assert completion == "e"
@pytest.mark.complete("man man1/f", cwd="man", env=dict(MANPATH=manpath))
def test_2(self, completion):
assert completion == "oo.1"
@pytest.mark.complete("man man/", cwd="man", env=dict(MANPATH=manpath))
def test_3(self, completion):
assert completion == "quux.8"
@pytest.mark.complete(
"man %s" % assumed_present,
cwd="shared/empty_dir",
env=dict(MANPATH=manpath),
)
def test_4(self, completion):
"""
Assumed present should not be completed complete when there's no
leading/trailing colon in $MANPATH.
"""
assert not completion
@pytest.mark.complete(
"man %s" % assumed_present,
require_cmd=True,
cwd="shared/empty_dir",
env=dict(MANPATH="%s:" % manpath),
)
def test_5(self, completion):
"""Trailing colon appends system man path."""
assert completion
@pytest.mark.complete(
"man bash-completion-testcas",
require_cmd=True,
env=dict(MANPATH="%s:" % manpath),
)
def test_6(self, completion):
assert completion == "e"
@pytest.mark.complete(
"man %s" % assumed_present,
require_cmd=True,
cwd="shared/empty_dir",
env=dict(MANPATH=":%s" % manpath),
)
def test_7(self, completion):
"""Leading colon prepends system man path."""
assert completion
@pytest.mark.complete(
"man bash-completion-testcas",
require_cmd=True,
env=dict(MANPATH=":%s" % manpath),
)
def test_8(self, completion):
assert completion == "e"
@pytest.mark.complete(
"man %s" % assumed_present,
require_cmd=True,
cwd="shared/empty_dir",
shopt=dict(failglob=True),
)
def test_9(self, bash, completion):
assert self.assumed_present in completion
def test_10(self, request, bash, colonpath):
if not is_bash_type(bash, "man"):
pytest.skip("Command not found")
completion = assert_complete(
bash,
"man Bash::C",
env=dict(MANPATH="%s:%s/man" % (TestMan.manpath, colonpath)),
)
assert completion == "ompletion"
@pytest.mark.complete("man -", require_cmd=True)
def test_11(self, completion):
assert completion
@pytest.mark.complete("man -S 1", require_cmd=True)
def test_delimited_first(self, completion):
# just appends space
assert not completion
assert completion.endswith(" ")
@pytest.mark.complete("man -S 1:", require_cmd=True)
def test_delimited_after_delimiter(self, completion):
assert completion
assert "1" not in completion
@pytest.mark.complete("man -S 1:2", require_cmd=True)
def test_delimited_later(self, completion):
# just appends space
assert not completion
assert completion.endswith(" ")
@pytest.mark.complete("man -S 1:1", require_cmd=True)
def test_delimited_deduplication(self, completion):
# no completion, no space appended
assert not completion
assert not completion.endswith(" ")
@pytest.mark.complete(
"man bash-completion-zstd-testcas",
env=dict(MANPATH=manpath),
require_cmd=True,
)
def test_zstd_arbitrary_sectsuffix(self, completion):
assert completion == "e"
@pytest.mark.complete(
"man bash-completion-testcas",
env=dict(MANPATH="'$(echo malicious code >/dev/tty)'"),
)
def test_manpath_code_injection(self, completion):
# no completion, no space appended
assert not completion
|