|
1 | 1 | (ns ^:debugger cider.nrepl.middleware.util.instrument-test |
2 | 2 | (:require |
3 | 3 | [cider.nrepl.middleware.util.instrument :as t] |
| 4 | + [clojure.data :as data] |
4 | 5 | [clojure.set :as set] |
5 | 6 | [clojure.test :refer :all] |
6 | 7 | [clojure.walk :as walk])) |
|
105 | 106 | this))) |
106 | 107 | reify-result))) |
107 | 108 |
|
| 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 | + |
108 | 126 | (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))))) |
121 | 145 |
|
122 | 146 | (deftest instrument-try-test |
123 | 147 | ;; No breakpoints around `catch`, `finally`, `Exception`, or `e`. |
|
0 commit comments