Commits

Meikel Brandmeyer committed ca0c10d

Added exception handling to test-driver

Comments (0)

Files changed (2)

 
 . t/testlib.sh
 
-echo 1..4
+echo 1..5
 
 try "(ok? true)" "ok 1" "true w/o description"
 try "(ok? false)" "not ok 1
 try "(ok? false \"failure\")" "not ok 1 - failure
 # Expected: false to be true" "false w/ description"
 
+try '(ok? (throw (new Exception "exception")) "exception")' \
+'not ok 1 - exception
+# Exception was thrown: java.lang.Exception: exception' "exceptions are caught"
+
 cleanup
 
 # vim:ft=sh:
     (print desc))
   (newline))
 
-(defmacro let-if [t b1 b2 & body]
-  `(if ~t
-     (let ~b1
-       ~@body)
-     (let ~b2
-       ~@body)))
-
 (defn test-driver [actual qactual exp desc pred diagnose]
   (await
     (send test-agent
           (fn [c m sr]
-            (let-if (= m :skip)
-                    [e nil
-                     a nil
-                     r true
-                     d sr]
-                    [e (exp)
-                     a (actual)
-                     r (pred e a)
-                     d desc]
-              (print-result c m r d)
-              (when-not r
-                (let [es (pr-str e)
-                      as (pr-str qactual)
-                      rs (pr-str a)]
-                  (diagnose es as rs)))
-              (flush)
-              (+ c 1)))
+            (if (= m :skip)
+              (print-result c m true sr)
+              (try
+                (let [e (exp)
+                      a (actual)
+                      r (pred e a)]
+                  (print-result c m r desc)
+                  (when-not r
+                    (let [es (pr-str e)
+                          as (pr-str qactual)
+                          rs (pr-str a)]
+                      (diagnose es as rs))))
+                (catch Exception e
+                  (print-result c m false desc)
+                  (diag (str "Exception was thrown: " e)))))
+            (flush)
+            (+ c 1))
           mode
           skip-reason)))