|
63 | 63 | (filter #(= (:class %) (.getName (class f))))
|
64 | 64 | (first)))
|
65 | 65 |
|
| 66 | +(defn- print-object [object] |
| 67 | + (let [print-fn (if (= (get-method print-method (:type (meta object))) |
| 68 | + (get-method print-method :default)) |
| 69 | + pp/pprint |
| 70 | + println)] |
| 71 | + (with-out-str (print-fn object)))) |
| 72 | + |
66 | 73 | (defn test-result
|
67 | 74 | "Transform the result of a test assertion. Append ns, var, assertion index,
|
68 |
| - and 'testing' context. Retain any exception. Pretty-print expected/actual." |
| 75 | + and 'testing' context. Retain any exception. Pretty-print expected/actual or |
| 76 | + use its `print-method`, if applicable." |
69 | 77 | [ns v m]
|
70 | 78 | (let [{:keys [actual diffs expected fault]
|
71 | 79 | t :type} m
|
72 | 80 | c (when (seq test/*testing-contexts*) (test/testing-contexts-str))
|
73 | 81 | i (count (get-in (@current-report :results) [ns (:name (meta v))]))
|
74 |
| - gen-input (:gen-input @current-report) |
75 |
| - pprint-str #(with-out-str (pp/pprint %))] |
| 82 | + gen-input (:gen-input @current-report)] |
| 83 | + |
76 | 84 | ;; Errors outside assertions (faults) do not return an :expected value.
|
77 | 85 | ;; Type :fail returns :actual value. Type :error returns :error and :line.
|
78 | 86 | (merge (dissoc m :expected :actual)
|
79 | 87 | {:ns ns, :var (:name (meta v)), :index i, :context c}
|
80 | 88 | (when (and (#{:fail :error} t) (not fault))
|
81 |
| - {:expected (pprint-str expected)}) |
| 89 | + {:expected (print-object expected)}) |
82 | 90 | (when (and (#{:fail} t) gen-input)
|
83 |
| - {:gen-input (pprint-str gen-input)}) |
| 91 | + {:gen-input (print-object gen-input)}) |
84 | 92 | (when (#{:fail} t)
|
85 |
| - {:actual (pprint-str actual)}) |
| 93 | + {:actual (print-object actual)}) |
86 | 94 | (when diffs
|
87 | 95 | {:diffs (extensions/diffs-result diffs)})
|
88 | 96 | (when (#{:error} t)
|
|
0 commit comments