tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.75k stars 139 forks source link

Do not reload the current ns with ct/report re-bound #268

Closed nberger closed 8 years ago

nberger commented 8 years ago

RunTests (and thus cpr on a clj file) does basically two things: it reloads the current namespace via (require .... :reload) and then runs the tests in the current ns with (clojure.test/run-all-tests). But to improve the output in case of a test failure it rebinds clojure.test/report to a new function that prints the output nicely.

clojure.test/report is a multimethod, but this new fn is not, so when there is a defmethod in the current namespace the (require ... :reload) fails due to an exception that looks like:

java.lang.ClassCastException: foo.core_test$eval3669$fn__3670 cannot be cast to clojure.lang.MultiFn, compiling:(foo/core_test.clj:5:1)

This change fixes this issue by doing the (require ... :reload) before binding clojure.test/report to a new fn.

An example of a library where this happens is test.check: github.com/clojure/test.check/blob/dd13277f7/src/main/clojure/clojure/test/check/clojure_test.cljc#L134

I created a repository to easily reproduce the issue in https://github.com/nberger/defmethod-vim-fireplace

tpope commented 8 years ago

Looks good.

nberger commented 8 years ago

Thanks for the merge!