diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-05-01 04:23:28 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-05-19 20:43:52 -0400 |
commit | cb5dc129c84022e6430ce86baeca4e63dc6fce92 (patch) | |
tree | c7cb1852cc2da0dc88fa36794fad2e11cbc6a8c1 | |
parent | ea55e4c1169fc5cae36166bee80c41805e758872 (diff) |
test for #317
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | test/clojure/test_clojure/main.clj | 28 |
1 files changed, 27 insertions, 1 deletions
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)))"))))) |