Factor out form-for-testing-namespaces for other plugins to use.

This commit is contained in:
Phil Hagelberg 2010-01-30 22:43:07 -08:00
parent 3a659941f8
commit a9936d22b7

View file

@ -9,6 +9,22 @@
[clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
[leiningen.compile :only [eval-in-project]]))
(defn form-for-testing-namespaces
"Return a form that when eval'd in the context of the project will test
each namespace and print an overall summary."
[namespaces]
`(do (use ~''clojure.test)
(let [add-numbers# (fn [a# b#] (if (number? a#)
(+ a# b#) a#))
summary# (reduce (fn [summary# n#]
(require n# :reload-all)
(merge-with add-numbers#
summary# (run-tests n#)))
{} '~namespaces)]
(with-test-out
(println "\n\n--------------------\nTotal:")
(report summary#)))))
(defn test
"Run the project's tests. Accept a list of namespaces for which to run all
tests for. If none are given, runs them all."
@ -16,21 +32,5 @@ tests for. If none are given, runs them all."
(let [namespaces (if (empty? namespaces)
(find-namespaces-in-dir (file (:test-path project)))
(map symbol namespaces))]
;; It's long and a bit hairy because it has to be self-contained.
(eval-in-project
project
`(do (use ~''clojure.test)
(let [add-numbers# (fn [a# b#] (if (number? a#)
(+ a# b#) a#))
summary# (reduce (fn [summary# n#]
(require n#)
(merge-with add-numbers#
summary# (run-tests n#)))
{} '~namespaces)]
(with-test-out
(println "\n\n--------------------\nTotal:")
(report summary#)
(System/setProperty "leiningen.test" (str false)
;; (successful? summary#)
)))))
(eval-in-project project (form-for-testing-namespaces namespaces))
(println (System/getProperty "leiningen.test"))))