1313 [cljs.spec :as s]
1414 [cljs.spec.impl.gen :as gen]))
1515
16+ (defonce ^:private instrumented-vars (atom #{}))
17+
1618(defn- collectionize
1719 [x]
1820 (if (symbol? x)
@@ -44,6 +46,7 @@ returns the set of all symbols naming vars in those nses."
4446 [[quote s] opts]
4547 (let [v (ana-api/resolve &env s)]
4648 (when v
49+ (swap! instrumented-vars conj v)
4750 `(let [checked# (instrument-1* ~s (var ~s) ~opts)]
4851 (when checked# (set! ~s checked#))
4952 '~(:name v)))))
@@ -52,6 +55,7 @@ returns the set of all symbols naming vars in those nses."
5255 [[quote s]]
5356 (let [v (ana-api/resolve &env s)]
5457 (when v
58+ (swap! instrumented-vars disj v)
5559 `(let [raw# (unstrument-1* ~s (var ~s))]
5660 (when raw# (set! ~s raw#))
5761 '~(:name v)))))
@@ -94,7 +98,7 @@ invokes the fn you provide, enabling arbitrary stubbing and mocking.
9498
9599Returns a collection of syms naming the vars instrumented."
96100 ([]
97- `(instrument ( instrumentable-syms ) ))
101+ `(instrument '[~@( s/speced-vars )] ))
98102 ([xs]
99103 `(instrument ~xs nil ))
100104 ([[quote sym-or-syms] opts]
@@ -119,30 +123,35 @@ Returns a collection of syms naming the vars instrumented."
119123as in instrument. With no args, unstruments all instrumented vars.
120124Returns a collection of syms naming the vars unstrumented."
121125 ([]
122- `(unstrument (map ->sym (keys @instrumented-vars))))
123- ([sym-or-syms]
124- `(into
126+ `(unstrument '[~@(deref instrumented-vars)]))
127+ ([[quote sym-or-syms]]
128+ `(reduce
129+ (fn [ret# f#]
130+ (let [sym# (f# )]
131+ (cond-> ret# sym# (conj sym#))))
125132 []
126- (comp (filter symbol?)
127- (map unstrument-1*)
128- (remove nil?))
129- (collectionize ~sym-or-syms))))
130-
131- (defmacro run-tests
132- " Like run-all-tests, but scoped to specific namespaces, or to
133- *ns* if no ns-sym are specified."
134- ([]
135- `(cljs.spec.test/run-tests '~ana/*cljs-ns*))
136- ([& ns-syms]
137- `(cljs.spec.test/run-var-tests
138- (->> #?(:clj ~(s/speced-vars* ns-syms)
139- :cljs ~(cljs.spec$macros/speced-vars* ns-syms))
140- (filter (fn [v#] (:args (cljs.spec/get-spec v#))))))))
141-
142- (defmacro run-all-tests
143- " Like clojure.test/run-all-tests, but runs test.check tests
144- for all speced vars. Prints per-test results to *out*, and
145- returns a map with :test,:pass,:fail, and :error counts."
146- []
147- `(cljs.spec.test/run-var-tests #?(:clj ~(s/speced-vars* )
148- :cljs ~(cljs.spec$macros/speced-vars* ))))
133+ [~@(->> (collectionize sym-or-syms)
134+ (map
135+ (fn [sym]
136+ (when (symbol? symbol)
137+ `(fn [] (unstrument-1 ~'sym)))))
138+ (remove nil?))])))
139+
140+ ; (defmacro run-tests
141+ ; "Like run-all-tests, but scoped to specific namespaces, or to
142+ ; *ns* if no ns-sym are specified."
143+ ; ([]
144+ ; `(cljs.spec.test/run-tests '~ana/*cljs-ns*))
145+ ; ([& ns-syms]
146+ ; `(cljs.spec.test/run-var-tests
147+ ; (->> #?(:clj ~(s/speced-vars* ns-syms)
148+ ; :cljs ~(cljs.spec$macros/speced-vars* ns-syms))
149+ ; (filter (fn [v#] (:args (cljs.spec/get-spec v#))))))))
150+ ;
151+ ; (defmacro run-all-tests
152+ ; "Like clojure.test/run-all-tests, but runs test.check tests
153+ ; for all speced vars. Prints per-test results to *out*, and
154+ ; returns a map with :test,:pass,:fail, and :error counts."
155+ ; []
156+ ; `(cljs.spec.test/run-var-tests #?(:clj ~(s/speced-vars)
157+ ; :cljs ~(cljs.spec$macros/speced-vars*))))
0 commit comments