Skip to content

Commit 642f899

Browse files
committed
test(quote_compgen): add basic tests
The tests for the old interface "quote_readline" are also added.
1 parent 4fe877d commit 642f899

File tree

1 file changed

+53
-16
lines changed

1 file changed

+53
-16
lines changed

test/t/unit/test_unit_quote_compgen.py

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,65 @@
55
from conftest import assert_bash_exec, assert_complete, bash_env_saved
66

77

8-
@pytest.mark.bashcomp(
9-
cmd=None,
10-
temp_cwd=True,
11-
ignore_env=r"^\+declare -f _comp_test_quote_compgen$",
12-
)
8+
@pytest.mark.bashcomp(cmd=None, temp_cwd=True)
139
class TestUnitQuoteCompgen:
1410
@pytest.fixture(scope="class")
1511
def functions(self, bash):
1612
assert_bash_exec(
1713
bash,
18-
'_comp_test_quote_compgen() { local ret; _comp_quote_compgen "$1"; printf %s "$ret"; }',
14+
'_comp__test_quote_compgen() { local ret; _comp_quote_compgen "$1"; printf %s "$ret"; }',
1915
)
2016

21-
def test_exec(self, bash, functions):
22-
assert_bash_exec(bash, "_comp_test_quote_compgen '' >/dev/null")
17+
@pytest.mark.parametrize(
18+
"funcname", "_comp__test_quote_compgen quote_readline".split()
19+
)
20+
def test_exec(self, bash, functions, funcname):
21+
assert_bash_exec(bash, "%s '' >/dev/null" % funcname)
2322

24-
def test_env_non_pollution(self, bash, functions):
23+
@pytest.mark.parametrize(
24+
"funcname", "_comp__test_quote_compgen quote_readline".split()
25+
)
26+
def test_env_non_pollution(self, bash, functions, funcname):
2527
"""Test environment non-pollution, detected at teardown."""
2628
assert_bash_exec(
27-
bash,
28-
"foo() { _comp_test_quote_compgen meh >/dev/null; }; foo; unset -f foo",
29+
bash, "foo() { %s meh >/dev/null; }; foo; unset -f foo" % funcname
30+
)
31+
32+
@pytest.mark.parametrize(
33+
"funcname", "_comp__test_quote_compgen quote_readline".split()
34+
)
35+
def test_1(self, bash, functions, funcname):
36+
output = assert_bash_exec(
37+
bash, "%s '';echo" % funcname, want_output=True
38+
)
39+
assert output.strip() == "''"
40+
41+
@pytest.mark.parametrize(
42+
"funcname", "_comp__test_quote_compgen quote_readline".split()
43+
)
44+
def test_2(self, bash, functions, funcname):
45+
output = assert_bash_exec(
46+
bash, "%s foo;echo" % funcname, want_output=True
47+
)
48+
assert output.strip() == "foo"
49+
50+
@pytest.mark.parametrize(
51+
"funcname", "_comp__test_quote_compgen quote_readline".split()
52+
)
53+
def test_3(self, bash, functions, funcname):
54+
output = assert_bash_exec(
55+
bash, '%s foo\\"bar;echo' % funcname, want_output=True
56+
)
57+
assert output.strip() == 'foo\\"bar'
58+
59+
@pytest.mark.parametrize(
60+
"funcname", "_comp__test_quote_compgen quote_readline".split()
61+
)
62+
def test_4(self, bash, functions, funcname):
63+
output = assert_bash_exec(
64+
bash, "%s '$(echo x >&2)';echo" % funcname, want_output=True
2965
)
66+
assert output.strip() == "\\$\\(echo\\ x\\ \\>\\&2\\)"
3067

3168
def test_github_issue_189_1(self, bash, functions):
3269
"""Test error messages on a certain command line
@@ -40,7 +77,7 @@ def test_github_issue_189_1(self, bash, functions):
4077
$ rm -- '${[TAB]
4178
4279
"""
43-
assert_bash_exec(bash, "_comp_test_quote_compgen $'\\'${' >/dev/null")
80+
assert_bash_exec(bash, "_comp__test_quote_compgen $'\\'${' >/dev/null")
4481

4582
def test_github_issue_492_1(self, bash, functions):
4683
"""Test unintended code execution on a certain command line
@@ -56,7 +93,7 @@ def test_github_issue_492_1(self, bash, functions):
5693
5794
"""
5895
assert_bash_exec(
59-
bash, "_comp_test_quote_compgen $'\\'$(touch 1.txt)' >/dev/null"
96+
bash, "_comp__test_quote_compgen $'\\'$(touch 1.txt)' >/dev/null"
6097
)
6198
assert not os.path.exists("./1.txt")
6299

@@ -72,7 +109,7 @@ def test_github_issue_492_2(self, bash, functions):
72109
73110
"""
74111
assert_bash_exec(
75-
bash, "_comp_test_quote_compgen $'\\'$1 > 1.0' >/dev/null"
112+
bash, "_comp__test_quote_compgen $'\\'$1 > 1.0' >/dev/null"
76113
)
77114
assert not os.path.exists("./1.0")
78115

@@ -87,7 +124,7 @@ def test_github_issue_492_3(self, bash, functions):
87124
88125
"""
89126
os.mkdir("./ret=$(echo injected >&2)")
90-
assert_bash_exec(bash, "_comp_test_quote_compgen $'\\'$*' >/dev/null")
127+
assert_bash_exec(bash, "_comp__test_quote_compgen $'\\'$*' >/dev/null")
91128

92129
def test_github_issue_492_4(self, bash, functions):
93130
"""Test error messages through unintended pathname expansions
@@ -103,7 +140,7 @@ def test_github_issue_492_4(self, bash, functions):
103140
with bash_env_saved(bash) as bash_env:
104141
bash_env.shopt("failglob", True)
105142
assert_bash_exec(
106-
bash, "_comp_test_quote_compgen $'a\\\\\\tb*' >/dev/null"
143+
bash, "_comp__test_quote_compgen $'a\\\\\\tb*' >/dev/null"
107144
)
108145

109146
def test_github_issue_526_1(self, bash):

0 commit comments

Comments
 (0)