Skip to content

Commit

Permalink
test(scp): Add unit tests for getting remote files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yedayak committed Sep 5, 2024
1 parent 529aff8 commit 1302eb3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/fixtures/_comp_compgen_xfunc_scp_remote_files/bin/ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
for arg in "$@"; do
case "$arg" in
-o)
shift 2;;
local)
shift 1;;
esac
done
$@
3 changes: 2 additions & 1 deletion test/t/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ EXTRA_DIST = \
test_unit_realcommand.py \
test_unit_split.py \
test_unit_unlocal.py \
test_unit_xfunc.py
test_unit_xfunc.py \
test_unit_xfunc_scp_remote_files.py

all:

Expand Down
33 changes: 33 additions & 0 deletions test/t/unit/test_unit_xfunc_scp_remote_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from conftest import assert_bash_exec, bash_env_saved


@pytest.mark.bashcomp(cmd="ssh", ignore_env=r"^\+COMPREPLY=")
class TestUnitXfuncScpRemoteFiles:
@pytest.fixture(scope="class")
def ssh_path(self, request, bash):
with bash_env_saved(bash) as bash_env:
bash_env.write_variable(
"PATH",
"$PWD/_comp_compgen_xfunc_scp_remote_files/bin:$PATH",
quote=False,
)
yield

def test_1(self, bash, ssh_path):
completions = (
assert_bash_exec(
bash,
r'cur=local:shared/default/ _comp_compgen -ax scp remote_files; printf "%s\n" "${COMPREPLY[@]}"; unset cur',
want_output=True,
)
.strip()
.splitlines()
)
assert completions == [
"shared/default/bar ",
r"shared/default/bar\\\ bar.d/",
"shared/default/foo ",
"shared/default/foo.d/",
]

0 comments on commit 1302eb3

Please sign in to comment.