summaryrefslogtreecommitdiffstats
path: root/Test
diff options
context:
space:
mode:
authorPhilippe Altherr <philippe.altherr@gmail.com>2026-05-09 13:36:54 -0700
committerBart Schaefer <schaefer@zsh.org>2026-05-09 13:36:54 -0700
commit64f8448103463999c5b75d7c01f39f31e2dd31fd (patch)
treef0a5460d8964da3d2378c5ee7298acad05c4ac2b /Test
parent54484: tests: fix -nt test on low-resolution file systems (diff)
downloadzsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.tar
zsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.tar.gz
zsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.tar.bz2
zsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.tar.lz
zsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.tar.xz
zsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.tar.zst
zsh-64f8448103463999c5b75d7c01f39f31e2dd31fd.zip
54374: Run ZERR trap on zsh errors
Diffstat (limited to 'Test')
-rw-r--r--Test/C03traps.ztst75
1 files changed, 75 insertions, 0 deletions
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index 87b7fd1f7..9924e4f96 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -361,6 +361,81 @@
>trap
>Working 0
+ ok() { true } # All good
+ ko() { false } # Just a non-zero status
+ KO() { { : $KO } 2>&1 } # A Zsh error
+ fn() {
+ echo "$1"
+ set -u;
+ case $1 in
+ *-TRAP-ok) TRAPZERR() { echo "ok 1"; ok; echo "ok 2" };;
+ *-trap-ok) trap 'echo "ok 1"; ok; echo "ok 2"' ZERR;;
+ *-TRAP-KO) TRAPZERR() { echo "ok 1"; KO; echo "KO 2" };;
+ *-trap-KO) trap 'echo "ok 1"; KO; echo "KO 2"' ZERR;;
+ * ) echo "Unrecognized id: $1";
+ esac
+ case $1 in
+ ko-*-*) ko; echo "ok 3";;
+ KO-*-*) KO; echo "KO 3";;
+ * ) echo "Unrecognized id: $1";
+ esac
+ }
+ (fn ko-TRAP-ok; echo "ok 4"); echo "\$?=$?"
+ (fn ko-trap-ok; echo "ok 4"); echo "\$?=$?"
+ (fn ko-TRAP-KO; echo "ok 4"); echo "\$?=$?"
+ (fn ko-trap-KO; echo "ok 4"); echo "\$?=$?"
+ (fn KO-TRAP-ok; echo "KO 4"); echo "\$?=$?"
+ (fn KO-trap-ok; echo "KO 4"); echo "\$?=$?"
+ (fn KO-TRAP-KO; echo "KO 4"); echo "\$?=$?"
+ (fn KO-trap-KO; echo "KO 4"); echo "\$?=$?"
+0:DDD
+>ko-TRAP-ok
+>ok 1
+>ok 2
+>ok 3
+>ok 4
+>$?=0
+>ko-trap-ok
+>ok 1
+>ok 2
+>ok 3
+>ok 4
+>$?=0
+>ko-TRAP-KO
+>ok 1
+>KO: KO: parameter not set
+F:Shouldn't the error in the trap prevent any further execution?
+>ok 3
+>ok 4
+>$?=0
+>ko-trap-KO
+>ok 1
+>KO: KO: parameter not set
+F:Shouldn't the error in the trap prevent any further execution?
+>ok 3
+>ok 4
+>$?=0
+>KO-TRAP-ok
+>KO: KO: parameter not set
+>ok 1
+>ok 2
+>$?=1
+>KO-trap-ok
+>KO: KO: parameter not set
+>ok 1
+>ok 2
+>$?=1
+>KO-TRAP-KO
+>KO: KO: parameter not set
+>ok 1
+>KO: KO: parameter not set
+>$?=1
+>KO-trap-KO
+>KO: KO: parameter not set
+>ok 1
+>KO: KO: parameter not set
+>$?=1
+
{ trap 'echo This subshell is exiting' EXIT; } | cat
0: EXIT trap set in current shell at left of pipeline
>This subshell is exiting