Skip to content

Commit 0eef733

Browse files
authored
Merge pull request #1244 from yedayak/scp-remote-unit
test(scp): Add unit tests for getting remote files
2 parents e8dc253 + b6e9900 commit 0eef733

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
hooks:
1414
- id: shfmt
1515
types: [text]
16-
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
16+
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fixtures/.+/bin/.+|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
1717
exclude: ^completions/(\.gitignore|Makefile.*)$
1818

1919
- repo: https://github.com/shellcheck-py/shellcheck-py
@@ -22,7 +22,7 @@ repos:
2222
- id: shellcheck
2323
args: [-f, gcc]
2424
types: [text]
25-
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
25+
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fixtures/.+/bin/.+|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
2626
exclude: ^completions/(\.gitignore|Makefile.*)$
2727
require_serial: false # We disable SC1090 anyway, so parallel is ok
2828

test/fixtures/mount/bin/showmount

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
if [ "$1" = -e ] && [ "$2" = mocksrv ]; then
3+
if [[ $1 == -e && $2 == "mocksrv" ]]; then
44
echo "Header line"
55
echo "/test/path"
66
echo "/test/path2"

test/fixtures/scp/bin/ssh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -eu
3+
args=("$@")
4+
while true; do
5+
arg="${args[0]-}"
6+
case "$arg" in
7+
-o)
8+
args=("${args[@]:2}")
9+
;;
10+
local)
11+
args=("${args[@]:1}")
12+
;;
13+
*)
14+
break
15+
;;
16+
esac
17+
done
18+
#shellcheck disable=SC2068
19+
${args[@]}

test/t/test_scp.py

Lines changed: 43 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, assert_complete
5+
from conftest import assert_bash_exec, assert_complete, bash_env_saved
66

77
LIVE_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

Comments
 (0)