-
-
Save ghoseb/286631 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn tests [] | |
[{:name 'suiteA | |
:total 3 | |
:passed (promise) | |
:failed (promise) | |
:success (promise) | |
:tests [{:name 'testA :success (promise)} | |
{:name 'testB :success (promise)} | |
{:name 'testC :success (promise)}]} | |
{:name 'suiteB | |
:total 3 | |
:passed (promise) | |
:failed (promise) | |
:success (promise) | |
:tests [{:name 'testD :success (promise)} | |
{:name 'testE :success (promise)} | |
{:name 'testF :success (promise)}]}]) | |
(defmacro future-out [& body] | |
`(let [out# *out*] | |
(future | |
(binding [*out* out#] | |
~@body)))) | |
(def dummy-results | |
{'testA 0 | |
'testB 1 | |
'testC 0 | |
'testD 1 | |
'testE 1 | |
'testF 0}) | |
(defn run-test [test] | |
(deliver (:success test) (dummy-results (:name test))) | |
test) | |
(defn prepare-tests [tests] | |
(loop [test (first tests), tests (rest tests), torun []] | |
(if (nil? test) | |
torun | |
(if (:tests test) | |
(let [subtests (prepare-tests (:tests test))] | |
(future-out | |
(deliver (:passed test) (reduce + (map #(deref (:success %)) subtests))) | |
(deliver (:failed test) (- (:total test) (deref (:passed test)))) | |
(deliver (:success test) (= (:total test) (deref (:passed test)))) | |
(println (:name test) | |
"passed" (deref (:passed test)) | |
"failed" (deref (:failed test)) | |
"total" (:total test))) | |
(recur (first tests) (rest tests) (concat torun subtests))) | |
(do | |
(future-out | |
(println (:name test) | |
"passed" (deref (:success test)))) | |
(recur (first tests) | |
(rest tests) | |
(if (nil? (:tests test)) | |
(conj torun test) | |
torun))))))) | |
(defn run [tests] | |
(for [test (prepare-tests tests)] | |
(run-test test))) | |
(comment | |
(run (tests))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment