Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception when instrumenting code with embedded namespace #329

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cider/nrepl/middleware/util/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

(defn strip-meta [form]
(if (meta form)
(with-meta form nil)
(try
(with-meta form nil)
(catch Exception e form))
form))

(defn macroexpand-all
Expand Down
16 changes: 16 additions & 0 deletions test/clj/cider/nrepl/middleware/util/instrument_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,19 @@
(is (= (breakpoint-tester '(deftest foo (bar)))
'#{[(def foo (fn* ([] (clojure.test/test-var (var foo))))) []]
[(bar) [2]]}))))

(defmacro ns-embedding-macro []
;; clojure.tools.logging does this:
`(identity ~*ns*))

(deftest test-namespace-embedded-in-code
;; Instrumentation used to fail if:
;; - a macro embedded a namespace in a form (eg: ~*ns*), and
;; - the namespace had metadata (eg: a docstring), and
;; - you tried to instrument a function that contained a call to the macro
;; This is because Namespace objects implement IMeta, but not IObj.
(let [an-ns (create-ns (with-meta 'foo.bar {:doc "ns docstring"}))]
(binding [*ns* an-ns]
(breakpoint-tester '(let [x (cider.nrepl.middleware.util.instrument-test/ns-embedding-macro)] x))
;; If the above did not throw, then we pass
(is true))))