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_load_completion.py | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/t/unit/test_unit_load_completion.py (limited to 'test/t/unit/test_unit_load_completion.py') diff --git a/test/t/unit/test_unit_load_completion.py b/test/t/unit/test_unit_load_completion.py new file mode 100644 index 0000000..6272e5b --- /dev/null +++ b/test/t/unit/test_unit_load_completion.py @@ -0,0 +1,94 @@ +import pytest + +from conftest import assert_bash_exec, bash_env_saved + + +@pytest.mark.bashcomp(cmd=None, cwd="_comp_load") +class TestLoadCompletion: + def test_userdir_1(self, bash): + with bash_env_saved(bash) as bash_env: + bash_env.write_variable( + "BASH_COMPLETION_USER_DIR", + "$PWD/userdir1:$PWD/userdir2:$BASH_COMPLETION_USER_DIR", + quote=False, + ) + bash_env.write_variable( + "PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False + ) + output = assert_bash_exec( + bash, "_comp_load cmd1", want_output=True + ) + assert output.strip() == "cmd1: sourced from userdir1" + output = assert_bash_exec( + bash, "_comp_load cmd2", want_output=True + ) + assert output.strip() == "cmd2: sourced from userdir2" + + def test_PATH_1(self, bash): + with bash_env_saved(bash) as bash_env: + bash_env.write_variable( + "PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False + ) + output = assert_bash_exec( + bash, "_comp_load cmd1", want_output=True + ) + assert output.strip() == "cmd1: sourced from prefix1" + output = assert_bash_exec( + bash, "_comp_load cmd2", want_output=True + ) + assert output.strip() == "cmd2: sourced from prefix1" + output = assert_bash_exec( + bash, "complete -p cmd2", want_output=True + ) + assert " cmd2" in output + output = assert_bash_exec( + bash, 'complete -p "$PWD/prefix1/sbin/cmd2"', want_output=True + ) + assert "/prefix1/sbin/cmd2" in output + + def test_cmd_path_1(self, bash): + assert_bash_exec(bash, "complete -r cmd1 || :", want_output=None) + output = assert_bash_exec( + bash, "_comp_load prefix1/bin/cmd1", want_output=True + ) + assert output.strip() == "cmd1: sourced from prefix1" + output = assert_bash_exec( + bash, 'complete -p "$PWD/prefix1/bin/cmd1"', want_output=True + ) + assert "/prefix1/bin/cmd1" in output + assert_bash_exec(bash, "! complete -p cmd1", want_output=None) + output = assert_bash_exec( + bash, "_comp_load prefix1/sbin/cmd2", want_output=True + ) + assert output.strip() == "cmd2: sourced from prefix1" + output = assert_bash_exec( + bash, "_comp_load bin/cmd1", want_output=True + ) + assert output.strip() == "cmd1: sourced from prefix1" + output = assert_bash_exec( + bash, "_comp_load bin/cmd2", want_output=True + ) + assert output.strip() == "cmd2: sourced from prefix1" + + def test_cmd_path_2(self, bash): + with bash_env_saved(bash) as bash_env: + bash_env.write_variable("PATH", "$PWD/bin:$PATH", quote=False) + output = assert_bash_exec( + bash, "_comp_load cmd1", want_output=True + ) + assert output.strip() == "cmd1: sourced from prefix1" + output = assert_bash_exec( + bash, "_comp_load cmd2", want_output=True + ) + assert output.strip() == "cmd2: sourced from prefix1" + + def test_cmd_intree_precedence(self, bash): + """ + Test in-tree, i.e. completions/$cmd relative to the main script + has precedence over location derived from PATH. + """ + with bash_env_saved(bash) as bash_env: + bash_env.write_variable("PATH", "$PWD/prefix1/bin", quote=False) + # The in-tree `sh` completion should be loaded here, + # and cause no output, unlike our `$PWD/prefix1/bin/sh` canary. + assert_bash_exec(bash, "_comp_load sh", want_output=False) -- cgit v1.2.3