Skip to content

Commit 013140c

Browse files
committed
test(diff_env): do not ignore changes of OLDPWD
1 parent a22afe0 commit 013140c

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

test/t/conftest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ def diff_env(before: List[str], after: List[str], ignore: str):
408408
# Remove unified diff markers:
409409
if not re.search(r"^(---|\+\+\+|@@ )", x)
410410
# Ignore variables expected to change:
411-
and not re.search("^[-+](_|PPID|BASH_REMATCH|OLDPWD)=", x)
411+
and not re.search(
412+
"^[-+](_|PPID|BASH_REMATCH|_bash_completion_test_[a-zA-Z_0-9]*)=",
413+
x,
414+
)
412415
# Ignore likely completion functions added by us:
413416
and not re.search(r"^\+declare -f _.+", x)
414417
# ...and additional specified things:
@@ -494,7 +497,12 @@ def assert_complete(
494497
pytest.xfail(xfail)
495498
cwd = kwargs.get("cwd")
496499
if cwd:
497-
assert_bash_exec(bash, "cd '%s'" % cwd)
500+
assert_bash_exec(
501+
bash,
502+
"_bash_completion_test_OLDPWD=$OLDPWD;cd %s"
503+
% shlex.quote(str(cwd)),
504+
want_output=None,
505+
)
498506
env_prefix = "_BASHCOMP_TEST_"
499507
env = kwargs.get("env", {})
500508
if env:
@@ -557,7 +565,11 @@ def assert_complete(
557565
% " ".join("%s%s" % (env_prefix, k) for k in env.keys()),
558566
)
559567
if cwd:
560-
assert_bash_exec(bash, "cd - >/dev/null")
568+
assert_bash_exec(
569+
bash,
570+
"cd -;OLDPWD=$_bash_completion_test_OLDPWD",
571+
want_output=None,
572+
)
561573
return result
562574

563575

test/t/unit/test_unit_known_hosts_real.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,23 @@ def test_included_configs(self, bash, hosts):
141141

142142
def test_no_globbing(self, bash):
143143
assert_bash_exec(
144-
bash, 'OLDHOME="$HOME"; HOME="%s/_known_hosts_real"' % bash.cwd
144+
bash,
145+
'OLDHOME="$HOME"; HOME="$PWD/_known_hosts_real";'
146+
"_bash_completion_test_OLDPWD=$OLDPWD;cd _known_hosts_real",
145147
)
146148
output = assert_bash_exec(
147149
bash,
148-
"cd _known_hosts_real; "
149150
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
150151
"_known_hosts_real -aF config ''; "
151-
r'printf "%s\n" "${COMPREPLY[@]}"; '
152-
"cd - &>/dev/null",
152+
r'printf "%s\n" "${COMPREPLY[@]}"',
153153
want_output=True,
154154
)
155-
assert_bash_exec(bash, 'HOME="$OLDHOME"')
155+
assert_bash_exec(
156+
bash,
157+
"cd - >/dev/null;OLDPWD=$_bash_completion_test_OLDPWD;"
158+
'HOME="$OLDHOME"',
159+
)
160+
156161
completion = sorted(set(output.strip().split()))
157162
assert "gee" in completion
158163
assert "gee-filename-canary" not in completion

0 commit comments

Comments
 (0)