Skip to content

Commit

Permalink
[Fix #671] Fix debug instrumentation for a dot special form case (#672)
Browse files Browse the repository at this point in the history
Instrumentation for dot special forms like (. clojure.lang.Numers (add 1 x)) used to fail. There was no breakpoint set for x.

This commit fixes this, so that the breakpoints are set inside the dot special form.

Co-authored-by: pranav <pranav.gajjewar45@gmail.com>
  • Loading branch information
Cartmanishere and pranav authored Mar 11, 2020
1 parent 1673e08 commit c754f98
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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)]
(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

0 comments on commit c754f98

Please sign in to comment.