-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make checking
's options optional
#58
base: master
Are you sure you want to change the base?
Changes from 8 commits
e77ca7e
dd5ad5f
2dd538a
810782c
03240d7
8a8085d
81ce719
0939c8a
122068e
ff48572
a11771a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,14 +88,13 @@ | |
(defmacro qc-and-report-exception | ||
[final-reports num-tests-or-options bindings & body] | ||
`(report-exception-or-shrunk | ||
(let [num-tests-or-options# ~num-tests-or-options] | ||
(apply tc/quick-check | ||
(times num-tests-or-options#) | ||
(prop/for-all ~bindings | ||
(let [reports# (capture-reports ~@body)] | ||
(swap! ~final-reports save-to-final-reports reports#) | ||
(pass? reports#))) | ||
(apply concat (options num-tests-or-options#)))))) | ||
(apply tc/quick-check | ||
(times ~num-tests-or-options) | ||
(prop/for-all ~bindings | ||
(let [reports# (capture-reports ~@body)] | ||
(swap! ~final-reports save-to-final-reports reports#) | ||
(pass? reports#))) | ||
(apply concat (options ~num-tests-or-options))))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason there was a E.g., compare the expansions of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I look closer, have you actually changed anything in this code, other than inlining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never thought of the double evaluation. Thanks for the tip. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code reverted by the way |
||
|
||
(defn -testing | ||
[name func] | ||
|
@@ -106,27 +105,45 @@ | |
(ct/report reports)) | ||
|
||
(defmacro checking | ||
"A macro intended to replace the testing macro in clojure.test with a | ||
{:doc "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)))). | ||
(checking \"doubling\" [x gen/int] (is (= (* 2 x) (+ x x)))). | ||
|
||
You can optionally pass in a map options instead of the number of tests, | ||
You can optionally pass the same options as test.check's defspec, | ||
which will be passed to `clojure.test.check/quick-check`, e.g.: | ||
|
||
(checking \"doubling\" {:num-tests 100 :seed 123 :max-size 10} | ||
(checking \"doubling\" 100 ;; number | ||
[x gen/int] | ||
(is (= (* 2 x) (+ x x)))) | ||
|
||
(checking \"doubling\" {:num-tests 100 :seed 123 :max-size 10} ;; options map | ||
[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 num-tests-or-options bindings & body] | ||
`(-testing ~name | ||
(fn [] | ||
(let [final-reports# (atom [])] | ||
(qc-and-report-exception final-reports# ~num-tests-or-options ~bindings ~@body) | ||
(doseq [r# @final-reports#] | ||
(-report r#)))))) | ||
:arglists '([name bindings & body] [name num-tests-or-options bindings & body])} | ||
[name & check-decl] | ||
(let [[num-tests-or-options bindings body] | ||
(cond | ||
(and (or (number? (first check-decl)) | ||
(map? (first check-decl))) | ||
(vector? (second check-decl))) | ||
[(first check-decl) (second check-decl) (nnext check-decl)] | ||
|
||
(vector? (first check-decl)) | ||
[nil (first check-decl) (next check-decl)] | ||
|
||
:else (throw (#?(:clj IllegalArgumentException. | ||
:cljs js/Error.) "Arguments to `checking` must be either [name bindings & body] or [name num-tests-or-options bindings & body]"))) | ||
num-tests-or-options (tc.clojure-test/process-options num-tests-or-options)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the fact that you're calling Now that I think about that distinction, I believe your check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, but... (read the comment below) |
||
`(-testing ~name | ||
(fn [] | ||
(let [final-reports# (atom [])] | ||
(qc-and-report-exception final-reports# ~num-tests-or-options ~bindings ~@body) | ||
(doseq [r# @final-reports#] | ||
(-report r#))))))) | ||
|
||
(defmacro for-all | ||
"An alternative to clojure.test.check.properties/for-all that uses | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please maintain the 2-space indentation for
for-all
expressionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done