Skip to content

Commit a9936d2

Browse files
committed
Factor out form-for-testing-namespaces for other plugins to use.
1 parent 3a65994 commit a9936d2

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/leiningen/test.clj

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
[clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
1010
[leiningen.compile :only [eval-in-project]]))
1111

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+
1228
(defn test
1329
"Run the project's tests. Accept a list of namespaces for which to run all
1430
tests for. If none are given, runs them all."
1531
[project & namespaces]
1632
(let [namespaces (if (empty? namespaces)
1733
(find-namespaces-in-dir (file (:test-path project)))
1834
(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))
3636
(println (System/getProperty "leiningen.test"))))

0 commit comments

Comments
 (0)