From 3a6e9e7f0e810b340919e774933703ebd08d0528 Mon Sep 17 00:00:00 2001 From: Yedaya Katsman Date: Thu, 11 Sep 2025 22:57:22 +0300 Subject: [PATCH] test(scp): use live_pwd to test xfunc_remote_files This removes the script emulating ssh introduced in https://github.com/scop/bash-completion/pull/1244 Also Modify tests that assume there is a dir named bin/ in the scp fixture dir. --- test/fixtures/scp/bin/ssh | 19 --------------- test/t/conftest.py | 8 ++++--- test/t/test_scp.py | 49 ++++++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 43 deletions(-) delete mode 100755 test/fixtures/scp/bin/ssh diff --git a/test/fixtures/scp/bin/ssh b/test/fixtures/scp/bin/ssh deleted file mode 100755 index 0392dfe5d38..00000000000 --- a/test/fixtures/scp/bin/ssh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -eu -args=("$@") -while true; do - arg="${args[0]-}" - case "$arg" in - -o) - args=("${args[@]:2}") - ;; - local) - args=("${args[@]:1}") - ;; - *) - break - ;; - esac -done -#shellcheck disable=SC2068 -${args[@]} diff --git a/test/t/conftest.py b/test/t/conftest.py index 8d38d873990..48be83d2929 100644 --- a/test/t/conftest.py +++ b/test/t/conftest.py @@ -184,6 +184,10 @@ def partialize( return first_char, partial_items +def get_testdir(): + return os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) + + @pytest.fixture(scope="class") def bash(request) -> pexpect.spawn: logfile: Optional[TextIO] = None @@ -196,9 +200,7 @@ def bash(request) -> pexpect.spawn: elif os.environ.get("CI"): logfile = sys.stdout - testdir = os.path.abspath( - os.path.join(os.path.dirname(__file__), os.pardir) - ) + testdir = get_testdir() # Create an empty temporary file for HISTFILE. # diff --git a/test/t/test_scp.py b/test/t/test_scp.py index d28a0eb6ada..56a3efa44f7 100644 --- a/test/t/test_scp.py +++ b/test/t/test_scp.py @@ -8,6 +8,7 @@ assert_bash_exec, assert_complete, bash_env_saved, + get_testdir, prepare_fixture_dir, ) @@ -32,7 +33,7 @@ def test_basic(self, hosts, completion): ) ), # Local filenames - ["bin/", "config", "known_hosts", r"spaced\ \ conf"], + ["config", "known_hosts", r"spaced\ \ conf"], ) ) assert completion == expected @@ -52,7 +53,7 @@ def test_basic_spaced_conf(self, hosts, completion): ) ), # Local filenames - ["bin/", "config", "known_hosts", r"spaced\ \ conf"], + ["config", "known_hosts", r"spaced\ \ conf"], ) ) assert completion == expected @@ -68,9 +69,9 @@ def test_capital_f_without_space(self, completion): def test_capital_f_without_space_2(self, completion): assert completion == "ig" - @pytest.mark.complete("scp -Fbi", cwd="scp") + @pytest.mark.complete("scp -Fempty", cwd="shared") def test_capital_f_without_space_3(self, completion): - assert completion == "n/" + assert completion == "_dir/" @pytest.fixture(scope="class") def live_pwd(self, bash): @@ -119,15 +120,15 @@ def test_remote_path_with_spaces(self, bash): assert_bash_exec(bash, "unset -f ssh") assert completion == r"\\\ in\\\ filename.txt" - def test_xfunc_remote_files(self, bash): + def test_xfunc_remote_files(self, live_pwd, bash): + def prefix_paths(prefix, paths): + return [f"{prefix}{path}" for path in paths] + with bash_env_saved(bash) as bash_env: bash_env.save_variable("COMPREPLY") bash_env.write_variable( - "PATH", - "$PWD/scp/bin:$PATH", - quote=False, + "cur", f"{LIVE_HOST}:{get_testdir()}/fixtures/shared/default/" ) - bash_env.write_variable("cur", "local:shared/default/") completions_regular_escape = ( assert_bash_exec( bash, @@ -146,18 +147,24 @@ def test_xfunc_remote_files(self, bash): .strip() .splitlines() ) - assert completions_regular_escape == [ - "shared/default/bar ", - r"shared/default/bar\\\ bar.d/", - "shared/default/foo ", - "shared/default/foo.d/", - ] - assert completions_less_escape == [ - "shared/default/bar ", - r"shared/default/bar\ bar.d/", - "shared/default/foo ", - "shared/default/foo.d/", - ] + assert completions_regular_escape == prefix_paths( + f"{get_testdir()}/fixtures/shared/default/", + [ + "bar ", + r"bar\\\ bar.d/", + "foo ", + "foo.d/", + ], + ) + assert completions_less_escape == prefix_paths( + f"{get_testdir()}/fixtures/shared/default/", + [ + "bar ", + r"bar\ bar.d/", + "foo ", + "foo.d/", + ], + ) @pytest.fixture def tmpdir_backslash(self, request, bash):