Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created January 24, 2010 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save swannodette/284957 to your computer and use it in GitHub Desktop.
Save swannodette/284957 to your computer and use it in GitHub Desktop.
(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