Skip to content

Commit af2e8b3

Browse files
committed
drop sym->check-map helper, implement check-1
1 parent dd8797d commit af2e8b3

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,27 @@ Returns a collection of syms naming the vars unstrumented."
142142

143143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; testing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144144

145-
(defmacro sym->check-map
146-
[[quote s]]
147-
(if-let [{:keys [name] :as v} (ana-api/resolve &env s)]
148-
`{:s '~s
149-
:v (var ~name)
150-
:spec (s/get-spec (var ~name))}
151-
`{:s '~s}))
145+
(defmacro check-1
146+
[[quote s] f opts]
147+
(let [{:keys [name] :as v} (ana-api/resolve &env s)]
148+
`(let [s# '~name
149+
opts# ~opts
150+
v# ~(when v `(var ~name))
151+
spec# ~(when v `(s/get-spec (var ~name)))
152+
re-inst?# (and v# (seq (unstrument '~name)) true)
153+
f# (or ~f (when v# @v#))]
154+
(try
155+
(cond
156+
(nil? f#)
157+
{:failure (ex-info "No fn to spec" {::s/failure :no-fn})
158+
:sym s# :spec spec#}
159+
160+
(:args spec#)
161+
(let [tcret# (quick-check f# spec# opts#)]
162+
(make-check-result s# spec# tcret#))
163+
164+
:default
165+
{:failure (ex-info "No :args spec" {::s/failure :no-args-spec})
166+
:sym s# :spec spec#})
167+
(finally
168+
(when re-inst?# (instrument '~name)))))))

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,6 @@ with explain-data + ::s/failure."
222222
(when-let [shrunk (-> test-check-ret :shrunk)]
223223
{:failure (:result shrunk)})))
224224

225-
(defn- check-1
226-
[{:keys [s f v spec]} opts]
227-
(let [re-inst? (and v (seq (unstrument s)) true)
228-
f (or f (when v @v))]
229-
(try
230-
(cond
231-
(nil? f)
232-
{:failure (ex-info "No fn to spec" {::s/failure :no-fn})
233-
:sym s :spec spec}
234-
235-
(:args spec)
236-
(let [tcret (quick-check f spec opts)]
237-
(make-check-result s spec tcret))
238-
239-
:default
240-
{:failure (ex-info "No :args spec" {::s/failure :no-args-spec})
241-
:sym s :spec spec})
242-
(finally
243-
(when re-inst? (instrument s))))))
244-
245225
(defn- validate-check-opts
246226
[opts]
247227
(assert (every? ident? (keys (:gen opts))) "check :gen expects ident keys"))
@@ -414,9 +394,9 @@ key with a count for each different :type of result."
414394
([a b]
415395
(ranged-rand 8 5)))
416396
(foo 1 2)
417-
(m/unstrument-1 ranged-rand)
397+
(m/unstrument-1 `ranged-rand)
418398

419-
(m/sym->check-map 'ranged-rand)
399+
(m/check-1 `ranged-rand nil {})
420400
)
421401

422402

0 commit comments

Comments
 (0)