Skip to content

Instantly share code, notes, and snippets.

@gtrak
Last active December 21, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtrak/6346408 to your computer and use it in GitHub Desktop.
Save gtrak/6346408 to your computer and use it in GitHub Desktop.
Clojure.test hacks.
(defmacro rcf
"Reports from the calling stack frame, useful for utility
assertion functions to workaround clojure.test's reporting of file-and-line info."
[& expr]
`(let [reports# (atom [])
out# (with-redefs [clojure.test/do-report (fn [m#] (swap! reports# conj m#))]
~@expr)
final# @reports#]
(doseq [m# final#]
(clojure.test/do-report m#))))
(defn- test-inner
[]
(is (= true false)))
(clojure.test/deftest test-rcf
[]
;; rcf will report file-and-line from here instead of test-inner
(rcf (test-inner)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment