aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2021-08-01 15:15:15 +1000
committerSteve Bennett <steveb@workware.net.au>2022-04-14 07:51:29 +1000
commit5b967d60f4f5277e0f843d15fc54c0cb906a1bc2 (patch)
tree3c6e9e7b8b49cd48b01334b552e91e40dbac4a6d /tests
parentb66b2a731be6bbc680f3f2c69d972050686d6720 (diff)
downloadjimtcl-5b967d60f4f5277e0f843d15fc54c0cb906a1bc2.zip
jimtcl-5b967d60f4f5277e0f843d15fc54c0cb906a1bc2.tar.gz
jimtcl-5b967d60f4f5277e0f843d15fc54c0cb906a1bc2.tar.bz2
try: add support for trap
In addition to "on codes ..." it is now possible to trap on errorcode with "trap sublist ..." e.g. try { ... } trap CHILDSTATUS {msg opts} { ... } Fixes #204 Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/try.test44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/try.test b/tests/try.test
index a2bb38a..0d76865 100644
--- a/tests/try.test
+++ b/tests/try.test
@@ -97,6 +97,50 @@ test try-1.9 "return -code from within try" {
list [catch a msg] $msg
} {3 text}
+test try-2.1 "try ... trap" -body {
+ proc a {} {
+ return -code error -errorcode {CUSTOM RESULT} "custom errorcode"
+ }
+ try {
+ a
+ } trap CUSTOM {msg opts} {
+ list $msg $opts(-code) $opts(-errorcode)
+ }
+} -result {{custom errorcode} 1 {CUSTOM RESULT}}
+
+test try-2.2 "trap single match" {
+ try {
+ apply {{} {return -code error -errorcode {FOO BAR} failed}}
+ } trap FOO {msg opts} {
+ list trapped
+ }
+} trapped
+
+test try-2.3 "trap two matches" {
+ try {
+ apply {{} {return -code error -errorcode {FOO BAR} failed}}
+ } trap {FOO BAR} {msg opts} {
+ list trapped
+ }
+} trapped
+
+test try-2.4 "trap no match" -body {
+ try {
+ apply {{} {return -code error -errorcode {FOO BAR} failed}}
+ } trap BAZ {msg opts} {
+ list trapped
+ }
+} -returnCodes error -result failed
+
+test try-2.5 "trap match first but not second" -body {
+ try {
+ apply {{} {return -code error -errorcode {FOO BAR} failed}}
+ } trap {FOO BAZ} {msg opts} {
+ list trapped
+ }
+} -returnCodes error -result failed
+
+
proc c {} {
try {
error here