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-dataclj/s

(get-data)

Returns current value of dynamic assertion data.

Returns current value of dynamic assertion data.
raw docstring

get-dynamic-assertion-dataclj/sdeprecated

(get-dynamic-assertion-data)

Prefer get-data

Prefer `get-data`
raw docstring

havecljmacro

(have x)
(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"})

Re: use of Truss assertions within other macro bodies: Due to CLJ-865, call site information (e.g. line number) of outer macro will unfortunately be lost.

See keep-callsite util for a workaround.

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"})`

Re: use of Truss assertions within other macro bodies:
  Due to CLJ-865, call site information (e.g. line number) of
  outer macro will unfortunately be lost.

  See `keep-callsite` util for a workaround.

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

have!cljmacro

(have! x)
(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).
raw docstring

have!?cljmacro

(have!? x)
(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.
raw docstring

have?cljmacro

(have? x)
(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
raw docstring

keep-callsitecljmacro

(keep-callsite & body)

CLJ-865 unfortunately means that it's currently not possible for an inner macro to access the &form metadata of an outer macro.

This means that inner macros lose call site information like the line number of the outer macro.

This util offers a workaround to macro authors:

(defmacro foo1 [x] (truss/have ~x)) ; W/o line info (defmacro foo2 [x] (keep-callsite(truss/have ~x))) ; With line info

CLJ-865 unfortunately means that it's currently not possible
for an inner macro to access the &form metadata of an outer macro.

This means that inner macros lose call site information like the
line number of the outer macro.

This util offers a workaround to macro authors:

  (defmacro foo1 [x]                `(truss/have ~x))  ; W/o  line info
  (defmacro foo2 [x] (keep-callsite `(truss/have ~x))) ; With line info
raw 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.
raw docstring

with-datacljmacro

(with-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.
raw docstring

with-dynamic-assertion-datacljmacrodeprecated

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

Prefer with-data

Prefer `with-data`
raw docstring

with-error-fncljmacro

(with-error-fn f & body)

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

× close