Skip to content

Commit ccae0ad

Browse files
committed
test(scp): Add unit tests for getting remote files
This tests the current behaviour of the xfunc_scp_compgen_remote_files function, including escaping, by introducing a fixture to mock ssh invocation on the local host.
1 parent 529aff8 commit ccae0ad

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

test/fixtures/scp/bin/ssh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
for arg in "$@"; do
3+
case "$arg" in
4+
-o)
5+
shift 2;;
6+
local)
7+
shift 1;;
8+
esac
9+
done
10+
$@

test/t/test_scp.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import pytest
44

5-
from conftest import assert_bash_exec
5+
from conftest import assert_bash_exec, bash_env_saved
66

77
LIVE_HOST = "bash_completion"
88

99

10+
@pytest.mark.bashcomp(ignore_env=r"^\+COMPREPLY=")
1011
class TestScp:
1112
@pytest.mark.complete("scp -F config ", cwd="scp")
1213
def test_basic(self, hosts, completion):
@@ -23,7 +24,7 @@ def test_basic(self, hosts, completion):
2324
)
2425
),
2526
# Local filenames
26-
["config", "known_hosts", r"spaced\ \ conf"],
27+
["bin/", "config", "known_hosts", r"spaced\ \ conf"],
2728
)
2829
)
2930
assert completion == expected
@@ -43,7 +44,7 @@ def test_basic_spaced_conf(self, hosts, completion):
4344
)
4445
),
4546
# Local filenames
46-
["config", "known_hosts", r"spaced\ \ conf"],
47+
["bin/", "config", "known_hosts", r"spaced\ \ conf"],
4748
)
4849
)
4950
assert completion == expected
@@ -95,3 +96,32 @@ def test_remote_path_with_nullglob(self, completion):
9596
)
9697
def test_remote_path_with_failglob(self, completion):
9798
assert not completion
99+
100+
@pytest.fixture(scope="class")
101+
def ssh_mock(self, request, bash):
102+
with bash_env_saved(bash) as bash_env:
103+
bash_env.write_variable(
104+
"PATH",
105+
"$PWD/scp/bin:$PATH",
106+
quote=False,
107+
)
108+
yield
109+
110+
def test_xfunc_remote_files(self, bash, ssh_mock):
111+
with bash_env_saved(bash) as bash_env:
112+
bash_env.write_variable("cur", "local:shared/default/")
113+
completions = (
114+
assert_bash_exec(
115+
bash,
116+
r'_comp_compgen -ax scp remote_files; printf "%s\n" "${COMPREPLY[@]}";',
117+
want_output=True,
118+
)
119+
.strip()
120+
.splitlines()
121+
)
122+
assert completions == [
123+
"shared/default/bar ",
124+
r"shared/default/bar\\\ bar.d/",
125+
"shared/default/foo ",
126+
"shared/default/foo.d/",
127+
]

0 commit comments

Comments
 (0)