summary refs log tree commit diff stats
path: root/tests/exception/tfinally4.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-02-23 11:34:08 +0100
committerAndreas Rumpf <rumpf_a@web.de>2014-02-23 11:34:08 +0100
commit6b945139e0191ad4152877ba14077b0fe3504288 (patch)
tree4e12ac6f915554e9e28aca21843e0db3b7e4d773 /tests/exception/tfinally4.nim
parent587f94f85b66c70e5006bd2b2de0d42d44b639d7 (diff)
parent1250db507533d1e11b2c451bd9bf6993beea1169 (diff)
downloadNim-6b945139e0191ad4152877ba14077b0fe3504288.tar.gz
Merge pull request #951 from skyfex/devel
Tests and fixes for return in except and finally statements
Diffstat (limited to 'tests/exception/tfinally4.nim')
-rw-r--r--tests/exception/tfinally4.nim40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/exception/tfinally4.nim b/tests/exception/tfinally4.nim
new file mode 100644
index 000000000..05c57c4f5
--- /dev/null
+++ b/tests/exception/tfinally4.nim
@@ -0,0 +1,40 @@
+discard """
+  file: "tfinally4.nim"
+  output: "B1\nA1\n1\nB1\nB2\ncatch\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\ncatch\nA1\nA2\n0\nB1\nA1\n1\nB1\nB2\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\nA1\nA2\n3"
+"""
+
+# More thorough test of return-in-finaly
+
+var raiseEx = true
+var returnA = true
+var returnB = false
+ 
+proc main: int = 
+  try: #A
+    try: #B
+      if raiseEx:
+        raise newException(EOS, "")
+      return 3
+    finally: #B
+      echo "B1"
+      if returnB:
+        return 2
+      echo "B2"
+  except EOS: #A
+    echo "catch"
+  finally: #A
+    echo "A1"
+    if returnA:
+      return 1
+    echo "A2"
+
+for x in [true, false]:
+  for y in [true, false]:
+    for z in [true, false]:
+      # echo "raiseEx: " & $x
+      # echo "returnA: " & $y
+      # echo "returnB: " & $z
+      raiseEx = x
+      returnA = y
+      returnB = z
+      echo main()