Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Keep value and side-effecting printing separate

fixes NREPL-45
  • Loading branch information...
commit bbc5e02b665356e7dc33fe1d78346f17b3dec452 1 parent 93de0e0
@trptcolin trptcolin authored
View
8 src/main/clojure/clojure/tools/nrepl/middleware/pr_values.clj
@@ -20,11 +20,15 @@
(send [this resp]
(.send transport
(if-let [[_ v] (find resp :value)]
- (assoc resp :value (with-out-str (pr v)))
+ (let [repr (java.io.StringWriter.)]
+ (assoc resp :value (do (if *print-dup*
+ (print-dup v repr)
+ (print-method v repr))
+ (str repr))))
resp))
this))))))
(set-descriptor! #'pr-values
{:requires #{}
:expects #{}
- :handles {}})
+ :handles {}})
View
10 src/test/clojure/clojure/tools/nrepl_test.clj
@@ -104,6 +104,16 @@
combine-responses
:out))))
+(def-repl-test error-on-lazy-seq-with-side-effects
+ (let [expression '(defn foo [] (map (fn [x]
+ (println x)
+ (throw (Exception. "oops")))
+ [1 2 3]))
+ results (-> (repl-eval session (pr-str (list 'do expression '(foo))))
+ combine-responses)]
+ (is (= "1\n" (:out results)))
+ (is (re-seq #"oops" (:err results)))))
+
(def-repl-test cross-transport-*out*
(let [sid (-> session meta ::nrepl/taking-until :session)
transport2 (nrepl/connect :port (:port *server*))]
Please sign in to comment.
Something went wrong with that request. Please try again.