From b6de4915213377fb406be6fe0cfdd3b944f667f9 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 10 Sep 2025 20:34:57 +0900 Subject: [PATCH 1/2] fix(test/t/conftest.py): include the output of pwd to the env check --- test/config/bashrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/config/bashrc b/test/config/bashrc index dcb8aacc53c..15e891979d4 100644 --- a/test/config/bashrc +++ b/test/config/bashrc @@ -64,6 +64,12 @@ add_comp_wordbreak_char() _comp__test_get_env() { + # Note: PWD is supposed to reflect the current working directory, but the + # real current working directory of the process can be different, e.g. when + # PWD is manually altered. Therefore, we also check the result of $(pwd) + # explicitly via a new variable `_comp_test_pwd`. + local _comp_test_pwd=$(pwd) + ( # Do not output the state of test variables "_comp__test_+([0-9])_*" # and internal mutable variables "_comp_*_mut_*". From 83d92c225a90f923401014023d1fb5f85328a085 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 10 Sep 2025 20:23:40 +0900 Subject: [PATCH 2/2] fix(_comp_compgen): go to the original directory on compgen failure --- bash_completion | 2 ++ test/t/unit/test_unit_compgen.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/bash_completion b/bash_completion index c39580c4bf8..f944f5e1d26 100644 --- a/bash_completion +++ b/bash_completion @@ -809,6 +809,8 @@ if ((BASH_VERSINFO[0] > 5 || BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3)); t # pat, the effect of -X '' is overwritten by the specified one. IFS=$_ifs compgen -V _result -X '' "$@" ${_cur:+-- "$_cur"} || { _comp_compgen__error_fallback + # shellcheck disable=SC2164 + [[ $_dir ]] && command cd -- "$_original_pwd" return } diff --git a/test/t/unit/test_unit_compgen.py b/test/t/unit/test_unit_compgen.py index 310609dc6e0..101d4bbe213 100644 --- a/test/t/unit/test_unit_compgen.py +++ b/test/t/unit/test_unit_compgen.py @@ -26,6 +26,11 @@ def functions(self, bash): '_comp__test_words_ifs() { local input=$2; _comp__test_compgen -F "$1" -c "${@:$#}" -- -W \'$input\'; }', ) + assert_bash_exec( + bash, + '_comp_cmd_fb() { _comp_compgen -c "$(_get_cword)" -C _filedir -- -f; }; ' + "complete -F _comp_cmd_fb fb", + ) assert_bash_exec( bash, '_comp_cmd_fc() { _comp_compgen -c "$(_get_cword)" -C _filedir filedir; }; ' @@ -143,6 +148,10 @@ def test_6_option_C_4(self, functions, completion): # will not suffix a slash to the directory name. assert completion == "b" + @pytest.mark.complete(r"fb nonexistent") + def test_6_option_C_5(self, bash, functions, completion): + assert not completion + def test_7_icmd(self, bash, functions): with bash_env_saved(bash) as bash_env: bash_env.write_variable(