Last active
August 29, 2015 13:56
-
-
Save mwmitchell/8890906 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 truth.core) | |
(defn get-data [] | |
{:data {:name {:first "matt"}}}) | |
(defmacro truth [lbl val tests redefs] | |
(loop [t tests] | |
(if-not (seq t) | |
true | |
`(with-redefs [~@(mapcat identity redefs)] | |
(if-not (-> ~val ~(first t)) | |
(format "[%s] failed on: (-> %s %s)" ~lbl '~val '~(first t)) | |
(truth ~lbl ~val ~(rest t) ~redefs)))))) | |
;; Run through each test form, one at a time - | |
;; applying the `val` to the form as (-> `val` `test-form`). | |
;; If one fails, throw an exception and include | |
;; the form in the error message | |
(truth "get-data looks good" (get-data) | |
[map? | |
(-> :data :name :first (string?))] | |
{map? (fn [_] true)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment