/
matcher_combinators.clj
59 lines (51 loc) · 2.52 KB
/
matcher_combinators.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
(ns kaocha.matcher-combinators
(:require [kaocha.report :as report]
[kaocha.output :as output]
[kaocha.hierarchy :as hierarchy]
[clojure.test :as t]
[lambdaisland.deep-diff :as ddiff]
[lambdaisland.deep-diff.printer :as printer]
[puget.printer :as puget]
[fipp.engine :as fipp]
[puget.color :as color]))
(def print-handlers {'matcher_combinators.model.Mismatch
(fn [printer expr]
(printer/print-mismatch printer {:- (:expected expr)
:+ (:actual expr)}))
'matcher_combinators.model.Missing
(fn [printer expr]
(printer/print-deletion printer {:- (:expected expr)}))
'matcher_combinators.model.Unexpected
(fn [printer expr]
(printer/print-insertion printer {:+ (:actual expr)}))
'matcher_combinators.model.FailedPredicate
(fn [printer expr]
[:group
[:align
(printer/print-other printer (:form expr))
(printer/print-insertion printer {:+ (:actual expr)})]])
'matcher_combinators.model.InvalidMatcherType
(fn [printer expr]
[:group
[:align
(color/document printer
::printer/other
[:span "-"
[:raw (:expected-type-msg expr)]])
(printer/print-insertion printer {:+ (:provided expr)})]])})
(run! #(apply printer/register-print-handler! %) print-handlers)
(defn fail-summary [{:keys [testing-contexts testing-vars] :as m}]
(let [printer (ddiff/printer {:print-color output/*colored-output*})]
(println (str "\n" (output/colored :red "FAIL") " in") (clojure.test/testing-vars-str m))
(when (seq t/*testing-contexts*)
(println (t/testing-contexts-str)))
(when-let [message (:message m)]
(println message))
(fipp/pprint-document
[:span
"Mismatch:" :line
[:nest (puget/format-doc printer (:markup m))]]
{:width (:width printer)})
(report/print-output m)))
(defmethod report/fail-summary :mismatch [m] (fail-summary m))
(defmethod report/fail-summary :matcher-combinators/mismatch [m] (fail-summary m))