From 6c09f2a45c5541e9c207d14fc7aa21a4a0066bde Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 03:03:19 +0200 Subject: Merging upstream version 1:2.12.0. Signed-off-by: Daniel Baumann --- test/t/unit/test_unit_compgen_commands.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/t/unit/test_unit_compgen_commands.py (limited to 'test/t/unit/test_unit_compgen_commands.py') diff --git a/test/t/unit/test_unit_compgen_commands.py b/test/t/unit/test_unit_compgen_commands.py new file mode 100644 index 0000000..d866239 --- /dev/null +++ b/test/t/unit/test_unit_compgen_commands.py @@ -0,0 +1,47 @@ +import pytest + +from conftest import assert_bash_exec, assert_complete, bash_env_saved + + +@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+COMPREPLY=") +class TestUtilCompgenCommands: + @pytest.fixture(scope="class") + def functions(self, request, bash): + assert_bash_exec( + bash, + r"_comp_compgen_commands__test() {" + r" local COMPREPLY=() cur=${1-};" + r" _comp_compgen_commands;" + r' printf "%s\n" "${COMPREPLY[@]-}";' + r"}", + ) + assert_bash_exec( + bash, + "_comp_cmd_ccc() {" + " local cur;" + " _comp_get_words cur;" + " unset -v COMPREPLY;" + " _comp_compgen_commands;" + "}; complete -F _comp_cmd_ccc ccc", + ) + + def test_basic(self, bash, functions): + output = assert_bash_exec( + bash, "_comp_compgen_commands__test sh", want_output=True + ) + assert output.strip() + + @pytest.mark.parametrize( + "shopt_no_empty,result_empty", ((True, True), (False, False)) + ) + def test_empty(self, bash, functions, shopt_no_empty, result_empty): + with bash_env_saved(bash) as bash_env: + bash_env.shopt("no_empty_cmd_completion", shopt_no_empty) + output = assert_bash_exec( + bash, "_comp_compgen_commands__test", want_output=True + ) + assert (output.strip() == "") == result_empty + + def test_spaces(self, bash, functions): + completion = assert_complete(bash, "ccc shared/default/bar") + assert completion == r"\ bar.d/" -- cgit v1.2.3