Documentation | Latest releases | Get support
Truss is a tiny Clojure/Script library that provides fast and flexible runtime assertions with terrific error messages. Use it as a complement or alternative to clojure.spec, core.typed, etc.
A doubtful friend is worse than a certain enemy. Let a man be one thing or the other, and we then know how to meet him. - Aesop
2024-09-07
1.12.0
: release infoSee here for earlier releases.
See for intro and usage:
(require '[taoensso.truss :as truss :refer [have have?]])
;; Truss uses the simple `(predicate arg)` pattern familiar to Clojure users:
(defn square [n]
(let [n (have integer? n)] ; <- A Truss assertion
(* n n)))
;; This assertion basically expands to:
;; (if (integer? n) n (throw-detailed-assertion-error!))
(square 5) ; => 25
(square nil) ; =>
;; Invariant failed at truss-examples[9,11]: (integer? n)
;; {:dt #inst "2023-07-31T09:56:10.295-00:00",
;; :pred clojure.core/integer?,
;; :arg {:form n, :value nil, :type nil},
;; :env {:elidable? true, :*assert* true},
;; :loc
;; {:ns truss-examples,
;; :line 9,
;; :column 11,
;; :file "examples.cljc"}}
;; Assert inside collections using `:in`:
(have string? :in ["don't" "panic"])
That's everything most users will need to know, but see the documentation below for more!
You can help support continued work on this project, thank you!! 🙏
Copyright © 2014-2024 Peter Taoussanis.
Licensed under EPL 1.0 (same as Clojure).