From 541f7b19759281971c77f26f07caf2506cf943c2 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 10 Jul 2022 20:36:47 +0900 Subject: [PATCH 1/3] test(function): add tests for existing/non-existing functions --- test/t/test_function.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/t/test_function.py b/test/t/test_function.py index 4401f0225bf..ce747801453 100644 --- a/test/t/test_function.py +++ b/test/t/test_function.py @@ -1,7 +1,19 @@ import pytest +from conftest import assert_bash_exec, assert_complete + +@pytest.mark.bashcomp(ignore_env=r"^\+declare -f fn$") class TestFunction: @pytest.mark.complete("function _parse_") def test_1(self, completion): assert completion + + @pytest.mark.complete("function non_existent_function ") + def test_2(self, completion): + assert completion == "()" + + def test_3(self, bash): + assert_bash_exec(bash, "fn() { echo; }") + completion = assert_complete(bash, "function fn ") + assert completion == "() { ^J echo^J}" From c343c46e8626cf7418a0c6d808c41d8d6fce93b6 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 10 Jul 2022 20:40:09 +0900 Subject: [PATCH 2/3] fix(function): suppress error messages for non-existent functions --- completions/function | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/function b/completions/function index 133d721d8eb..9d4a9f5d294 100644 --- a/completions/function +++ b/completions/function @@ -8,7 +8,7 @@ _function() if ((cword == 1)); then COMPREPLY=($(compgen -A function -- "$cur")) else - COMPREPLY=("() $(type -- ${words[1]} | command sed -e 1,2d)") + COMPREPLY=("() $(type -- "${words[1]}" 2>/dev/null | command sed -e 1,2d)") fi } && complete -F _function function From f45fc7706fc7e5245de9e2b9437ac8abc0f6524d Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 10 Jul 2022 20:48:39 +0900 Subject: [PATCH 3/3] fix(function): remove extra space for non-existing functions --- completions/function | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completions/function b/completions/function index 9d4a9f5d294..f19646f6a7d 100644 --- a/completions/function +++ b/completions/function @@ -8,7 +8,8 @@ _function() if ((cword == 1)); then COMPREPLY=($(compgen -A function -- "$cur")) else - COMPREPLY=("() $(type -- "${words[1]}" 2>/dev/null | command sed -e 1,2d)") + local funcdef=$(type -- "${words[1]}" 2>/dev/null | command sed -e 1,2d) + COMPREPLY=("()${funcdef:+ $funcdef}") fi } && complete -F _function function