5
5
from conftest import assert_bash_exec , assert_complete , bash_env_saved
6
6
7
7
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 )
13
9
class TestUnitQuoteCompgen :
14
10
@pytest .fixture (scope = "class" )
15
11
def functions (self , bash ):
16
12
assert_bash_exec (
17
13
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"; }' ,
19
15
)
20
16
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 )
23
22
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 ):
25
27
"""Test environment non-pollution, detected at teardown."""
26
28
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
29
65
)
66
+ assert output .strip () == "\\ $\\ (echo\\ x\\ \\ >\\ &2\\ )"
30
67
31
68
def test_github_issue_189_1 (self , bash , functions ):
32
69
"""Test error messages on a certain command line
@@ -40,7 +77,7 @@ def test_github_issue_189_1(self, bash, functions):
40
77
$ rm -- '${[TAB]
41
78
42
79
"""
43
- assert_bash_exec (bash , "_comp_test_quote_compgen $'\\ '${' >/dev/null" )
80
+ assert_bash_exec (bash , "_comp__test_quote_compgen $'\\ '${' >/dev/null" )
44
81
45
82
def test_github_issue_492_1 (self , bash , functions ):
46
83
"""Test unintended code execution on a certain command line
@@ -56,7 +93,7 @@ def test_github_issue_492_1(self, bash, functions):
56
93
57
94
"""
58
95
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"
60
97
)
61
98
assert not os .path .exists ("./1.txt" )
62
99
@@ -72,7 +109,7 @@ def test_github_issue_492_2(self, bash, functions):
72
109
73
110
"""
74
111
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"
76
113
)
77
114
assert not os .path .exists ("./1.0" )
78
115
@@ -87,7 +124,7 @@ def test_github_issue_492_3(self, bash, functions):
87
124
88
125
"""
89
126
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" )
91
128
92
129
def test_github_issue_492_4 (self , bash , functions ):
93
130
"""Test error messages through unintended pathname expansions
@@ -103,7 +140,7 @@ def test_github_issue_492_4(self, bash, functions):
103
140
with bash_env_saved (bash ) as bash_env :
104
141
bash_env .shopt ("failglob" , True )
105
142
assert_bash_exec (
106
- bash , "_comp_test_quote_compgen $'a\\ \\ \\ tb*' >/dev/null"
143
+ bash , "_comp__test_quote_compgen $'a\\ \\ \\ tb*' >/dev/null"
107
144
)
108
145
109
146
def test_github_issue_526_1 (self , bash ):
0 commit comments