Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taoensso/truss
Assertions micro-library for Clojure/Script
https://github.com/taoensso/truss
assertions clojure clojure-spec clojurescript epl schema taoensso validation
Last synced: 3 months ago
JSON representation
Assertions micro-library for Clojure/Script
- Host: GitHub
- URL: https://github.com/taoensso/truss
- Owner: taoensso
- License: epl-1.0
- Created: 2015-11-05T04:44:50.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-06T09:15:33.000Z (9 months ago)
- Last Synced: 2024-05-19T05:04:43.909Z (9 months ago)
- Topics: assertions, clojure, clojure-spec, clojurescript, epl, schema, taoensso, validation
- Language: Clojure
- Homepage: https://www.taoensso.com/truss
- Size: 614 KB
- Stars: 296
- Watchers: 14
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-clojurescript - Truss
README
[**Documentation**](#documentation) | [Latest releases](#latest-releases) | [Get support][GitHub issues]# 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](https://clojure.org/about/spec), [core.typed](https://github.com/clojure/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
- `2024-09-07` `1.12.0`: [release info](../../releases/tag/v1.12.0)
[![Main tests][Main tests SVG]][Main tests URL]
[![Graal tests][Graal tests SVG]][Graal tests URL]See [here][GitHub releases] 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:
## Quick example
```clojure
(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](#documentation) below for more!
## Documentation
- [Wiki][GitHub wiki] (getting started, usage, etc.)
- API reference: [cljdoc][cljdoc docs] or [Codox][Codox docs]## Funding
You can [help support][sponsor] continued work on this project, thank you!! 🙏
## License
Copyright © 2014-2024 [Peter Taoussanis][].
Licensed under [EPL 1.0](LICENSE.txt) (same as Clojure).[GitHub releases]: ../../releases
[GitHub issues]: ../../issues
[GitHub wiki]: ../../wiki[Peter Taoussanis]: https://www.taoensso.com
[sponsor]: https://www.taoensso.com/sponsor[Codox docs]: https://taoensso.github.io/truss/
[cljdoc docs]: https://cljdoc.org/d/com.taoensso/truss/[Clojars SVG]: https://img.shields.io/clojars/v/com.taoensso/truss.svg
[Clojars URL]: https://clojars.org/com.taoensso/truss[Main tests SVG]: https://github.com/taoensso/truss/actions/workflows/main-tests.yml/badge.svg
[Main tests URL]: https://github.com/taoensso/truss/actions/workflows/main-tests.yml
[Graal tests SVG]: https://github.com/taoensso/truss/actions/workflows/graal-tests.yml/badge.svg
[Graal tests URL]: https://github.com/taoensso/truss/actions/workflows/graal-tests.yml