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 instrument for a dot special form case #672

Merged
merged 1 commit into from
Mar 11, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* [#666](https://github.com/clojure-emacs/cider-nrepl/pull/666): Add a check in apropos var-query-map.
* [#669](https://github.com/clojure-emacs/cider-nrepl/pull/669): Fix NPE and add isDirectory check in slurp
* [#672](https://github.com/clojure-emacs/cider-nrepl/pull/672): Fix instrument for a dot special form case

### New Features

Expand Down
10 changes: 9 additions & 1 deletion src/cider/nrepl/middleware/util/instrument.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@
'#{new} (cons (first args) (instrument-coll (rest args)))
'#{quote & var clojure.core/import*} args
'#{.} (list* (first args)
(second args)
;; To handle the case when second argument to dot call
;; is a list e.g (. class-name (method-name args*))
;; The values present as args* should be instrumented.
(let [s (second args)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to add some comments explaining this block of code.

(if (coll? s)
(->> (rest s)
instrument-coll
(concat (cons (first s) '())))
s))
(instrument-coll (rest (rest args))))
'#{def} (let [sym (first args)]
(list* (m/merge-meta sym
Expand Down
11 changes: 11 additions & 0 deletions test/clj/cider/nrepl/middleware/util/instrument_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@
'#{[(def foo "foo doc" (bp (bar) {:coor [3]} (bar))) []]
[(bar) [3]]})))

(deftest instrument-dot-test
(testing "Instrument dot special form of type"
(testing "(. class-name method-name args*)"
(is (= (t/breakpoint-tester '(. clojure.lang.Numbers add 1 x))
'#{[(. clojure.lang.Numbers add 1 (bp x {:coor [4]} x)) []]
[x [4]]})))
(testing "(. class-name (method-name args*))"
(is (= (t/breakpoint-tester '(. clojure.lang.Numbers (add 1 x)))
'#{[x [2 2]]
[(. clojure.lang.Numbers (add 1 (bp x {:coor [2 2]} x))) []]})))))

(deftest instrument-set!-test
(is (= (t/breakpoint-tester '(set! foo (bar)))
'#{[(set! foo (bp (bar) {:coor [2]} (bar))) []]
Expand Down