Skip to content

Commit 20e646d

Browse files
authored
Merge pull request #853 from clojure-emacs/instrument-function-call-test
Adapt `instrument-function-call-test` to Clojure master
2 parents 8b54122 + 55eb8a6 commit 20e646d

File tree

3 files changed

+59
-32
lines changed

3 files changed

+59
-32
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test quick-test fast-test eastwood cljfmt install fast-install smoketest deploy clean detect_timeout lein-repl repl lint light-kondo docs test_impl
1+
.PHONY: test quick-test fast-test eastwood cljfmt cljfmt-fix install fast-install smoketest deploy clean detect_timeout lein-repl repl lint light-kondo docs test_impl
22
.DEFAULT_GOAL := quick-test
33

44
CLOJURE_VERSION ?= 1.11
@@ -82,6 +82,9 @@ eastwood:
8282
cljfmt:
8383
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+cljfmt cljfmt check
8484

85+
cljfmt-fix:
86+
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+cljfmt cljfmt fix
87+
8588
.make_kondo_prep: project.clj .clj-kondo/config.edn
8689
touch .no-pedantic
8790
touch .no-mranderson

test/clj/cider/nrepl/middleware/inspect_test.clj

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@
4141

4242
(def var-result
4343
(cond-> '("Class"
44-
": "
45-
(:value "clojure.lang.Var" 0)
46-
(:newline)
47-
"Value: "
48-
(:value "true" 1)
49-
(:newline)
50-
(:newline)
51-
"--- Meta Information:"
52-
(:newline)
53-
" "
54-
(:value ":line" 2) " = " (:value "40" 3) (:newline)
55-
" "
56-
(:value ":column" 4) " = " (:value "1" 5) (:newline)
57-
" "
58-
(:value ":file" 6) " = " (:value "\"cider/nrepl/middleware/inspect_test.clj\"" 7) (:newline)
59-
" "
60-
(:value ":name" 8) " = " (:value "any-var" 9) (:newline)
61-
" "
62-
(:value ":ns" 10) " = " (:value "cider.nrepl.middleware.inspect-test" 11) (:newline))
44+
": "
45+
(:value "clojure.lang.Var" 0)
46+
(:newline)
47+
"Value: "
48+
(:value "true" 1)
49+
(:newline)
50+
(:newline)
51+
"--- Meta Information:"
52+
(:newline)
53+
" "
54+
(:value ":line" 2) " = " (:value "40" 3) (:newline)
55+
" "
56+
(:value ":column" 4) " = " (:value "1" 5) (:newline)
57+
" "
58+
(:value ":file" 6) " = " (:value "\"cider/nrepl/middleware/inspect_test.clj\"" 7) (:newline)
59+
" "
60+
(:value ":name" 8) " = " (:value "any-var" 9) (:newline)
61+
" "
62+
(:value ":ns" 10) " = " (:value "cider.nrepl.middleware.inspect-test" 11) (:newline))
6363
datafy? (concat '((:newline)
6464
"--- Datafy:"
6565
(:newline)

test/clj/cider/nrepl/middleware/util/instrument_test.clj

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns ^:debugger cider.nrepl.middleware.util.instrument-test
22
(:require
33
[cider.nrepl.middleware.util.instrument :as t]
4+
[clojure.data :as data]
45
[clojure.set :as set]
56
[clojure.test :refer :all]
67
[clojure.walk :as walk]))
@@ -105,19 +106,42 @@
105106
this)))
106107
reify-result)))
107108

