Catch exceptions that happen before the assertion can be made

This commit is contained in:
Colin Jones 2011-06-16 17:47:28 -05:00
parent 02b00bafd7
commit 8e33a43ee8

View File

@ -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)))