Last active
June 10, 2020 17:25
-
-
Save dustingetz/f0cdcad7e6d804249624240c2a0870ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user.test | |
(:refer-clojure :exclude [test]) | |
(:require | |
[meander.epsilon :as m] | |
[taoensso.timbre :refer [error]])) | |
(def tests-enabled true) | |
(defmacro test [& body] | |
(when tests-enabled | |
(let [parsed (m/rewrite (vec body) | |
[] [] | |
[!xs ... '=> ?v & ?more] | |
[[[!xs ...] ?v] & (m/cata ?more)])] | |
(doseq [[forms expected] parsed] | |
(try | |
(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 (last forms) '=> expected 'passed) | |
(error 'test (last forms) '=> expected 'failed))) | |
(catch Throwable e | |
(error e))))))) | |
(test | |
1 | |
1 | |
1 | |
(inc 42) => 43 | |
(inc 3) => 4 | |
(inc 3) => 5 | |
nil => nil | |
nil => true | |
) |
Author
dustingetz
commented
Jun 10, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment