Skip to content

Commit f6bc05d

Browse files
authored
Merge pull request #417 from lambdaisland/laurence/fix-kaocha-416-casting-clojure-out-to-java-system-out
fix the issue from kaocha #416: casting *out* to System/out
2 parents f8775f2 + b85883d commit f6bc05d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/kaocha/api.clj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
;; Prevent clj-refactor from "cleaning" these from the ns form
1818
(require 'kaocha.monkey-patch)
1919

20-
(def orig-out *out*)
20+
;; Before orig-out was set to *out*, and unfortunately that will
21+
;; cause a ClassCastException.
22+
;; => "java.io.OutputStreamWriter cannot be cast to java.io.PrintStream"
23+
;; Explanation:
24+
;; The exception is because that when user interruption happens,
25+
;; Kaocha will force resetting printing to stdout. However, *out*
26+
;; is of class java.io.OutputStreamWriter, but System/out is of
27+
;; class java.io.PrintStream
28+
(def orig-out System/out)
29+
(def orig-err System/err)
2130

2231
(def ^:dynamic *active?*
2332
"Is Kaocha currently active? i.e. loading or runnning tests."
@@ -112,7 +121,7 @@
112121
(count (testable/test-seq-with-skipped test-plan))))
113122
(output/warn (str "No tests were found. This may be an issue in your Kaocha test configuration."
114123
" To investigate, check the :test-paths and :ns-patterns keys in tests.edn.")))
115-
(throw+ {:kaocha/early-exit 0 }))
124+
(throw+ {:kaocha/early-exit 0}))
116125

117126
(when (find-ns 'matcher-combinators.core)
118127
(require 'kaocha.matcher-combinators))
@@ -130,6 +139,8 @@
130139
;; still be in effect.
131140
(System/setOut
132141
orig-out)
142+
(System/setErr
143+
orig-err)
133144
(binding [history/*history* history]
134145
(t/do-report (history/clojure-test-summary)))
135146
(catch Throwable t

0 commit comments

Comments
 (0)