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.
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
2023-07-31
1.11.0
: changes
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
Quickstart
1. Add the relevant dependency to your project:
Leiningen: [com.taoensso/truss "x-y-z"] ; or
deps.edn: com.taoensso/truss {:mvn/version "x-y-z"}
2. Setup your namespace imports:
(ns my-ns (:require [taoensso.truss :as truss :refer [have have?]]))
3. 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/truss_examples.cljc"}}
That's everything most users will need to know, but see the documentation for more.
Documentation
- Full documentation (detailed usage, etc.)
- Auto-generated API reference: Codox, clj-doc
Motivation
See here for more.
Funding
You can help support continued work on this project, thank you!! 🙏
License
Copyright © 2014-2023 Peter Taoussanis.
Licensed under EPL 1.0 (same as Clojure).