You're viewing version 1.2.0 of is. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (is form)
  • (is form msg)
Generic assertion macro. 'form' is any predicate test.
'msg' is an optional message to attach to the assertion.

Example: (is (= 4 (+ 2 2)) "Two plus two should be 4")

Special forms:

(is (thrown? c body)) checks that an instance of c is thrown from
body, fails if not; then returns the thing thrown.

(is (thrown-with-msg? c re body)) checks that an instance of c is
thrown AND that the message on the exception matches (with
re-find) the regular expression re.

2 Examples top

  • (use '[clojure.test :only [is]])
    
    user=> (is (true? true))
    true
    
    ;; false assertions print a message and evaluate to false
    
    user=> (is (true? false))
    FAIL in clojure.lang.PersistentList$EmptyList@1 (NO_SOURCE_FILE:1)
    expected: (true? false)
      actual: (not (true? false))
    false
    
    
  • ; Testing for thrown exceptions
    
    ; Verifies that the specified exception is thrown
    user=> (is (thrown? ArithmeticException (/ 1 0)))
    #<ArithmeticException java.lang.ArithmeticException: Divide by zero>
    
    ; Verified that the exception is thrown, and that the error message matches the specified regular expression.
    user=> (is (thrown-with-msg? ArithmeticException #"Divide by zero"
      #_=>                       (/ 1 0)))
    #<ArithmeticException java.lang.ArithmeticException: Divide by zero>
    user=> 
    
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/test.clj:533 top

(defmacro is
  "Generic assertion macro.  'form' is any predicate test.
  'msg' is an optional message to attach to the assertion.
  
  Example: (is (= 4 (+ 2 2)) \"Two plus two should be 4\")

  Special forms:

  (is (thrown? c body)) checks that an instance of c is thrown from
  body, fails if not; then returns the thing thrown.

  (is (thrown-with-msg? c re body)) checks that an instance of c is
  thrown AND that the message on the exception matches (with
  re-find) the regular expression re."
  {:added "1.1"} 
  ([form] `(is ~form nil))
  ([form msg] `(try-expr ~msg ~form)))
Vars in clojure.test/is: defmacro concat list seq
Used in 0 other vars

Comments top

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