summaryrefslogtreecommitdiffstats
path: root/test/t/unit/test_unit_expand_tilde_by_ref.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:14:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:14:42 +0000
commit0bc58b66a4850cdb8458a86c3d9a2fc81de82aa3 (patch)
treeea0fe36eb5e6f40e0a1f765d44c4b0c0b2bfb089 /test/t/unit/test_unit_expand_tilde_by_ref.py
parentInitial commit. (diff)
downloadbash-completion-upstream/1%2.11.tar.xz
bash-completion-upstream/1%2.11.zip
Adding upstream version 1:2.11.upstream/1%2.11upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/t/unit/test_unit_expand_tilde_by_ref.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/t/unit/test_unit_expand_tilde_by_ref.py b/test/t/unit/test_unit_expand_tilde_by_ref.py
new file mode 100644
index 0000000..17bdedf
--- /dev/null
+++ b/test/t/unit/test_unit_expand_tilde_by_ref.py
@@ -0,0 +1,46 @@
+import pytest
+
+from conftest import assert_bash_exec
+
+
+@pytest.mark.bashcomp(cmd=None, ignore_env=r"^[+-]var=")
+class TestUnitExpandTildeByRef:
+ def test_1(self, bash):
+ assert_bash_exec(bash, "__expand_tilde_by_ref >/dev/null")
+
+ def test_2(self, bash):
+ """Test environment non-pollution, detected at teardown."""
+ assert_bash_exec(
+ bash,
+ '_x() { local aa="~"; __expand_tilde_by_ref aa; }; _x; unset _x',
+ )
+
+ @pytest.mark.parametrize("plain_tilde", (True, False))
+ @pytest.mark.parametrize(
+ "suffix_expanded",
+ (
+ ("", True),
+ ("/foo", True),
+ (r"/\$HOME", True),
+ ("/a b", True),
+ ("/*", True),
+ (";echo hello", False),
+ ("/a;echo hello", True),
+ ),
+ )
+ def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
+ user, home = user_home
+ suffix, expanded = suffix_expanded
+ if plain_tilde:
+ user = ""
+ if not suffix or not expanded:
+ home = "~"
+ elif not expanded:
+ home = "~%s" % user
+ output = assert_bash_exec(
+ bash,
+ r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
+ % (user, suffix),
+ want_output=True,
+ )
+ assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)