Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns user.dustin.minitest2
(:refer-clojure :exclude [test])
[meander.epsilon :as m]
[taoensso.timbre :refer [error]]))
(declare tests test!)
(def ^:dynamic *tests* (atom {}))
(defmacro tests [& body]
(swap! *tests* assoc (ns-name *ns*) '~body)
; if repl mode, just run them
(test!))) ; danger
(defn test!
([] (test! (ns-name *ns*)))
(let [parsed (m/rewrite (vec (get @*tests* ns))
[] []
[!xs ... '=> ?v & ?more]
[[[!xs ...] ?v] & (m/cata ?more)])]
(doseq [[forms expected] parsed]
(doseq [form forms]
(let [v (eval form)]
(set! *3 *2) (set! *2 *1) (set! *1 v)))
(let [e (eval expected)]
(if (= *1 e)
(println 'test 'passed (last forms) '=> expected)
(error 'test 'failed (last forms) '=> expected e)))
(catch Exception e
; continue
(error e)))))))
(inc 42) => 43
(inc 3) => 4
(inc 3) => 5
nil => nil
nil => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.