forked from ldnclj/Coloured-Balls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.clj
57 lines (48 loc) · 2.33 KB
/
tasks.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(use 'cake 'cake.core
'[cake.project :only [reload!]]
'[bake.find-namespaces :only [find-namespaces-in-dir]])
(import '[java.io File])
(deftask midje
"Run midje and clojure.test tests"
(bake (:use [bake.core :only [with-context]])
(:require [clojure test string])
[namespaces (concat (find-namespaces-in-dir (java.io.File. "test"))
(find-namespaces-in-dir (java.io.File. "src")))]
(with-context :test
;; This turns off "Testing ...." lines, which I hate, especially
;; when there's no failure output.
(defmethod clojure.test/report :begin-test-ns [m])
(alter-var-root (var clojure.test/*report-counters*)
(fn [_] (ref clojure.test/*initial-report-counters*)))
(doseq [n namespaces] (require n :reload))
(let [midje-passes (:pass @clojure.test/*report-counters*)
midje-fails (:fail @clojure.test/*report-counters*)
midje-failure-message
(condp = midje-fails
0 (format "All claimed facts (%d) have been confirmed." midje-passes)
1 (format "FAILURE: %d fact was not confirmed." midje-fails)
(format "FAILURE: %d facts were not confirmed." midje-fails))
potential-consolation
(condp = midje-passes
0 ""
1 "(But 1 was.)"
(format "(But %d were.)" midje-passes))
midje-consolation
(if (> midje-fails 0) potential-consolation "")
; Stashed clojure.test output
clojure-test-output-catcher
(java.io.StringWriter.)
clojure-test-result
(binding [clojure.test/*test-out* clojure-test-output-catcher]
(apply clojure.test/run-tests namespaces))
clojure-test-output
(-> clojure-test-output-catcher .toString clojure.string/split-lines)]
(when (> (+ (:fail clojure-test-result) (:error clojure-test-result))
0)
(println ">>> Output from clojure.test tests:")
(dorun (map println (drop-last 2 clojure-test-output))))
(when (> (:test clojure-test-result) 0)
(println ">>> clojure.test summary:")
(dorun (map println (take-last 2 clojure-test-output)))
(println ">>> Midje summary:"))
(println midje-failure-message midje-consolation)))))