|
6 | 6 | @pytest.mark.bashcomp( |
7 | 7 | cmd=None, |
8 | 8 | cwd="_filedir", |
9 | | - ignore_env=r"^\+(my_array=|declare -f dump_array$)", |
| 9 | + ignore_env=r"^\+declare -f (dump_array|__tester)$", |
10 | 10 | ) |
11 | 11 | class TestExpandGlob: |
12 | | - def test_match_all(self, bash): |
| 12 | + @pytest.fixture(scope="class") |
| 13 | + def functions(self, bash): |
13 | 14 | assert_bash_exec( |
14 | 15 | bash, |
15 | | - "dump_array() { ((${#my_array[@]})) && printf '<%s>' \"${my_array[@]}\"; echo; }", |
| 16 | + "dump_array() { ((${#arr[@]})) && printf '<%s>' \"${arr[@]}\"; echo; }", |
16 | 17 | ) |
17 | | - output = assert_bash_exec( |
| 18 | + assert_bash_exec( |
18 | 19 | bash, |
19 | | - "LC_ALL= LC_COLLATE=C _comp_expand_glob my_array '*';dump_array", |
20 | | - want_output=True, |
| 20 | + '__tester() { local LC_ALL= LC_COLLATE=C arr; _comp_expand_glob arr "$@";dump_array; }', |
21 | 21 | ) |
| 22 | + |
| 23 | + def test_match_all(self, bash, functions): |
| 24 | + output = assert_bash_exec(bash, "__tester '*'", want_output=True) |
22 | 25 | assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé><brackets><ext>" |
23 | 26 |
|
24 | | - def test_match_pattern(self, bash): |
25 | | - output = assert_bash_exec( |
26 | | - bash, |
27 | | - "LC_ALL= LC_COLLATE=C _comp_expand_glob my_array 'a*';dump_array", |
28 | | - want_output=True, |
29 | | - ) |
| 27 | + def test_match_pattern(self, bash, functions): |
| 28 | + output = assert_bash_exec(bash, "__tester 'a*'", want_output=True) |
30 | 29 | assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>" |
31 | 30 |
|
32 | | - def test_match_unmatched(self, bash): |
| 31 | + def test_match_unmatched(self, bash, functions): |
33 | 32 | output = assert_bash_exec( |
34 | | - bash, |
35 | | - "_comp_expand_glob my_array 'unmatched-*';dump_array", |
36 | | - want_output=True, |
| 33 | + bash, "__tester 'unmatched-*'", want_output=True |
37 | 34 | ) |
38 | 35 | assert output.strip() == "" |
39 | 36 |
|
40 | | - def test_match_multiple_words(self, bash): |
41 | | - output = assert_bash_exec( |
42 | | - bash, |
43 | | - "_comp_expand_glob my_array 'b* e*';dump_array", |
44 | | - want_output=True, |
45 | | - ) |
| 37 | + def test_match_multiple_words(self, bash, functions): |
| 38 | + output = assert_bash_exec(bash, "__tester 'b* e*'", want_output=True) |
46 | 39 | assert output.strip() == "<brackets><ext>" |
47 | 40 |
|
48 | | - def test_match_brace_expansion(self, bash): |
| 41 | + def test_match_brace_expansion(self, bash, functions): |
49 | 42 | output = assert_bash_exec( |
50 | | - bash, |
51 | | - "_comp_expand_glob my_array 'brac{ket,unmatched}*';dump_array", |
52 | | - want_output=True, |
| 43 | + bash, "__tester 'brac{ket,unmatched}*'", want_output=True |
53 | 44 | ) |
54 | 45 | assert output.strip() == "<brackets>" |
55 | 46 |
|
56 | | - def test_protect_from_noglob(self, bash): |
57 | | - with bash_env_saved(bash) as bash_env: |
| 47 | + def test_protect_from_noglob(self, bash, functions): |
| 48 | + with bash_env_saved(bash, functions) as bash_env: |
58 | 49 | bash_env.set("noglob", True) |
59 | | - output = assert_bash_exec( |
60 | | - bash, |
61 | | - "LC_ALL= LC_COLLATE=C _comp_expand_glob my_array 'a*';dump_array", |
62 | | - want_output=True, |
63 | | - ) |
| 50 | + output = assert_bash_exec(bash, "__tester 'a*'", want_output=True) |
64 | 51 | assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>" |
65 | 52 |
|
66 | | - def test_protect_from_failglob(self, bash): |
| 53 | + def test_protect_from_failglob(self, bash, functions): |
67 | 54 | with bash_env_saved(bash) as bash_env: |
68 | 55 | bash_env.shopt("failglob", True) |
69 | 56 | output = assert_bash_exec( |
70 | | - bash, |
71 | | - "_comp_expand_glob my_array 'unmatched-*';dump_array", |
72 | | - want_output=True, |
| 57 | + bash, "__tester 'unmatched-*'", want_output=True |
73 | 58 | ) |
74 | 59 | assert output.strip() == "" |
75 | 60 |
|
76 | | - def test_protect_from_nullglob(self, bash): |
| 61 | + def test_protect_from_nullglob(self, bash, functions): |
77 | 62 | with bash_env_saved(bash) as bash_env: |
78 | 63 | bash_env.shopt("nullglob", False) |
79 | 64 | output = assert_bash_exec( |
80 | | - bash, |
81 | | - "_comp_expand_glob my_array 'unmatched-*';dump_array", |
82 | | - want_output=True, |
| 65 | + bash, "__tester 'unmatched-*'", want_output=True |
83 | 66 | ) |
84 | 67 | assert output.strip() == "" |
85 | 68 |
|
86 | | - def test_protect_from_dotglob(self, bash): |
| 69 | + def test_protect_from_dotglob(self, bash, functions): |
87 | 70 | with bash_env_saved(bash) as bash_env: |
88 | 71 | bash_env.shopt("dotglob", True) |
89 | 72 | output = assert_bash_exec( |
90 | | - bash, |
91 | | - "_comp_expand_glob my_array 'ext/foo/*';dump_array", |
92 | | - want_output=True, |
| 73 | + bash, "__tester 'ext/foo/*'", want_output=True |
93 | 74 | ) |
94 | 75 | assert output.strip() == "" |
95 | 76 |
|
96 | | - def test_protect_from_GLOBIGNORE(self, bash): |
| 77 | + def test_protect_from_GLOBIGNORE(self, bash, functions): |
97 | 78 | with bash_env_saved(bash) as bash_env: |
98 | 79 | # Note: dotglob is changed by GLOBIGNORE |
99 | 80 | bash_env.save_shopt("dotglob") |
100 | 81 | bash_env.write_variable("GLOBIGNORE", "*") |
101 | | - output = assert_bash_exec( |
102 | | - bash, |
103 | | - "LC_ALL= LC_COLLATE=C _comp_expand_glob my_array 'a*';dump_array", |
104 | | - want_output=True, |
105 | | - ) |
| 82 | + output = assert_bash_exec(bash, "__tester 'a*'", want_output=True) |
106 | 83 | assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>" |
0 commit comments