22
33import pytest
44
5- from conftest import assert_bash_exec , assert_complete
5+ from conftest import assert_bash_exec , assert_complete , bash_env_saved
66
77LIVE_HOST = "bash_completion"
88
@@ -23,7 +23,7 @@ def test_basic(self, hosts, completion):
2323 )
2424 ),
2525 # Local filenames
26- ["config" , "known_hosts" , r"spaced\ \ conf" ],
26+ ["bin/" , " config" , "known_hosts" , r"spaced\ \ conf" ],
2727 )
2828 )
2929 assert completion == expected
@@ -43,7 +43,7 @@ def test_basic_spaced_conf(self, hosts, completion):
4343 )
4444 ),
4545 # Local filenames
46- ["config" , "known_hosts" , r"spaced\ \ conf" ],
46+ ["bin/" , " config" , "known_hosts" , r"spaced\ \ conf" ],
4747 )
4848 )
4949 assert completion == expected
@@ -101,3 +101,43 @@ def test_remote_path_with_spaces(self, bash):
101101 completion = assert_complete (bash , "scp remote_host:spaces" )
102102 assert_bash_exec (bash , "unset -f ssh" )
103103 assert completion == r"\\\ in\\\ filename.txt"
104+
105+ def test_xfunc_remote_files (self , bash ):
106+ with bash_env_saved (bash ) as bash_env :
107+ bash_env .save_variable ("COMPREPLY" )
108+ bash_env .write_variable (
109+ "PATH" ,
110+ "$PWD/scp/bin:$PATH" ,
111+ quote = False ,
112+ )
113+ bash_env .write_variable ("cur" , "local:shared/default/" )
114+ completions_regular_escape = (
115+ assert_bash_exec (
116+ bash ,
117+ r'_comp_compgen -x scp remote_files; printf "%s\n" "${COMPREPLY[@]}"' ,
118+ want_output = True ,
119+ )
120+ .strip ()
121+ .splitlines ()
122+ )
123+ completions_less_escape = (
124+ assert_bash_exec (
125+ bash ,
126+ r'_comp_compgen -x scp remote_files -l; printf "%s\n" "${COMPREPLY[@]}"' ,
127+ want_output = True ,
128+ )
129+ .strip ()
130+ .splitlines ()
131+ )
132+ assert completions_regular_escape == [
133+ "shared/default/bar " ,
134+ r"shared/default/bar\\\ bar.d/" ,
135+ "shared/default/foo " ,
136+ "shared/default/foo.d/" ,
137+ ]
138+ assert completions_less_escape == [
139+ "shared/default/bar " ,
140+ r"shared/default/bar\ bar.d/" ,
141+ "shared/default/foo " ,
142+ "shared/default/foo.d/" ,
143+ ]
0 commit comments