Skip to content

Commit 4519f16

Browse files
committed
Fix a regression in test results formatting.
The changes introduced in #683 resulted in test results always being printed via println instead of clojure.pprint/pprint. BetterThanTomorrow/calva#1280 describes the degraded user experience caused by this issue. This PR limits println usage to matchers-combinators results.
1 parent ebe962a commit 4519f16

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/cider/nrepl/middleware/test.clj

+7-5
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@
6868
first))))
6969

7070
(defn- print-object
71-
"Print `object` using pprint or a custom print-method, if available."
71+
"Print `object` using println for matcher-combinators results and pprint
72+
otherwise."
7273
[object]
73-
(let [print-fn (if (= (get-method print-method (:type (meta object)))
74-
(get-method print-method :default))
75-
pp/pprint
76-
println)]
74+
(let [matcher-combinators-result? (= (:type (meta object))
75+
:matcher-combinators.clj-test/mismatch)
76+
print-fn (if matcher-combinators-result?
77+
println
78+
pp/pprint)]
7779
(with-out-str (print-fn object))))
7880

7981
(def ^:dynamic *test-error-handler*

test/clj/cider/nrepl/middleware/test_test.clj

+10-9
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,17 @@
159159
first
160160
:message))))))
161161

162-
(defmethod clojure.core/print-method ::custom [_ out]
163-
(binding [*out* out]
164-
(print "custom-output")))
165-
166162
(deftest print-object-test
167-
(testing "use an object's print-method when applicable, otherwise invoke pprint"
168-
(is (= "custom-output\n"
169-
(#'test/print-object (with-meta {:not :printed} {:type ::custom}))))
170-
(is (= "{:a :b, :c :d}\n"
171-
(#'test/print-object {:a :b :c :d})))))
163+
(testing "uses println for matcher-combinators results, otherwise invokes pprint"
164+
(is (= "{no quotes}\n"
165+
(#'test/print-object (with-meta {"no" "quotes"} {:type :matcher-combinators.clj-test/mismatch})))
166+
"println is chosen, as indicated by strings printed without quotes")
167+
(is (= "{:a\n (\"a-sufficiently-long-string\"\n \"a-sufficiently-long-string\"\n \"a-sufficiently-long-string\")}\n"
168+
(#'test/print-object {:a (repeat 3 "a-sufficiently-long-string")}))
169+
"pprint is chosen, as indicated by quoted strings and newlines")
170+
(is (= "{:a \"b\", :c \"42\"}\n"
171+
(#'test/print-object (with-meta {:a "b" :c "42"} {:type ::mismatch})))
172+
"pprint is chosen, because :type does not match matchers-combinators keyword")))
172173

173174
(deftest test-result-test
174175
(testing "It passes `:error`s to `test/*test-error-handler*`"

0 commit comments

Comments
 (0)