is

added
1.1

ns
clojure.test

type
macro

(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.

                (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=>