1
1
import pytest
2
2
3
- from conftest import assert_bash_exec
3
+ from conftest import assert_bash_exec , bash_env_saved
4
4
5
5
6
6
@pytest .mark .bashcomp (cmd = None )
@@ -16,10 +16,30 @@ def functions(self, bash):
16
16
'_comp__test_compgen() { local -a arr=(00); _comp_compgen -v arr "$@"; _comp__test_dump; }' ,
17
17
)
18
18
19
- def test_1_trailing_colons (self , bash , functions ):
19
+ # We fallback to ifconfig if ip fails, so we want to check also the scenario without ip.
20
+ @pytest .fixture (scope = "function" , params = ["ip" , "ifconfig" ])
21
+ def remove_one_tool (self , request , bash ):
22
+ assert_bash_exec (bash , f"{ request .param } () {{ false; }}" )
23
+ yield
24
+ assert_bash_exec (bash , f"unset -f { request .param } " )
25
+
26
+ def test_1_trailing_colons (self , bash , functions , remove_one_tool ):
20
27
output = assert_bash_exec (
21
28
bash ,
22
29
"_comp__test_compgen available_interfaces" ,
23
30
want_output = True ,
24
31
)
25
32
assert ":>" not in output .strip ()
33
+
34
+ def test_2_correct_interfaces (self , bash , functions , remove_one_tool ):
35
+ with bash_env_saved (bash ) as bash_env :
36
+ # Using emulated ip and ifconfig commands
37
+ bash_env .write_variable (
38
+ "PATH" , "$PWD/shared/bin:$PATH" , quote = False
39
+ )
40
+ output = assert_bash_exec (
41
+ bash ,
42
+ "_comp__test_compgen available_interfaces" ,
43
+ want_output = True ,
44
+ )
45
+ assert all (iface in output for iface in ["<eth0>" , "<lo>" ])
0 commit comments