Liking cljdoc? Tell your friends :D

taoensso.truss

An opinionated assertions API for Clojure/Script.

An opinionated assertions API for Clojure/Script.
raw docstring

get-dynamic-assertion-dataclj/s

(get-dynamic-assertion-data)

Returns current value of dynamic assertion data.

Returns current value of dynamic assertion data.
sourceraw docstring

havecljmacro

(have pred (:in) x)
(have pred (:in) x & more-xs)

Takes a pred and one or more vals. Tests pred against each val, trapping errors. If any pred test fails, throws a detailed assertion error. Otherwise returns input val/vals for convenient inline-use/binding.

Respects assert value so tests can be elided from production for zero runtime costs.

Provides a small, simple, flexible feature subset to alternative tools like clojure.spec, core.typed, prismatic/schema, etc.

;; Will throw a detailed error message on invariant violation: (fn my-fn [x] (str/trim (have string? x)))

You may attach arbitrary debug info to assertion violations like: (have string? x :data {:my-arbitrary-debug-info "foo"})

See also have?, have!.

Takes a pred and one or more vals. Tests pred against each val,
trapping errors. If any pred test fails, throws a detailed assertion error.
Otherwise returns input val/vals for convenient inline-use/binding.

Respects *assert* value so tests can be elided from production for zero
runtime costs.

Provides a small, simple, flexible feature subset to alternative tools like
clojure.spec, core.typed, prismatic/schema, etc.

  ;; Will throw a detailed error message on invariant violation:
  (fn my-fn [x] (str/trim (have string? x)))

You may attach arbitrary debug info to assertion violations like:
  `(have string? x :data {:my-arbitrary-debug-info "foo"})`

See also `have?`, `have!`.
sourceraw docstring

have!cljmacro

(have! pred (:in) x)
(have! pred (:in) x & more-xs)

Like have but ignores assert value (so can never be elided). Useful for important conditions in production (e.g. security checks).

Like `have` but ignores *assert* value (so can never be elided). Useful
for important conditions in production (e.g. security checks).
sourceraw docstring

have!?cljmacro

(have!? pred (:in) x)
(have!? pred (:in) x & more-xs)

Specialized cross between have? and have!. Not used often but can be handy for semantic clarification and/or to improve multi-val performance when the return vals aren't necessary.

WARNING: Do NOT use in :pre/:post conds since those are ALWAYS subject to assert, directly contradicting the intention of the bang (!) here.

Specialized cross between `have?` and `have!`. Not used often but can be
handy for semantic clarification and/or to improve multi-val performance
when the return vals aren't necessary.

**WARNING**: Do NOT use in :pre/:post conds since those are ALWAYS subject
to *assert*, directly contradicting the intention of the bang (`!`) here.
sourceraw docstring

have?cljmacro

(have? pred (:in) x)
(have? pred (:in) x & more-xs)

Like have but returns true on successful tests. In particular, this can be handy for use with :pre/:post conditions. Compare: (fn my-fn [x] {:post [(have nil? %)]} nil) ; {:post [nil]} FAILS (fn my-fn [x] {:post [(have? nil? %)]} nil) ; {:post [true]} passes as intended

Like `have` but returns `true` on successful tests. In particular, this
can be handy for use with :pre/:post conditions. Compare:
  (fn my-fn [x] {:post [(have  nil? %)]} nil) ; {:post [nil]} FAILS
  (fn my-fn [x] {:post [(have? nil? %)]} nil) ; {:post [true]} passes as intended
sourceraw docstring

set-error-fn!clj/s

(set-error-fn! f)

Sets the root (fn [data-map-delay]) called on invariant violations.

Sets the root (fn [data-map-delay]) called on invariant violations.
sourceraw docstring

with-dynamic-assertion-datacljmacro

(with-dynamic-assertion-data data & body)

Executes body with dynamic assertion data bound to given value. This data will be included in any violation errors thrown by body.

Executes body with dynamic assertion data bound to given value.
This data will be included in any violation errors thrown by body.
sourceraw docstring

with-error-fncljmacro

(with-error-fn f & body)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close