109+
(defn slashize
110+
"Converts interop dot notation into slash notation."
111+
[coll]
112+
(walk/postwalk (fn [x]
113+
(if (and (seq? x)
114+
(-> x first (= '.)))
115+
(let [[_ class member & args] x]
116+
(apply list (symbol (str class)
117+
(str member))
118+
args))
119+
x))
120+
coll))
121+
122+
(deftest slashize-test
123+
(is (= '[(System/currentTimeMillis) [3 3 1]]
124+
(slashize '[(. System currentTimeMillis) [3 3 1]]))))
125+
108126
(deftest instrument-function-call-test
109-
(is (= (t/breakpoint-tester
110-
'(defn test-fn []
111-
(let [start-time (System/currentTimeMillis)]
112-
(Thread/sleep 1000)
113-
(- (System/currentTimeMillis) start-time))))
114-
'#{[(def test-fn (fn* ([] (bp (let* [start-time (bp (. System currentTimeMillis) {:coor [3 1 1]} (System/currentTimeMillis))] (bp (. Thread sleep 1000) {:coor [3 2]} (Thread/sleep 1000)) (bp (- (bp (. System currentTimeMillis) {:coor [3 3 1]} (System/currentTimeMillis)) (bp start-time {:coor [3 3 2]} start-time)) {:coor [3 3]} (- (System/currentTimeMillis) start-time))) {:coor [3]} (let [start-time (System/currentTimeMillis)] (Thread/sleep 1000) (- (System/currentTimeMillis) start-time)))))) []]
115-
[(let* [start-time (bp (. System currentTimeMillis) {:coor [3 1 1]} (System/currentTimeMillis))] (bp (. Thread sleep 1000) {:coor [3 2]} (Thread/sleep 1000)) (bp (- (bp (. System currentTimeMillis) {:coor [3 3 1]} (System/currentTimeMillis)) (bp start-time {:coor [3 3 2]} start-time)) {:coor [3 3]} (- (System/currentTimeMillis) start-time))) [3]]
116-
[(- (bp (. System currentTimeMillis) {:coor [3 3 1]} (System/currentTimeMillis)) (bp start-time {:coor [3 3 2]} start-time)) [3 3]]
117-
[(. System currentTimeMillis) [3 1 1]]
118-
[(. Thread sleep 1000) [3 2]]
119-
[start-time [3 3 2]]
120-
[(. System currentTimeMillis) [3 3 1]]})))
127+
(let [expected '#{[(def test-fn (fn* ([] (bp (let* [start-time (bp (. System currentTimeMillis) {:coor [3 1 1]} (System/currentTimeMillis))] (bp (. Thread sleep 1000) {:coor [3 2]} (Thread/sleep 1000)) (bp (- (bp (. System currentTimeMillis) {:coor [3 3 1]} (System/currentTimeMillis)) (bp start-time {:coor [3 3 2]} start-time)) {:coor [3 3]} (- (System/currentTimeMillis) start-time))) {:coor [3]} (let [start-time (System/currentTimeMillis)] (Thread/sleep 1000) (- (System/currentTimeMillis) start-time)))))) []]
128+
[(let* [start-time (bp (. System currentTimeMillis) {:coor [3 1 1]} (System/currentTimeMillis))] (bp (. Thread sleep 1000) {:coor [3 2]} (Thread/sleep 1000)) (bp (- (bp (. System currentTimeMillis) {:coor [3 3 1]} (System/currentTimeMillis)) (bp start-time {:coor [3 3 2]} start-time)) {:coor [3 3]} (- (System/currentTimeMillis) start-time))) [3]]
129+
[(- (bp (. System currentTimeMillis) {:coor [3 3 1]} (System/currentTimeMillis)) (bp start-time {:coor [3 3 2]} start-time)) [3 3]]
130+
[(. System currentTimeMillis) [3 1 1]]
131+
[(. Thread sleep 1000) [3 2]]
132+
[start-time [3 3 2]]
133+
[(. System currentTimeMillis) [3 3 1]]}
134+
actual (t/breakpoint-tester
135+
'(defn test-fn []
136+
(let [start-time (System/currentTimeMillis)]
137+
(Thread/sleep 1000)
138+
(- (System/currentTimeMillis) start-time))))]
139+
(is (or
140+
;; Clojure < 1.12:
141+
(= expected actual)
142+
;; Clojure >= 1.12:
143+
(= (slashize expected) actual))
144+
(pr-str (data/diff expected actual)))))
121145

122146
(deftest instrument-try-test
123147
;; No breakpoints around `catch`, `finally`, `Exception`, or `e`.

0 commit comments

Comments
 (0)