Core assert macros.
Core assert macros.
(assert-expr expr)(assert-expr expr message)Evaluates expr and throws an exception if it does not evaluate to logical
true. Similar to clojure.core/assert but with better reporting. Returns
true to be used directly in :pre/:post conditions. Attaches failed
:asserting/value (false or nil) in ex-data.
(assert-expr (= 1 (inc 0)))
;=> true
(assert-expr (= 1 2) "Expect 1=2")
;Expect 1=2 - Assert failed: (assert-expr (= 1 2))
; #:asserting{:value false}
Evaluates expr and throws an exception if it does not evaluate to logical
true. Similar to `clojure.core/assert` but with better reporting. Returns
`true` to be used directly in :pre/:post conditions. Attaches failed
`:asserting/value` (`false` or `nil`) in ex-data.
(assert-expr (= 1 (inc 0)))
;=> true
(assert-expr (= 1 2) "Expect 1=2")
;Expect 1=2 - Assert failed: (assert-expr (= 1 2))
; #:asserting{:value false}
(assert-pred x pred)(assert-pred x pred message)Evaluates (pred x) and throws an exception if it does not evaluate to
logical true. Returns true to be used directly in :pre/:post conditions.
Attaches failed :asserting/value and :asserting/type in ex-data.
(assert-pred "1" string?)
;=> true
(assert-pred (inc 0) string? "Expect string")
;Expect string - Assert failed: (assert-pred (inc 0) string?)
; #:asserting{:value 1, :type java.lang.Long}
Evaluates `(pred x)` and throws an exception if it does not evaluate to
logical true. Returns `true` to be used directly in :pre/:post conditions.
Attaches failed `:asserting/value` and `:asserting/type` in ex-data.
(assert-pred "1" string?)
;=> true
(assert-pred (inc 0) string? "Expect string")
;Expect string - Assert failed: (assert-pred (inc 0) string?)
; #:asserting{:value 1, :type java.lang.Long}
(not-thrown f)Returns predicate function which is true if (f x) does not throw exception.
Can be used to assert expressions for errorless flow instead of truthy result.
(assert-pred [] first)
;Assert failed: (assert-pred [] first)
(assert-pred [] (not-thrown first))
;=> true
(assert-pred 1 (not-thrown first))
;Assert failed: (assert-pred 1 (not-thrown first))
; #:asserting{:value 1, :type java.lang.Long}
;Don't know how to create ISeq from: java.lang.Long
Returns predicate function which is true if `(f x)` does not throw exception.
Can be used to assert expressions for errorless flow instead of truthy result.
(assert-pred [] first)
;Assert failed: (assert-pred [] first)
(assert-pred [] (not-thrown first))
;=> true
(assert-pred 1 (not-thrown first))
;Assert failed: (assert-pred 1 (not-thrown first))
; #:asserting{:value 1, :type java.lang.Long}
;Don't know how to create ISeq from: java.lang.Long
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |