You're viewing version 1.2.0 of test. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (test v)
test [v] finds fn at key :test in var metadata and calls it,
presuming failure will throw exception

1 Example top

  • (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
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3735 top

(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)))
Vars in clojure.core/test: defn let

Comments top

No comments for test. Log in to add a comment.