macro | since v0.0-927 | clojure.core/assert | Edit |
(assert x)
(assert x message)
(assert x)
- throw exception if x
is false
(assert x message)
- include message if assertion fails
Returns nil
.
(assert true)
;;=> nil
(assert false)
;;=> Uncaught Error: Assert failed: false
(assert (= 1 2) "1 is not 2")
;;=> Uncaught Error: Assert failed: 1 is not 2
;; (= 1 2)
Evaluates expr and throws an exception if it does not evaluate to logical true.
(core/defmacro assert
([x]
(core/when *assert*
`(when-not ~x
(throw (js/Error. ~(core/str "Assert failed: " (core/pr-str x)))))))
([x message]
(core/when *assert*
`(when-not ~x
(throw (js/Error.
(cljs.core/str "Assert failed: " ~message "\n" ~(core/pr-str x))))))))