@@ -181,6 +181,11 @@ Returns a collection of syms naming the vars unstrumented."
181
181
(validate-check-opts opts#)
182
182
(check-1 nil ~f ~spec opts#))))
183
183
184
+ (defn checkable-syms* [opts]
185
+ (reduce into #{}
186
+ [(filter fn-spec-name? (keys @s/registry-ref))
187
+ (keys (:spec opts))]))
188
+
184
189
(defmacro checkable-syms
185
190
" Given an opts map as per check, returns the set of syms that
186
191
can be checked."
@@ -191,4 +196,51 @@ can be checked."
191
196
(validate-check-opts opts#)
192
197
(reduce conj #{}
193
198
'[~@(filter fn-spec-name? (keys @s/registry-ref))
194
- ~@(keys (:spec opts))]))))
199
+ ~@(keys (:spec opts))]))))
200
+
201
+ (defmacro check
202
+ " Run generative tests for spec conformance on vars named by
203
+ sym-or-syms, a symbol or collection of symbols. If sym-or-syms
204
+ is not specified, check all checkable vars.
205
+
206
+ The opts map includes the following optional keys, where stc
207
+ aliases clojure.spec.test.check:
208
+
209
+ ::stc/opts opts to flow through test.check/quick-check
210
+ :gen map from spec names to generator overrides
211
+
212
+ The ::stc/opts include :num-tests in addition to the keys
213
+ documented by test.check. Generator overrides are passed to
214
+ spec/gen when generating function args.
215
+
216
+ Returns a lazy sequence of check result maps with the following
217
+ keys
218
+
219
+ :spec the spec tested
220
+ :sym optional symbol naming the var tested
221
+ :failure optional test failure
222
+ ::stc/ret optional value returned by test.check/quick-check
223
+
224
+ The value for :failure can be any exception. Exceptions thrown by
225
+ spec itself will have an ::s/failure value in ex-data:
226
+
227
+ :check-failed at least one checked return did not conform
228
+ :no-args-spec no :args spec provided
229
+ :no-fn no fn provided
230
+ :no-fspec no fspec provided
231
+ :no-gen unable to generate :args
232
+ :instrument invalid args detected by instrument
233
+ "
234
+ ([]
235
+ `(check '~(checkable-syms* )))
236
+ ([sym-or-syms]
237
+ `(check ~sym-or-syms nil ))
238
+ ([sym-or-syms opts]
239
+ (let [sym-or-syms (eval sym-or-syms)
240
+ opts-sym (gensym " opts" )]
241
+ `(let [~opts-sym ~opts]
242
+ [~@(->> (collectionize sym-or-syms)
243
+ (filter (checkable-syms* opts))
244
+ (map
245
+ (fn [sym]
246
+ (do `(check-1 '~sym nil nil ~opts-sym)))))]))))
0 commit comments