Skip to content

Commit 9dbf1aa

Browse files
plexusbbatsov
authored andcommitted
Clojure 1.10 REPL exception and error message changes
Clojure 1.10 saw changes in how certain errors are reported, in particular reader/compiler related errors that happen at the REPL. Since CIDER is based on a REPL interface, this changes the errors that CIDER sees. Split the tests in separate 1.9 / 1.10 branches where appropriate.
1 parent fa592ca commit 9dbf1aa

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

test/clj/cider/nrepl/middleware/inspect_test.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@
7676
:code "(first 1)"})]
7777

7878
(testing "exprs that throw exceptions return an `ex` slot"
79-
(is (= "class java.lang.Exception"
80-
(:ex exception-response))))))
79+
(is (= "class java.lang.IllegalArgumentException"
80+
(:ex exception-response))))
81+
82+
;;TODO: The :err slot is missing when running this through the Cider test-runner
83+
(testing "exprs that throw exceptions return an `err` slot"
84+
(is (.contains (:err exception-response)
85+
"IllegalArgumentException")))))
8186

8287
(testing "inspect-pop error handling"
8388
(with-redefs [i/swap-inspector! (fn [& _] (throw (Exception. "pop exception")))]

test/clj/cider/nrepl/middleware/pprint_test.clj

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@
8484
:pprint "true"
8585
:pprint-fn "cider.nrepl.middleware.pprint/fipp-pprint"}]
8686
(is (= "{nil [nil nil nil #{nil} nil nil nil]}\n"
87-
(:pprint-out (session/message message))))))
87+
(:pprint-out (session/message message)))))))
8888

89+
(deftest wrap-pprint-custom-pprint-fn-test
8990
(testing "fipp-pprint respects the :print-meta slot"
9091
(is (= "^{:a :b}\n{}\n"
9192
(:pprint-out (session/message {:op :eval
@@ -122,8 +123,9 @@
122123
:code "^{:a :b} {}"
123124
:pprint "true"
124125
:pprint-fn "cider.nrepl.middleware.pprint/fipp-pprint"
125-
:print-meta "true"})))))
126+
:print-meta "true"}))))))
126127

128+
(deftest ^{:max-clj-version "1.9.0"} wrap-pprint-resolve-pprint-fn-1.9-test
127129
(testing "non-resolvable pprint-fn"
128130
(testing "non-existing ns"
129131
(let [response (session/message {:op :eval
@@ -154,3 +156,38 @@
154156
(is (= (:ex response) "class java.lang.NullPointerException"))
155157
(is (= (:root-ex response) "class java.lang.NullPointerException"))
156158
(is (.startsWith (:err response) "NullPointerException clojure.lang.Var.find"))))))
159+
160+
(deftest ^{:min-clj-version "1.10.0"} wrap-pprint-resolve-pprint-fn-1.10-test
161+
(testing "non-resolvable pprint-fn"
162+
(testing "non-existing ns"
163+
(let [response (session/message {:op :eval
164+
:code "nil"
165+
:pprint "true"
166+
:pprint-fn "never-used-ns-example/pprint"})]
167+
(is (= (:status response) #{"eval-error" "done"}))
168+
(is (= (:ex response) "class clojure.lang.ExceptionInfo"))
169+
(is (= (:root-ex response) "class java.lang.IllegalArgumentException"))
170+
171+
(is (.startsWith (:err response) "Error printing return value (IllegalArgumentException) at clojure.lang.Var/find "))
172+
(is (.contains (:err response) "No such namespace: never-used-ns-example"))))
173+
174+
(testing "non-existing Var"
175+
(let [response (session/message {:op :eval
176+
:code "nil"
177+
:pprint "true"
178+
:pprint-fn "clojure.core/never-used-pprint-example"})]
179+
(is (= (:status response) #{"eval-error" "done"}))
180+
(is (= (:ex response) "class clojure.lang.ExceptionInfo"))
181+
(is (= (:root-ex response) "class java.lang.IllegalArgumentException"))
182+
(is (.startsWith (:err response) "Error printing return value (IllegalArgumentException) at cider.nrepl.middleware.pprint/resolve-pprint-fn"))
183+
(is (.contains (:err response) "clojure.core/never-used-pprint-example is not resolvable to a var"))))
184+
185+
(testing "nil input"
186+
(let [response (session/message {:op :eval
187+
:code "nil"
188+
:pprint "true"
189+
:pprint-fn nil})]
190+
(is (= (:status response) #{"eval-error" "done"}))
191+
(is (= (:ex response) "class clojure.lang.ExceptionInfo"))
192+
(is (= (:root-ex response) "class java.lang.NullPointerException"))
193+
(is (.startsWith (:err response) "Error printing return value (NullPointerException) at clojure.lang.Var/find"))))))

test/clj/cider/nrepl/middleware/stacktrace_test.clj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,15 @@
121121
(binding [*print-level* 3]
122122
(clojure.pprint/pprint object))))))))
123123
(testing "compilation errors"
124-
(is (re-find #"Unable to resolve symbol: not-defined in this context"
125-
(:message (first causes3))))))
124+
(let [clojure-version ((juxt :major :minor) *clojure-version*)]
125+
(if (< (compare clojure-version [1 10]) 0)
126+
;; 1.8 / 1.9
127+
(is (re-find #"Unable to resolve symbol: not-defined in this context"
128+
(:message (first causes3))))
129+
130+
;; 1.10+
131+
(is (re-find #"Syntax error compiling at \(cider/nrepl/middleware/stacktrace_test\.clj:"
132+
(:message (first causes3))))))))
126133

127134
(deftest compilation-errors-test
128135
(testing "extract-location"

0 commit comments

Comments
 (0)