Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
93 lines (79 sloc) 2.69 KB
; Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
; All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(:refer-clojure :exclude [pr-str println await])
(:require [clojure.pprint :as pprint]))
(def ^:private serializer (agent nil))
(defn await
"Wait for everything sent to the serializer"
(send-off serializer (fn [_]))
(clojure.core/await serializer))
(defn serialized
"Returns a function that calls f for side effects, async,
serialized by an agent"
([f] (serialized f serializer))
([f agt]
(fn [& args]
(send-off agt
(fn [_]
(apply f args)
(catch Throwable t
(.printStackTrace t)))
;; TODO set from Java property?
(def ^:private event-print-length 100)
(def ^:private event-print-level 10)
(defn pr-str
"Print with event print settings"
(binding [*print-length* event-print-length
*print-level* event-print-level]
(clojure.core/pr-str s)))
(def println
"threadsafe print with event print settings"
(serialized clojure.core/println))
(def pprint
"threadsafe pprint with event print settings"
(fn [s]
(binding [*print-length* event-print-length
*print-level* event-print-level]
(pprint/pprint s)
(def report-hierarchy
#(apply derive %1 %2)
[[:test/iter :ignore]
[:test/seed :ignore]
[:test/pass :ignore]
[:assert/pass :ignore]
[:assert/summary :ignore]]))
(defmulti console-reporter :type :hierarchy #'report-hierarchy)
(defmethod console-reporter :ignore [_])
(defmethod console-reporter :test/test
[{:keys [tags msec count] :as m}]
(when (and (get tags :end) count)
(println (select-keys m [:msec :test/result :name :count]))))
(defmethod console-reporter :test/group
[{:keys [name tags]}]
(when-not (get tags :end)
(println (str "\n" name"\n"))))
(defmethod console-reporter :test/library
[{:keys [name]}]
(println (str "\n"
(apply str (repeat 60 "="))
"\nRunning " name " tests\n")))
(defmethod console-reporter :default [m]
(when-let [^Throwable t (:exception m)]
(send-off serializer (fn [_] (.printStackTrace t))))
(pprint m))
Jump to Line
Something went wrong with that request. Please try again.