-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.cljc
44 lines (37 loc) · 1.16 KB
/
macros.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;; Copyright (c) Konrad Grzanek
;; Created 2019-12-12
(ns cljs.kongra.spec.alpha.macros
#?(:clj (:require
[clojure.spec.alpha
:as spec])))
#?(:clj (set! *warn-on-reflection* true))
#?(:clj
(defmacro chSpec {:style/indent 1}
[spec & body]
;; Works like spec/assert but it does not depend on *compile-asserts* nor
;; spec/check-asserts?
`(spec/assert* ~spec (do ~@body))))
#?(:clj
(defmacro specInstr
[s]
(when spec/*compile-asserts*
`(when (cljs.spec.alpha/check-asserts?)
(cljs.spec.test.alpha/instrument ~s)))))
#?(:clj
(defmacro specCheck
([s]
`(specCheck ~s {}))
([s opts]
(when spec/*compile-asserts*
`(when (cljs.spec.alpha/check-asserts?)
(print "specCheck" ~s "...")
(let [result#
(-> ~s
(cljs.spec.test.alpha/check ~opts)
first
:clojure.spec.test.check/ret)]
(if (= (:result result#) true)
(println (:num-tests result#)
"calls in"
(:time-elapsed-ms result#) "msecs")
(println result#))))))))