Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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 <stu@thinkrelevance.com>
  • Loading branch information...
commit 153a2d0f000ab2f254704e4970968fee6a0329a1 1 parent 704b9e5
@jszakmeister jszakmeister authored stuarthalloway committed
Showing with 25 additions and 18 deletions.
  1. +25 −18 src/clj/clojure/test/tap.clj
View
43 src/clj/clojure/test/tap.clj
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.