/
result.clj
60 lines (50 loc) · 1.8 KB
/
result.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
58
59
60
(ns kaocha.result
(:require [clojure.spec.alpha :as s]))
(defn diff-test-result
"Subtract two clojure.test style summary maps."
[before after]
{::pass (apply - (map :pass [after before]))
::error (apply - (map :error [after before]))
::fail (apply - (map :fail [after before]))
::pending (apply - (map :pending [after before]))})
(defn sum
"Sum up kaocha result maps."
[& rs]
{::count (apply + (map #(::count % 0) rs))
::pass (apply + (map #(::pass % 0) rs))
::error (apply + (map #(::error % 0) rs))
::fail (apply + (map #(::fail % 0) rs))
::pending (apply + (map #(::pending % 0) rs))})
(s/fdef sum
:ret (s/keys :req [::count ::pass ::error ::fail ::pending]))
(declare testable-totals)
(defn totals
"Return a map of summed up results for a collection of testables."
[testables]
(apply sum (map testable-totals testables)))
(defn testable-totals
"Return a map of summed up results for a testable, including descendants."
[testable]
(if-let [testables (::tests testable)]
(merge testable (totals testables))
(merge (sum) testable)))
(s/fdef testable-totals
:ret (s/keys :req [::count ::pass ::error ::fail ::pending]))
(defn failed?
"Did this testable, or one of its children, fail or error?"
[testable]
(let [{::keys [error fail]} (testable-totals testable)]
(or (> error 0) (> fail 0))))
(defn failed-one?
"Did this testable fail or error, does not recurse."
[{::keys [error fail] :or {error 0 fail 0}}]
(or (> error 0) (> fail 0)))
(defn totals->clojure-test-summary
"Turn a kaocha-style result map into a clojure.test style summary map."
[totals]
{:type :summary
:test (::count totals)
:pass (::pass totals)
:fail (::fail totals)
:pending (::pending totals)
:error (::error totals)})