/
progress.clj
55 lines (45 loc) · 1.75 KB
/
progress.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
(ns kaocha.report.progress
(:require [clojure.test :as t]
[progrock.core :as pr]
[kaocha.testable :as testable]
[kaocha.output :as output]
[kaocha.report :as report]
[kaocha.hierarchy :as hierarchy]))
(def bar (atom nil))
(defn format-bar [{:keys [label label-width failed?] :as bar}]
(str (format (str "%" label-width "s") label)
": :percent% ["
(output/colored (if failed? :red :green) ":bar")
"] :progress/:total"))
(defn print-bar []
(t/with-test-out
(pr/print @bar {:format (format-bar @bar)})))
(defmulti progress :type :hierarchy #'hierarchy/hierarchy)
(defmethod progress :default [_])
(defmethod progress :begin-test-suite [m]
(let [testable (:kaocha/testable m)
test-plan (:kaocha/test-plan m)
leaf-tests (->> testable
testable/test-seq
(filter hierarchy/leaf?))]
(reset! bar (assoc (pr/progress-bar (count leaf-tests))
:label (name (:kaocha.testable/id testable))
:label-width (->> test-plan
:kaocha.test-plan/tests
(remove :kaocha.testable/skip)
(map (comp count name :kaocha.testable/id))
(apply max))))
(print-bar)))
(defmethod progress :end-test-var [m]
(swap! bar pr/tick)
(print-bar))
(defmethod progress :end-test-suite [m]
(swap! bar assoc :done? true)
(print-bar))
(defmethod progress :kaocha/fail-type [m]
(swap! bar assoc :failed? true)
(print-bar))
(defmethod progress :error [m]
(swap! bar assoc :failed? true)
(print-bar))
(def report [progress report/result])