Skip to content

Commit

Permalink
tap: handle :fail reports
Browse files Browse the repository at this point in the history
Consolidated much of the reporting, since it was effectively duplicated
across three functions after handling failures.

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
jszakmeister authored and stuarthalloway committed May 19, 2012
1 parent 704b9e5 commit 153a2d0
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/clj/clojure/test/tap.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,45 @@
(println "not ok" msg))

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

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

(defn print-diagnostics [data]
(when (seq t/*testing-contexts*)
(print-tap-diagnostic (t/testing-contexts-str)))
(when (:message data)
(print-tap-diagnostic (:message data)))
(print-tap-diagnostic (str "expected:" (pr-str (:expected data))))
(if (= :pass (:type data))
(print-tap-diagnostic (str " actual:" (pr-str (:actual data))))
(do
(print-tap-diagnostic
(str " actual:"
(with-out-str
(if (instance? Throwable (:actual data))
(stack/print-cause-trace (:actual data) t/*stack-trace-depth*)
(prn (:actual data)))))))))

(defmethod tap-report :pass [data]
(t/with-test-out
(t/inc-report-counter :pass)
(print-tap-pass (t/testing-vars-str data))
(when (seq t/*testing-contexts*)
(print-tap-diagnostic (t/testing-contexts-str)))
(when (:message data)
(print-tap-diagnostic (:message data)))
(print-tap-diagnostic (str "expected:" (pr-str (:expected data))))
(print-tap-diagnostic (str " actual:" (pr-str (:actual data))))))
(print-diagnostics data)))

(defmethod tap-report :error [data]
(t/with-test-out
(t/inc-report-counter :error)
(print-tap-fail (t/testing-vars-str data))
(when (seq t/*testing-contexts*)
(print-tap-diagnostic (t/testing-contexts-str)))
(when (:message data)
(print-tap-diagnostic (:message data)))
(print-tap-diagnostic (str "expected:" (pr-str (:expected data))))
(print-tap-diagnostic " actual: ")
(print-tap-diagnostic
(with-out-str
(if (instance? Throwable (:actual data))
(stack/print-cause-trace (:actual data) t/*stack-trace-depth*)
(prn (:actual data)))))))
(print-diagnostics data)))

(defmethod tap-report :fail [data]
(t/with-test-out
(t/inc-report-counter :fail)
(print-tap-fail (t/testing-vars-str data))
(print-diagnostics data)))

(defmethod tap-report :summary [data]
(t/with-test-out
Expand Down

0 comments on commit 153a2d0

Please sign in to comment.