Skip to content

Commit 1302eb3

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 1302eb3

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
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/unit/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ EXTRA_DIST = \
3636
test_unit_realcommand.py \
3737
test_unit_split.py \
3838
test_unit_unlocal.py \
39-
test_unit_xfunc.py
39+
test_unit_xfunc.py \
40+
test_unit_xfunc_scp_remote_files.py
4041

4142
all:
4243

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec, bash_env_saved
4+
5+
6+
@pytest.mark.bashcomp(cmd="ssh", ignore_env=r"^\+COMPREPLY=")
7+
class TestUnitXfuncScpRemoteFiles:
8+
@pytest.fixture(scope="class")
9+
def ssh_path(self, request, bash):
10+
with bash_env_saved(bash) as bash_env:
11+
bash_env.write_variable(
12+
"PATH",
13+
"$PWD/_comp_compgen_xfunc_scp_remote_files/bin:$PATH",
14+
quote=False,
15+
)
16+
yield
17+
18+
def test_1(self, bash, ssh_path):
19+
completions = (
20+
assert_bash_exec(
21+
bash,
22+
r'cur=local:shared/default/ _comp_compgen -ax scp remote_files; printf "%s\n" "${COMPREPLY[@]}"; unset cur',
23+
want_output=True,
24+
)
25+
.strip()
26+
.splitlines()
27+
)
28+
assert completions == [
29+
"shared/default/bar ",
30+
r"shared/default/bar\\\ bar.d/",
31+
"shared/default/foo ",
32+
"shared/default/foo.d/",
33+
]

0 commit comments

Comments
 (0)