File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,12 +143,12 @@ Returns a collection of syms naming the vars unstrumented."
143143; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; testing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144144
145145(defmacro check-1
146- [[quote s] f opts]
147- (let [{:keys [name] :as v} (ana-api/resolve &env s)]
146+ [[quote s :as qs ] f spec opts]
147+ (let [{:keys [name] :as v} (when qs ( ana-api/resolve &env s) )]
148148 `(let [s# '~name
149149 opts# ~opts
150150 v# ~(when v `(var ~name))
151- spec# ~ (when v `(s/get-spec (var ~name)))
151+ spec# ( or ~spec ~ (when v `(s/get-spec (var ~name) )))
152152 re-inst?# (and v# (seq (unstrument '~name)) true )
153153 f# (or ~f (when v# @v#))]
154154 (try
@@ -165,4 +165,14 @@ Returns a collection of syms naming the vars unstrumented."
165165 {:failure (ex-info " No :args spec" {::s/failure :no-args-spec })
166166 :sym s# :spec spec#})
167167 (finally
168- (when re-inst?# (instrument '~name)))))))
168+ (when re-inst?# (instrument '~name)))))))
169+
170+ (defmacro check-fn
171+ " Runs generative tests for fn f using spec and opts. See
172+ 'check' for options and return."
173+ ([f spec]
174+ `(check-fn ~f ~spec nil ))
175+ ([f spec opts]
176+ `(let [opts# ~opts]
177+ (validate-check-opts opts#)
178+ (check-1 nil ~f ~spec opts#))))
Original file line number Diff line number Diff line change @@ -226,14 +226,6 @@ with explain-data + ::s/failure."
226226 [opts]
227227 (assert (every? ident? (keys (:gen opts))) " check :gen expects ident keys" ))
228228
229- (defn check-fn
230- " Runs generative tests for fn f using spec and opts. See
231- 'check' for options and return."
232- ([f spec] (check-fn f spec nil ))
233- ([f spec opts]
234- (validate-check-opts opts)
235- (check-1 {:f f :spec spec} opts)))
236-
237229(defn checkable-syms
238230 " Given an opts map as per check, returns the set of syms that
239231can be checked."
@@ -370,10 +362,10 @@ key with a count for each different :type of result."
370362
371363 (s/fdef ranged-rand
372364 :args (s/and (s/cat :start int? :end int?)
373- #(< (:start %) (:end %)))
374- :ret int?
375- :fn (s/and #(>= (:ret %) (-> % :args :start ))
376- #(< (:ret %) (-> % :args :end ))))
365+ #(< (:start %) (:end %)))
366+ :ret int?
367+ :fn (s/and #(>= (:ret %) (-> % :args :start ))
368+ #(< (:ret %) (-> % :args :end ))))
377369
378370 (instrumentable-syms )
379371
@@ -396,7 +388,12 @@ key with a count for each different :type of result."
396388 (foo 1 2 )
397389 (m/unstrument-1 `ranged-rand)
398390
399- (m/check-1 `ranged-rand nil {})
391+ (m/check-1 `ranged-rand nil nil {})
392+
393+ (m/check-fn inc
394+ (s/fspec
395+ :args (s/cat :x int?)
396+ :ret int?))
400397 )
401398
402399
You can’t perform that action at this time.
0 commit comments