Skip to content

Commit 153a2d0

Browse files
jszakmeisterstuarthalloway
authored andcommitted
tap: handle :fail reports
Consolidated much of the reporting, since it was effectively duplicated across three functions after handling failures. Signed-off-by: Stuart Halloway <[email protected]>
1 parent 704b9e5 commit 153a2d0

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/clj/clojure/test/tap.clj

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,45 @@
6969
(println "not ok" msg))
7070

7171
;; This multimethod will override test/report
72-
(defmulti ^:dynamic tap-report (fn [data] (:type data)))
72+
(defmulti ^:dynamic tap-report :type)
7373

7474
(defmethod tap-report :default [data]
7575
(t/with-test-out
7676
(print-tap-diagnostic (pr-str data))))
7777

78+
(defn print-diagnostics [data]
79+
(when (seq t/*testing-contexts*)
80+
(print-tap-diagnostic (t/testing-contexts-str)))
81+
(when (:message data)
82+
(print-tap-diagnostic (:message data)))
83+
(print-tap-diagnostic (str "expected:" (pr-str (:expected data))))
84+
(if (= :pass (:type data))
85+
(print-tap-diagnostic (str " actual:" (pr-str (:actual data))))
86+
(do
87+
(print-tap-diagnostic
88+
(str " actual:"
89+
(with-out-str
90+
(if (instance? Throwable (:actual data))
91+
(stack/print-cause-trace (:actual data) t/*stack-trace-depth*)
92+
(prn (:actual data)))))))))
93+
7894
(defmethod tap-report :pass [data]
7995
(t/with-test-out
8096
(t/inc-report-counter :pass)
8197
(print-tap-pass (t/testing-vars-str data))
82-
(when (seq t/*testing-contexts*)
83-
(print-tap-diagnostic (t/testing-contexts-str)))
84-
(when (:message data)
85-
(print-tap-diagnostic (:message data)))
86-
(print-tap-diagnostic (str "expected:" (pr-str (:expected data))))
87-
(print-tap-diagnostic (str " actual:" (pr-str (:actual data))))))
98+
(print-diagnostics data)))
8899

89100
(defmethod tap-report :error [data]
90101
(t/with-test-out
91102
(t/inc-report-counter :error)
92103
(print-tap-fail (t/testing-vars-str data))
93-
(when (seq t/*testing-contexts*)
94-
(print-tap-diagnostic (t/testing-contexts-str)))
95-
(when (:message data)
96-
(print-tap-diagnostic (:message data)))
97-
(print-tap-diagnostic (str "expected:" (pr-str (:expected data))))
98-
(print-tap-diagnostic " actual: ")
99-
(print-tap-diagnostic
100-
(with-out-str
101-
(if (instance? Throwable (:actual data))
102-
(stack/print-cause-trace (:actual data) t/*stack-trace-depth*)
103-
(prn (:actual data)))))))
104+
(print-diagnostics data)))
105+
106+
(defmethod tap-report :fail [data]
107+
(t/with-test-out
108+
(t/inc-report-counter :fail)
109+
(print-tap-fail (t/testing-vars-str data))
110+
(print-diagnostics data)))
104111

105112
(defmethod tap-report :summary [data]
106113
(t/with-test-out

0 commit comments

Comments
 (0)