Skip to content

Commit 50ecafa

Browse files
committed
test(assert_complete): support systems with OLDPWD being unset
1 parent 013140c commit 50ecafa

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

test/t/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,12 @@ def assert_complete(
499499
if cwd:
500500
assert_bash_exec(
501501
bash,
502-
"_bash_completion_test_OLDPWD=$OLDPWD;cd %s"
503-
% shlex.quote(str(cwd)),
502+
"if [[ ${OLDPWD+set} ]]; then _bash_completion_test_OLDPWD=$OLDPWD; else unset -v _bash_completion_test_OLDPWD; fi",
504503
want_output=None,
505504
)
505+
assert_bash_exec(
506+
bash, "builtin cd %s" % shlex.quote(str(cwd)), want_output=None
507+
)
506508
env_prefix = "_BASHCOMP_TEST_"
507509
env = kwargs.get("env", {})
508510
if env:
@@ -567,7 +569,7 @@ def assert_complete(
567569
if cwd:
568570
assert_bash_exec(
569571
bash,
570-
"cd -;OLDPWD=$_bash_completion_test_OLDPWD",
572+
"builtin cd -;if [[ ${_bash_completion_test_OLDPWD+set} ]]; then OLDPWD=$_bash_completion_test_OLDPWD; else unset -v OLDPWD; fi",
571573
want_output=None,
572574
)
573575
return result

test/t/unit/test_unit_known_hosts_real.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ def test_included_configs(self, bash, hosts):
140140
assert sorted(set(output.strip().split())) == sorted(expected)
141141

142142
def test_no_globbing(self, bash):
143+
assert_bash_exec(
144+
bash, 'OLDHOME="$HOME"; HOME="$PWD/_known_hosts_real"'
145+
)
143146
assert_bash_exec(
144147
bash,
145-
'OLDHOME="$HOME"; HOME="$PWD/_known_hosts_real";'
146-
"_bash_completion_test_OLDPWD=$OLDPWD;cd _known_hosts_real",
148+
"if [[ ${OLDPWD+set} ]]; then _bash_completion_test_OLDPWD=$OLDPWD; else unset -v _bash_completion_test_OLDPWD; fi; "
149+
"builtin cd _known_hosts_real",
147150
)
148151
output = assert_bash_exec(
149152
bash,
@@ -154,9 +157,10 @@ def test_no_globbing(self, bash):
154157
)
155158
assert_bash_exec(
156159
bash,
157-
"cd - >/dev/null;OLDPWD=$_bash_completion_test_OLDPWD;"
158-
'HOME="$OLDHOME"',
160+
"builtin cd - >/dev/null; "
161+
"if [[ ${_bash_completion_test_OLDPWD+set} ]]; then OLDPWD=$_bash_completion_test_OLDPWD; else unset -v OLDPWD; fi",
159162
)
163+
assert_bash_exec(bash, 'HOME="$OLDHOME"')
160164

161165
completion = sorted(set(output.strip().split()))
162166
assert "gee" in completion

0 commit comments

Comments
 (0)