Awesome
<a href="https://www.taoensso.com/clojure" title="More stuff by @ptaoussanis at www.taoensso.com"><img src="https://www.taoensso.com/open-source.png" alt="Taoensso open source" width="340"/></a>
Documentation | Latest releases | Get support
Truss
Assertions micro-library for Clojure/Script
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.
<img width="600" src="../../blob/master/hero.png" alt="Egyptian ship with rope truss, the oldest known use of trusses (about 1250 BC)."/>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
Latest release/s
2024-09-07
1.12.0
: release info
See here for earlier releases.
Why Truss?
- Tiny cross-platform Clj/s codebase with zero dependencies
- Trivially easy to learn, use, and understand
- Terrific error messages for quick+easy debugging
- Terrific performance: miniscule (!) runtime cost
- Easy elision for zero runtime cost
- No commitment or costly buy-in: use it just when+where needed
- Perfect for library authors: no bulky dependencies
Video demo
See for intro and usage:
<a href="https://www.youtube.com/watch?v=gMB4Y-EIArA" target="_blank"> <img src="https://img.youtube.com/vi/gMB4Y-EIArA/maxresdefault.jpg" alt="Truss demo video" width="480" border="0" /> </a>Quick example
(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!
Documentation
Funding
You can help support continued work on this project, thank you!! 🙏
License
Copyright © 2014-2024 Peter Taoussanis.
Licensed under EPL 1.0 (same as Clojure).