我尝试测试异常的抛出:
;;; src
;; Courtesy https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj
(defmacro assert-args [& pairs]
`(do (when-not ~(first pairs)
(throw (IllegalArgumentException.
(str (first ~'&form) " requires " ~(second pairs) " in " ~'*ns* ":" (:line (meta ~'&form))))))
~(let [more (nnext pairs)]
(when more
(list* `assert-args more)))))
(defmacro my-macro []
(assert-args false "foobar")
#_(...))
;;; test
(deftest x-fn-test
(is (thrown-with-msg? IllegalArgumentException #"foo" (my-macro))))
但是没有一个异常被测试框架捕获,而是全部抛出。