test [v] finds fn at key :test in var metadata and calls it,
presuming failure will throw exception
(defn my-function
"this function adds two numbers"
{:test #(do
(assert (= (my-function 2 3) 5))
(assert (= (my-function 4 4) 8)))}
([x y] (+ x y)))
(test #'my-function) ;equal to (test (var my-function))
=> :ok
-----------------------------------------------------------------------
(defn my-function
"this function adds two numbers"
{:test #(do
(assert (= (my-function 2 3) 5))
(assert (= (my-function 99 4) 8)))}
([x y] (+ x y)))
(test #'my-function)
=> java.lang.AssertionError: Assert failed: (= (my-function 99 4) 8) (NO_SOURCE_FILE:0
---------------------------------------------------------------------------
(defn my-function
"this function adds two numbers"
([x y] (+ x y)))
(test #'my-function)
=> :no-test
(defn test
"test [v] finds fn at key :test in var metadata and calls it,
presuming failure will throw exception"
{:added "1.0"}
[v]
(let [f (:test (meta v))]
(if f
(do (f) :ok)
:no-test)))
Comments top
No comments for test. Log in to add a comment.