Closed DjebbZ closed 3 years ago
that sounds fine to me!
I quickly tried something but it failed:
(defmacro checking
"A macro intended to replace the testing macro in clojure.test with a
generative form. To make (testing \"doubling\" (is (= (* 2 2) (+ 2 2))))
generative, you simply have to change it to
(checking \"doubling\" 100 [x gen/int] (is (= (* 2 x) (+ x x)))).
You can optionally pass in a map options instead of the number of tests,
which will be passed to `clojure.test.check/quick-check`, e.g.:
(checking \"doubling\" {:num-tests 100 :seed 123 :max-size 10}
[x gen/int]
(is (= (* 2 x) (+ x x))))
For background, see
http://blog.colinwilliams.name/blog/2015/01/26/alternative-clojure-dot-test-integration-with-test-dot-check/"
([name bindings & body] ;; NEW ARITY!
`(checking ~name nil ~bindings ~body))
([name num-tests-or-options bindings & body]
`(-testing ~name
(fn []
(let [final-reports# (atom [])
options# (tc.clojure-test/process-options ~num-tests-or-options)] ;; quickly copied from tc.clojure-test, my macro-fu is weak though
(qc-and-report-exception final-reports# options# ~bindings ~@body)
(doseq [r# @final-reports#]
(-report r#)))))))
;=> CompilerException java.lang.RuntimeException: Can't have more than 1 variadic overload
Since the macro takes a variable number of args, it's not possible to have different arities... I see no solution, do you?
you'd have to manually parse the arguments (e.g., macros like clojure.core/fn
have to do this)
this is part of the problem that spec solves, but I'm not sure if adding spec to test.chuck is a good idea yet
to do it by hand, you would check if the second arg is a vector; if it's not, then you can assume it's the num-tests-or-options
; if it is a vector, then the user must not have supplied one
Hello,
First of all thank @gfredericks for pointing me to the
checking
macro here https://groups.google.com/forum/#!topic/clojure/K7T8ZkF2VEUThe only small caveat is that while
defspec
make its options completely optional with a multi-arity macro,checking
forces to specify the number of tests or a map. Maybechecking
could reuse the sameprocess-options
function from test.check directly to be sure to reuse the same logic.What do you think ?