Skip to content

Commit 1da052f

Browse files
committed
test(rsync,ssh): test remote filenames with spaces using mock commands
1 parent 78e1675 commit 1da052f

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

completions/rsync

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ _comp_cmd_rsync__vercomp()
55
if [[ $1 == "$2" ]]; then
66
return 0
77
fi
8-
local IFS=.
9-
local i ver1=($1) ver2=($2)
8+
local i ver1 ver2
9+
_comp_split -F . ver1 "$1"
10+
_comp_split -F . ver2 "$2"
1011
local n=$((${#ver1[@]} >= ${#ver2[@]} ? ${#ver1[@]} : ${#ver2[@]}))
1112
for ((i = 0; i < n; i++)); do
1213
if ((10#${ver1[i]:-0} > 10#${ver2[i]:-0})); then

test/t/test_rsync.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import pytest
22

3-
from conftest import assert_bash_exec
4-
5-
LIVE_HOST = "bash_completion"
3+
from conftest import assert_bash_exec, assert_complete
64

75

86
@pytest.mark.bashcomp(ignore_env=r"^[+-]_comp_cmd_scp__path_esc=")
@@ -67,8 +65,10 @@ def test_vercomp(self, bash, ver1, ver2, result):
6765
else:
6866
raise Exception(f"Unsupported comparison result: {result}")
6967

70-
@pytest.mark.complete(f"rsync {LIVE_HOST}:spaces", sleep_after_tab=2)
71-
def test_remote_path_with_spaces(self, completion):
68+
def test_remote_path_with_spaces(self, bash):
69+
assert_bash_exec(bash, "ssh() { echo 'spaces in filename.txt'; }")
70+
completion = assert_complete(bash, "rsync remote_host:spaces")
71+
assert_bash_exec(bash, "unset -f ssh")
7272
assert (
7373
completion == r"\ in\ filename.txt"
7474
or completion == r"\\\ in\\\ filename.txt"

test/t/test_scp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

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

77
LIVE_HOST = "bash_completion"
88

@@ -96,6 +96,8 @@ def test_remote_path_with_nullglob(self, completion):
9696
def test_remote_path_with_failglob(self, completion):
9797
assert not completion
9898

99-
@pytest.mark.complete(f"scp {LIVE_HOST}:spaces", sleep_after_tab=2)
100-
def test_remote_path_with_spaces(self, live_pwd, completion):
99+
def test_remote_path_with_spaces(self, bash):
100+
assert_bash_exec(bash, "ssh() { echo 'spaces in filename.txt'; }")
101+
completion = assert_complete(bash, "scp remote_host:spaces")
102+
assert_bash_exec(bash, "unset -f ssh")
101103
assert completion == r"\\\ in\\\ filename.txt"

0 commit comments

Comments
 (0)