@@ -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
0 commit comments