Skip to content

Commit 7a539cc

Browse files
author
dnolen
committed
fix some obvious issues with instrument macro
1 parent 052d45e commit 7a539cc

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

src/main/cljs/cljs/spec/test.cljc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
(ns cljs.spec.test
1010
(:require
11-
[cljs.util :refer [distinct-by]]
1211
[cljs.analyzer :as ana]
1312
[cljs.analyzer.api :as ana-api]
1413
[cljs.spec :as s]
@@ -99,20 +98,22 @@ Returns a collection of syms naming the vars instrumented."
9998
([xs]
10099
`(instrument ~xs nil))
101100
([[quote sym-or-syms] opts]
102-
`(let [opts# ~opts]
103-
(reduce
104-
(fn [ret [_ f]]
105-
(let [sym (f)]
106-
(cond-> ret sym (conj sym))))
107-
[]
108-
(->> (zipmap
109-
(collectionize ~sym-or-syms)
110-
~@(map
111-
(fn [sym]
112-
`(fn [] (instrument-1 '~sym opts#)))
113-
(collectionize ~sym-or-syms)))
114-
(filter #((instrumentable-syms opts#) (first %)))
115-
(distinct-by first))))))
101+
(let [opts-sym (gensym "opts")]
102+
`(let [~opts-sym ~opts]
103+
(reduce
104+
(fn [ret# [_# f#]]
105+
(let [sym# (f#)]
106+
(cond-> ret# sym# (conj sym#))))
107+
[]
108+
(->> (zipmap
109+
(collectionize ~sym-or-syms)
110+
~(into []
111+
(map
112+
(fn [sym]
113+
`(fn [] (instrument-1 '~sym ~opts-sym))))
114+
(collectionize sym-or-syms)))
115+
(filter #((instrumentable-syms ~opts-sym) (first %)))
116+
(distinct-by first)))))))
116117

117118
(defmacro unstrument
118119
"Undoes instrument on the vars named by sym-or-syms, specified

src/main/cljs/cljs/spec/test.cljs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
[clojure.test.check]
1919
[clojure.test.check.properties]))
2020

21+
(defn distinct-by
22+
([f coll]
23+
(let [step (fn step [xs seen]
24+
(lazy-seq
25+
((fn [[x :as xs] seen]
26+
(when-let [s (seq xs)]
27+
(let [v (f x)]
28+
(if (contains? seen v)
29+
(recur (rest s) seen)
30+
(cons x (step (rest s) (conj seen v)))))))
31+
xs seen)))]
32+
(step coll #{}))))
33+
2134
(defn ->sym
2235
[x]
2336
(@#'s/->sym x))
@@ -281,6 +294,10 @@ Returns a map as quick-check, with :explain-data added if
281294
(instrumentable-syms)
282295

283296
(m/instrument-1 ranged-rand {})
297+
298+
(m/instrument `ranged-rand)
299+
(m/instrument `[ranged-rand])
300+
284301
(ranged-rand 8 5)
285302
(defn foo
286303
([a])

0 commit comments

Comments
 (0)