forked from technomancy/leiningen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.clj
42 lines (39 loc) · 1.49 KB
/
test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns leiningen.test
"Run the project's tests."
(:refer-clojure :exclude [test])
(:use [clojure.test]
[clojure.contrib.java-utils :only [file]]
[clojure.contrib.find-namespaces :only [find-namespaces-in-dir]]
[leiningen.compile :only [eval-in-project]]))
(def report-fns
'(let [orig-report report
aggregates (ref [])]
(defn lein-report [event]
(when (= (:type event) :summary)
(dosync (commute aggregates conj event)))
(orig-report event))
(defn super-summary []
(with-test-out
(println "\n\n--------------------\nTotal:"))
(orig-report (apply merge-with (fn [a b]
(if (number? a)
(+ a b)
a))
@aggregates)))))
(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."
[project & namespaces]
;; TODO: System/exit appropriately (depends on Clojure ticket #193)
(let [namespaces (if (empty? namespaces)
(find-namespaces-in-dir (file (:root project) "test"))
(map symbol namespaces))]
(eval-in-project
project
`(do
(use ~''clojure.test)
~report-fns
(doseq [ns# '~namespaces]
(require ns#)
(binding [report ~'lein-report]
(run-tests ns#)))))))