Separate version check from form generator; add an optional test-package argument to the from generator.
This commit is contained in:
parent
b19d46b6d0
commit
d11eae7451
1 changed files with 34 additions and 25 deletions
|
@ -5,39 +5,48 @@
|
||||||
[clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
|
[clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
|
||||||
[leiningen.compile :only [eval-in-project]]))
|
[leiningen.compile :only [eval-in-project]]))
|
||||||
|
|
||||||
|
(defn- with-version-guard
|
||||||
|
"Compatibility test to prevent use of clojure.test with Clojure 1.0."
|
||||||
|
[form]
|
||||||
|
`(if (and (= 1 (:major *clojure-version*))
|
||||||
|
(= 0 (:minor *clojure-version*)))
|
||||||
|
(println "\"lein test\" is not compatible with Clojure 1.0 projects.
|
||||||
|
Please consider upgrading to a newer version of Clojure or using"
|
||||||
|
"the lein-test-is plugin.")
|
||||||
|
~form))
|
||||||
|
|
||||||
(defn form-for-testing-namespaces
|
(defn form-for-testing-namespaces
|
||||||
"Return a form that when eval'd in the context of the project will test
|
"Return a form that when eval'd in the context of the project will test
|
||||||
each namespace and print an overall summary."
|
each namespace and print an overall summary."
|
||||||
[namespaces]
|
([namespaces] (form-for-testing-namespaces namespaces 'clojure.test))
|
||||||
`(do
|
([namespaces test-package]
|
||||||
(require ~''clojure.test)
|
`(do
|
||||||
(if (and (= 1 (:major *clojure-version*))
|
(require '~test-package)
|
||||||
(= 0 (:minor *clojure-version*)))
|
(let [resolver# (fn [fname#]
|
||||||
(println "\"lein test\" is not compatible with Clojure 1.0.\n
|
(ns-resolve
|
||||||
Please consider upgrading to a newer version of Clojure or using"
|
(find-ns '~test-package) fname#))
|
||||||
"the lein-test-is plugin.")
|
add-numbers# (fn [a# b#] (if (number? a#)
|
||||||
(let [resolver# (fn [fname#]
|
(+ a# b#) a#))
|
||||||
(ns-resolve
|
summary# (reduce (fn [summary# n#]
|
||||||
(find-ns 'clojure.test) fname#))
|
(require n# :reload-all)
|
||||||
add-numbers# (fn [a# b#] (if (number? a#)
|
(merge-with add-numbers#
|
||||||
(+ a# b#) a#))
|
summary#
|
||||||
summary# (reduce (fn [summary# n#]
|
((resolver# ~''run-tests) n#)))
|
||||||
(require n# :reload-all)
|
{} '~namespaces)]
|
||||||
(merge-with add-numbers#
|
((resolver# ~''with-test-out)
|
||||||
summary#
|
|
||||||
((resolver# ~''run-tests) n#)))
|
|
||||||
{} '~namespaces)]
|
|
||||||
((resolver# ~''with-test-out)
|
|
||||||
(println "\n\n--------------------\nTotal:")
|
(println "\n\n--------------------\nTotal:")
|
||||||
((resolver# ~''report) summary#))
|
((resolver# ~''report) summary#))
|
||||||
(when-not (= "1.5" (System/getProperty "java.specification.version"))
|
(when-not (= "1.5" (System/getProperty "java.specification.version"))
|
||||||
(shutdown-agents))))))
|
(shutdown-agents))))))
|
||||||
|
|
||||||
(defn test
|
(defn test
|
||||||
"Run the project's tests. Accept a list of namespaces for which to run all
|
"Run the project's tests. Accepts a list of namespaces for which to run all
|
||||||
tests for. If none are given, runs them all."
|
tests. If none are given, runs them all."
|
||||||
[project & namespaces]
|
[project & namespaces]
|
||||||
(let [namespaces (if (empty? namespaces)
|
(let [namespaces (if (empty? namespaces)
|
||||||
(find-namespaces-in-dir (file (:test-path project)))
|
(find-namespaces-in-dir (file (:test-path project)))
|
||||||
(map symbol namespaces))]
|
(map symbol namespaces))]
|
||||||
(eval-in-project project (form-for-testing-namespaces namespaces))))
|
(eval-in-project
|
||||||
|
project
|
||||||
|
(with-version-guard
|
||||||
|
(form-for-testing-namespaces namespaces)))))
|
||||||
|
|
Loading…
Reference in a new issue