summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clj/clojure/core.clj4
-rw-r--r--src/clj/clojure/main.clj7
-rw-r--r--test/clojure/test_clojure/main.clj28
3 files changed, 35 insertions, 4 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 70d83348..4c466c56 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -5334,9 +5334,9 @@
(if-let [s (seq coll)]
(reduce f (first s) (next s))
(f)))
- ([f start coll]
+ ([f val coll]
(let [s (seq coll)]
- (clojure.core.protocols/internal-reduce s f start))))
+ (clojure.core.protocols/internal-reduce s f val))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; futures (needs proxy);;;;;;;;;;;;;;;;;;
(defn future-call
diff --git a/src/clj/clojure/main.clj b/src/clj/clojure/main.clj
index 1af45bf8..e607440c 100644
--- a/src/clj/clojure/main.clj
+++ b/src/clj/clojure/main.clj
@@ -198,7 +198,12 @@
(prompt)
(flush)
(loop []
- (when-not (= (read-eval-print) request-exit)
+ (when-not
+ (try (= (read-eval-print) request-exit)
+ (catch Throwable e
+ (caught e)
+ (set! *e e)
+ nil))
(when (need-prompt)
(prompt)
(flush))
diff --git a/test/clojure/test_clojure/main.clj b/test/clojure/test_clojure/main.clj
index 3a552b72..8c5f098c 100644
--- a/test/clojure/test_clojure/main.clj
+++ b/test/clojure/test_clojure/main.clj
@@ -10,7 +10,8 @@
(ns clojure.test-clojure.main
- (:use clojure.test))
+ (:use clojure.test)
+ (:require [clojure.main :as main]))
(deftest eval-opt
(testing "evals and prints forms"
@@ -22,3 +23,28 @@
(testing "does not block access to *in* (#299)"
(with-in-str "(+ 1 1)"
(is (= "(+ 1 1)\n" (with-out-str (#'clojure.main/eval-opt "(read)")))))))
+
+(defmacro with-err-str
+ "Evaluates exprs in a context in which *err* is bound to a fresh
+ StringWriter. Returns the string created by any nested printing
+ calls."
+ [& body]
+ `(let [s# (new java.io.StringWriter)
+ p# (new java.io.PrintWriter s#)]
+ (binding [*err* p#]
+ ~@body
+ (str s#))))
+
+(defn run-repl-and-return-err
+ "Run repl, swallowing stdout and returing stderr."
+ [in-str]
+ (with-err-str
+ (with-out-str
+ (with-in-str in-str
+ (main/repl)))))
+
+(deftest repl-exception-safety
+ (testing "catches and prints exception on bad equals"
+ (is (= "java.lang.NullPointerException\n"
+ (run-repl-and-return-err
+ "(proxy [Object] [] (equals [o] (.toString nil)))")))))