From 8e33a43ee89c225609f93e7225edcb3477d4ab1e Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Thu, 16 Jun 2011 17:47:28 -0500 Subject: [PATCH] Catch exceptions that happen before the assertion can be made --- src/path_to_enlightenment.clj | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index f0a9d0b..4001658 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -6,10 +6,19 @@ (def __ :fill-in-the-blank) (def ___ (fn [& args] __)) +(defmacro fancy-assert + ([x] (fancy-assert x "")) + ([x message] + `(try + (assert ~x ~message) + (catch Exception e# + (throw (Exception. (str '~message "\n" '~x ) + e#)))))) + (defmacro meditations [& forms] (let [pairs (partition 2 forms) tests (map (fn [[doc# code#]] - `(assert ~code# ~doc#)) + `(fancy-assert ~code# ~doc#)) pairs)] `(do ~@tests)))