-
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 1 commit
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 |
---|---|---|
|
@@ -105,7 +105,7 @@ | |
(ct/report reports)) | ||
|
||
(defmacro checking | ||
^{:doc "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\" [x gen/int] (is (= (* 2 x) (+ x x)))). | ||
|
@@ -123,19 +123,20 @@ | |
|
||
For background, see | ||
http://blog.colinwilliams.name/blog/2015/01/26/alternative-clojure-dot-test-integration-with-test-dot-check/" | ||
:arglists '([name bindings body] [name num-tests-or-options bindings body])} | ||
: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. "Arguments to `checking` must be either [name bindings body] or [name num-tests-or-options bindings body]") | ||
:cljs (js/Error. "Arguments to `checking` must be either [name bindings body] or [name num-tests-or-options bindings body]")))) | ||
(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. "Arguments to `checking` must be either [name bindings body] or [name num-tests-or-options bindings body]") | ||
: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 [] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,13 @@ | |
;; no option is OK, defaults to 100 tests | ||
(let [nb-runs (atom 0)] | ||
(checking "no option works" [i gen/s-pos-int] | ||
(swap! nb-runs inc) | ||
(is (> 0))) | ||
(swap! nb-runs inc) | ||
(is (> 0))) | ||
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. this isn't really core to the test, but I assume you meant |
||
(testing "no option means 100 runs (test.check's default)" | ||
(is (= 100 @nb-runs)))) | ||
;; empty map is OK, defaults to 100 tests | ||
(checking "strings are strings" {} [s gen/string-ascii] | ||
(is (string? s))) | ||
(is (string? s))) | ||
;; passes because the number of tests is small | ||
(checking "small ints" {:num-tests 5} [i gen/s-pos-int] | ||
(is (< i 10))) | ||
|
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.
you can avoid the duplication here by pushing the
#?
down to just theIllegalArgumentException.
andjs/Error.