From 8c3b8ed4b9781672bba1c361bb27c66a743340a1 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 3 Aug 2025 19:11:03 +0900 Subject: [PATCH 1/2] test(sshfs): create files on the fly to work around Windows filesystem https://github.com/scop/bash-completion/pull/1397#discussion_r2164546105 --- test/fixtures/sshfs/local_path-dir/dummy.txt | 0 "test/fixtures/sshfs/local_path-file\\" | 0 test/t/test_sshfs.py | 21 +++++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) delete mode 100644 test/fixtures/sshfs/local_path-dir/dummy.txt delete mode 100644 "test/fixtures/sshfs/local_path-file\\" diff --git a/test/fixtures/sshfs/local_path-dir/dummy.txt b/test/fixtures/sshfs/local_path-dir/dummy.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git "a/test/fixtures/sshfs/local_path-file\\" "b/test/fixtures/sshfs/local_path-file\\" deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/t/test_sshfs.py b/test/t/test_sshfs.py index 5b502461e57..a530ef477f3 100644 --- a/test/t/test_sshfs.py +++ b/test/t/test_sshfs.py @@ -1,6 +1,8 @@ +import sys + import pytest -from conftest import assert_bash_exec, assert_complete +from conftest import assert_bash_exec, assert_complete, prepare_fixture_dir @pytest.mark.bashcomp(ignore_env=r"^[+-]_comp_cmd_scp__path_esc=") @@ -9,8 +11,21 @@ class TestSshfs: def test_1(self, completion): assert completion - @pytest.mark.complete("sshfs local_path", cwd="sshfs") - def test_local_path_suffix_1(self, completion): + @pytest.fixture + def tmpdir_backslash(self, request, bash): + if sys.platform.startswith("win"): + pytest.skip("Filenames not allowed on Windows") + + tmpdir, _, _ = prepare_fixture_dir( + request, files=["local_path-file\\"], dirs=["local_path-dir"] + ) + return tmpdir + + def test_local_path_suffix_1(self, bash, tmpdir_backslash): + completion = assert_complete( + bash, "sshfs local_path", cwd=tmpdir_backslash + ) + assert completion == "-dir/" def test_remote_path_ending_with_backslash(self, bash): From c3d122a6e90853fc9f4fdf4a20e811a9bdfed1b5 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 3 Aug 2025 21:30:34 +0900 Subject: [PATCH 2/2] test(scp): test spaces after completing filenames ending with '\' The test has not been prepared because the ending spaces cannot be tested with the typical comparison of `completion == "..."` or `completion == [...]`, but it turned out that existing test cases uses `completion.output` to check suffixing spaces. This patch implements the test using `completion.output`. https://github.com/scop/bash-completion/pull/1397#discussion_r2165093062 --- test/t/test_scp.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/t/test_scp.py b/test/t/test_scp.py index f47b1e9f05a..d28a0eb6ada 100644 --- a/test/t/test_scp.py +++ b/test/t/test_scp.py @@ -1,4 +1,5 @@ import os +import sys from itertools import chain import pytest @@ -158,6 +159,28 @@ def test_xfunc_remote_files(self, bash): "shared/default/foo.d/", ] + @pytest.fixture + def tmpdir_backslash(self, request, bash): + if sys.platform.startswith("win"): + pytest.skip("Filenames not allowed on Windows") + + tmpdir, _, _ = prepare_fixture_dir( + request, files=["local_path-file\\"], dirs=[] + ) + return tmpdir + + def test_local_path_ending_with_backslash(self, bash, tmpdir_backslash): + completion = assert_complete( + bash, "scp local_path-", cwd=tmpdir_backslash + ) + assert completion.output == r"file\\ " + + def test_remote_path_ending_with_backslash(self, bash): + assert_bash_exec(bash, "ssh() { echo 'hypothetical\\'; }") + completion = assert_complete(bash, "scp remote_host:hypo") + assert_bash_exec(bash, "unset -f ssh") + assert completion.output == r"thetical\\\\ " + @pytest.fixture def tmpdir_mkfifo(self, request, bash): tmpdir, _, _ = prepare_fixture_dir(request, files=[], dirs=[])