A snapshot testing macro, shiny and chrome.
Quickly capture the behavior of arbitrary code, creating an enduring record in your source code.
Import Witness through an ns declaration.
(ns foo.bar (:require [dev.sparrows.witness :as w]))
;; Or
(ns foo.bar (:require [dev.sparrows.witness :refer [witness]]))
;; Or
(ns foo.bar (:require [dev.sparrows.witness]))
Then use the witness macro, which has 4 arities.
- 0-arity will load the source code file from disk, find all instances of 1-arity witness, and snapshots them into the 2-arity version.
- 1-arity loads the source file, finds all forms that looks like that one, and snapshots them into 2-arity calls.
- 2-arity macro-expands into a clojure.test that the two forms are equal. Loading and running the tests in the namespace is up to you.
- 3-arity takes a function as the first argument, and does clojure.test that the function returns true when called with the other two arguments. It's an escape hatch for more advanced assertions.
Witness is not named after a maddened leap for nothing! Keep the following in mind while using it.
- Unsaved changes in your file might be in your REPL state, but Witness can't see that.
- Make sure you can see Witness's changes by reloading if it 'doesn't do anything.'
- Witness evals code at compile time. This makes it a lot harder to keep your namespaces safely reloadable.
Copyright © 2025 Charlot Shaw
Distributed under the MIT license.