summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 18:53:39 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 18:53:39 -0600
commit93bbcf2f9a75bb5090d96ec9908594e15aa5908b (patch)
tree5069e98a1caee726174588d3522d4e85e5cbc353 /tests
parentfd782a60f3993d6ec302de669ceefbdacbf1f97a (diff)
downloadzash-perf/cd-inproc.tar.gz
perf: restore cwd after a lone ( cd dir ) in-processperf/cd-inproc
A subshell whose body is a single cd now runs in the parent shell with the directory, PWD, OLDPWD and curdir saved and restored, instead of forking. On z/OS a fork costs ~0.4 ms there; the cd itself costs ~5 us. A readonly, integer or dynamic PWD/OLDPWD keeps the forked path.
Diffstat (limited to 'tests')
-rw-r--r--tests/zash/cd-isolated.exp11
-rw-r--r--tests/zash/cd-isolated.sh16
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/zash/cd-isolated.exp b/tests/zash/cd-isolated.exp
new file mode 100644
index 0000000..13467d5
--- /dev/null
+++ b/tests/zash/cd-isolated.exp
@@ -0,0 +1,11 @@
+after=0 same=yes
+/
+/
+bad=nonzero same=yes
+redir=0 same=yes
+vars=pwd oldpwd
+list=0 same=yes
+yes
+int=2 same=yes
+ro=2 same=yes
+[status 0]
diff --git a/tests/zash/cd-isolated.sh b/tests/zash/cd-isolated.sh
new file mode 100644
index 0000000..f740aa0
--- /dev/null
+++ b/tests/zash/cd-isolated.sh
@@ -0,0 +1,16 @@
+# A lone ( cd dir ) must put the shell back where it was.
+start=$(pwd -P)
+(cd /); echo "after=$? same=$([ "$(pwd -P)" = "$start" ] && echo yes || echo no)"
+(cd /; pwd)
+(cd / && pwd)
+(cd /nonexistent) 2>/dev/null; echo "bad=$([ $? -ne 0 ] && echo nonzero) same=$([ "$(pwd -P)" = "$start" ] && echo yes || echo no)"
+(cd /) 2>/dev/null; echo "redir=$? same=$([ "$(pwd -P)" = "$start" ] && echo yes || echo no)"
+old=$OLDPWD
+(cd /); echo "vars=$([ "$PWD" = "$start" ] && echo pwd) $([ "$OLDPWD" = "$old" ] && echo oldpwd)"
+(cd /; :); echo "list=$? same=$([ "$(pwd -P)" = "$start" ] && echo yes || echo no)"
+(cd /) || echo no
+(cd /) && echo yes
+
+( typeset -i PWD; (cd /) 2>/dev/null; echo "int=$? same=$([ "$(pwd -P)" = "$start" ] && echo yes || echo no)" )
+readonly PWD
+(cd /) 2>/dev/null; echo "ro=$? same=$([ "$(pwd -P)" = "$start" ] && echo yes || echo no)"