|
9 | 9 | [clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
|
10 | 10 | [leiningen.compile :only [eval-in-project]]))
|
11 | 11 |
|
| 12 | +(defn form-for-testing-namespaces |
| 13 | + "Return a form that when eval'd in the context of the project will test |
| 14 | +each namespace and print an overall summary." |
| 15 | + [namespaces] |
| 16 | + `(do (use ~''clojure.test) |
| 17 | + (let [add-numbers# (fn [a# b#] (if (number? a#) |
| 18 | + (+ a# b#) a#)) |
| 19 | + summary# (reduce (fn [summary# n#] |
| 20 | + (require n# :reload-all) |
| 21 | + (merge-with add-numbers# |
| 22 | + summary# (run-tests n#))) |
| 23 | + {} '~namespaces)] |
| 24 | + (with-test-out |
| 25 | + (println "\n\n--------------------\nTotal:") |
| 26 | + (report summary#))))) |
| 27 | + |
12 | 28 | (defn test
|
13 | 29 | "Run the project's tests. Accept a list of namespaces for which to run all
|
14 | 30 | tests for. If none are given, runs them all."
|
15 | 31 | [project & namespaces]
|
16 | 32 | (let [namespaces (if (empty? namespaces)
|
17 | 33 | (find-namespaces-in-dir (file (:test-path project)))
|
18 | 34 | (map symbol namespaces))]
|
19 |
| - ;; It's long and a bit hairy because it has to be self-contained. |
20 |
| - (eval-in-project |
21 |
| - project |
22 |
| - `(do (use ~''clojure.test) |
23 |
| - (let [add-numbers# (fn [a# b#] (if (number? a#) |
24 |
| - (+ a# b#) a#)) |
25 |
| - summary# (reduce (fn [summary# n#] |
26 |
| - (require n#) |
27 |
| - (merge-with add-numbers# |
28 |
| - summary# (run-tests n#))) |
29 |
| - {} '~namespaces)] |
30 |
| - (with-test-out |
31 |
| - (println "\n\n--------------------\nTotal:") |
32 |
| - (report summary#) |
33 |
| - (System/setProperty "leiningen.test" (str false) |
34 |
| - ;; (successful? summary#) |
35 |
| - ))))) |
| 35 | + (eval-in-project project (form-for-testing-namespaces namespaces)) |
36 | 36 | (println (System/getProperty "leiningen.test"))))
|
0 commit comments