Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2017 15:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Prettifying Clojure test reports
; Prettify test reports
(ns unit.reporter
[clojure.test :refer [report with-test-out]]))
; Change the report multimethod to ignore namespaces that don't contain any tests.
; taken from:
(defmethod report :begin-test-ns [m]
(when (some #(:test (meta %)) (vals (ns-interns (:ns m))))
(println "\n-------====== Testing" (ns-name (:ns m)) "======-------"))))
; Report test names
(defmethod report :begin-test-var [m]
(println "\r\uD83C\uDF00 " (:verbose-name (meta (:var m))))))
(def ansi-reset "\u001B[0m")
(def ansi-bold "\u001B[1m")
(def ansi-red "\u001B[31m")
; Summary reporting with color
(defmethod report :summary [m]
(print ansi-bold)
(when (not (every? zero? [(:fail m) (:error m)]))
(print ansi-red))
(println "\nRan" (:test m) "tests containing"
(+ (:pass m) (:fail m) (:error m)) "assertions.")
(println (:fail m) "failures," (:error m) "errors."))
(print ansi-reset))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment