From c9324c18e63eb67b1d3f7418c345d1dd1e6d3bdb Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 27 Jan 2010 14:21:41 +1000 Subject: Add basic Tcl implementation of 'try ... finally' --- tests/try.test | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/try.test (limited to 'tests') diff --git a/tests/try.test b/tests/try.test new file mode 100644 index 0000000..3cc86fb --- /dev/null +++ b/tests/try.test @@ -0,0 +1,65 @@ +source testing.tcl + +test try-1.1 "Simple case" { + try { + set x 0 + } finally { + incr x + } +} 0 + +test try-1.2 "Error in body" { + list [catch { + try { + set x 0 + error message + } finally { + incr x + } + } msg] $msg $x +} {1 message 1} + +test try-1.3 "Error in finally" { + list [catch { + try { + set x 0 + } finally { + incr x + error finally + } + } msg] $msg $x +} {1 finally 1} + +test try-1.4 "Error in both" { + list [catch { + try { + set x 0 + error message + } finally { + incr x + error finally + } + } msg] $msg $x +} {1 message 1} + +test try-1.5 "break in body" { + list [catch { + try { + set x 0 + break + } finally { + incr x + } + } msg] $msg $x +} {3 {} 1} + +test try-1.6 "break in finally" { + list [catch { + try { + set x 0 + } finally { + incr x + break + } + } msg] $msg $x +} {3 {} 1} -- cgit v1.1