aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/test_is.clj
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-01-21 15:44:31 +0000
committerStuart Sierra <mail@stuartsierra.com>2009-01-21 15:44:31 +0000
commit46681192663f8962f8b3d5cb10fe8f89451625d9 (patch)
treeedbeb53c52bf676a6c11a989a16d552ebbb4d00e /src/clojure/contrib/test_is.clj
parent1e1439ab3e476f1e12bdd12a14e8f45d70d4e68f (diff)
test_is.clj: new assertion "(is (thrown-with-msg? class re ...))"
Diffstat (limited to 'src/clojure/contrib/test_is.clj')
-rw-r--r--src/clojure/contrib/test_is.clj18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/clojure/contrib/test_is.clj b/src/clojure/contrib/test_is.clj
index b729c884..2907b429 100644
--- a/src/clojure/contrib/test_is.clj
+++ b/src/clojure/contrib/test_is.clj
@@ -269,8 +269,22 @@
(report :pass ~msg '~form e#)
e#))))
-;; New assertions coming soon:
-;; * thrown-with-msg?
+(defmethod assert-expr 'thrown-with-msg? [msg form]
+ ;; (is (thrown-with-msg? c re expr))
+ ;; Asserts that evaluating expr throws an exception of class c.
+ ;; Also asserts that the message string of the exception matches
+ ;; (with re-matches) the regular expression re.
+ (let [klass (nth form 1)
+ re (nth form 2)
+ body (nthrest form 3)]
+ `(try ~@body
+ (report :fail ~msg '~form nil)
+ (catch ~klass e#
+ (let [m# (.getMessage e#)]
+ (if (re-matches ~re m#)
+ (report :pass ~msg '~form e#)
+ (report :fail ~msg '~form e#)))
+ e#))))