Skip to content

Commit 8cc1f4f

Browse files
committed
Make info-test assertions fail more informatively
1 parent 51baf08 commit 8cc1f4f

File tree

1 file changed

+94
-47
lines changed

1 file changed

+94
-47
lines changed

test/clj/cider/nrepl/middleware/info_test.clj

Lines changed: 94 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"resource" "clojure/core.clj"}))))
5757

5858
(deftest info-test
59-
;; handle zero-lenth input
59+
;; handle zero-lenth input
6060
(is (nil? (info/info {:ns (ns-name *ns*) :sym ""})))
6161
(is (nil? (info/info {:ns "" :sym ""})))
6262

@@ -86,7 +86,8 @@
8686
(testing "info op"
8787
(testing "get info of a clojure function"
8888
(let [response (session/message {:op "info" :sym "testing-function" :ns "cider.nrepl.middleware.info-test"})]
89-
(is (= (:status response) #{"done"}))
89+
(is (= (:status response) #{"done"})
90+
(pr-str response))
9091
(is (= (:ns response) "cider.nrepl.middleware.info-test"))
9192
(is (= (:name response) "testing-function"))
9293
(is (= (:arglists-str response) "[a b c]"))
@@ -96,7 +97,8 @@
9697

9798
(testing "get info of a clojure macro"
9899
(let [response (session/message {:op "info" :sym "testing-macro" :ns "cider.nrepl.middleware.info-test"})]
99-
(is (= (:status response) #{"done"}))
100+
(is (= (:status response) #{"done"})
101+
(pr-str response))
100102
(is (= (:ns response) "cider.nrepl.middleware.info-test"))
101103
(is (= (:name response) "testing-macro"))
102104
(is (= (:arglists-str response) "[pred a b]"))
@@ -108,7 +110,8 @@
108110
(let [response (session/message {:op "info"
109111
:class "cider.nrepl.test.TestClass"
110112
:member "getInt"})]
111-
(is (= (:status response) #{"done"}))
113+
(is (= (:status response) #{"done"})
114+
(pr-str response))
112115
(is (= (:class response) "cider.nrepl.test.TestClass"))
113116
(is (= (:member response) "getInt"))
114117
(is (= (:arglists-str response) "[this]"))
@@ -122,20 +125,23 @@
122125
(let [response (session/message {:op "info"
123126
:class "cider.nrepl.test.TestClass"
124127
:member "getInt"})]
125-
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#getInt--")))))
128+
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#getInt--")
129+
(pr-str response)))))
126130

127131
(if (SystemUtils/IS_JAVA_9)
128132
(testing "JDK 9 Javadoc URL style"
129133
(let [response (session/message {:op "info"
130134
:class "cider.nrepl.test.TestClass"
131135
:member "getInt"})]
132-
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#getInt--"))))))
136+
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#getInt--")
137+
(pr-str response))))))
133138

134139
(testing "get info of a private java class method, void return"
135140
(let [response (session/message {:op "info"
136141
:class "cider.nrepl.test.TestClass"
137142
:member "doSomething"})]
138-
(is (= (:status response) #{"done"}))
143+
(is (= (:status response) #{"done"})
144+
(pr-str response))
139145
(is (= (:class response) "cider.nrepl.test.TestClass"))
140146
(is (= (:member response) "doSomething"))
141147
(is (= (:arglists-str response) "[int int java.lang.String]"))
@@ -149,20 +155,23 @@
149155
(let [response (session/message {:op "info"
150156
:class "cider.nrepl.test.TestClass"
151157
:member "doSomething"})]
152-
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#doSomething-int-int-java.lang.String-")))))
158+
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#doSomething-int-int-java.lang.String-")
159+
(pr-str response)))))
153160

154161
(if (SystemUtils/IS_JAVA_9)
155162
(testing "JDK 9 Javadoc URL style"
156163
(let [response (session/message {:op "info"
157164
:class "cider.nrepl.test.TestClass"
158165
:member "doSomething"})]
159-
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#doSomething-int-int-java.lang.String-"))))))
166+
(is (= (:javadoc response) "cider/nrepl/test/TestClass.html#doSomething-int-int-java.lang.String-")
167+
(pr-str response))))))
160168

161169
(testing "get info of a java method"
162170
(let [response (session/message {:op "info"
163171
:class "java.lang.StringBuilder"
164172
:member "capacity"})]
165-
(is (= (:status response) #{"done"}))
173+
(is (= (:status response) #{"done"})
174+
(pr-str response))
166175
(is (= (:class response) "java.lang.StringBuilder"))
167176
(is (= (:member response) "capacity"))
168177
(is (= (:arglists-str response) "[this]"))
@@ -176,18 +185,21 @@
176185
(let [response (session/message {:op "info"
177186
:class "java.lang.StringBuilder"
178187
:member "capacity"})]
179-
(is (= (:javadoc response) "https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#capacity--")))))
188+
(is (= (:javadoc response) "https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#capacity--")
189+
(pr-str response)))))
180190

181191
(if (SystemUtils/IS_JAVA_9)
182192
(testing "JDK 9 Javadoc URL style"
183193
(let [response (session/message {:op "info"
184194
:class "java.lang.StringBuilder"
185195
:member "capacity"})]
186-
(is (= (:javadoc response) "https://docs.oracle.com/javase/9/docs/api/java/lang/StringBuilder.html#capacity--"))))))
196+
(is (= (:javadoc response) "https://docs.oracle.com/javase/9/docs/api/java/lang/StringBuilder.html#capacity--")
197+
(pr-str response))))))
187198

188199
(testing "get info on the dot-operator"
189200
(let [response (session/message {:op "info" :sym "." :ns "user"})]
190-
(is (= (:status response) #{"done"}))
201+
(is (= (:status response) #{"done"})
202+
(pr-str response))
191203
(is (= (:name response) "."))
192204
(is (= (:url response) "https://clojure.org/java_interop#dot"))
193205
(is (= (:special-form response) "true"))
@@ -196,7 +208,8 @@
196208

197209
(testing "get info of a clojure non-core file, located in a jar"
198210
(let [response (session/message {:op "info" :sym "resource" :ns "clojure.java.io"})]
199-
(is (= (:status response) #{"done"}))
211+
(is (= (:status response) #{"done"})
212+
(pr-str response))
200213
(is (= (:name response) "resource"))
201214
(is (= (:resource response) "clojure/java/io.clj"))
202215
(is (= (:ns response) "clojure.java.io"))
@@ -208,7 +221,8 @@
208221
(let [response (session/message {:op "info" :ns (ns-name *ns*) :sym "toString"})
209222
candidates (:candidates response)
210223
individual (:java.lang.Exception candidates)]
211-
(is (contains? candidates :java.lang.NoSuchFieldException))
224+
(is (contains? candidates :java.lang.NoSuchFieldException)
225+
(pr-str response))
212226
(is (contains? candidates :java.lang.Package))
213227
(is (contains? candidates :java.lang.LinkageError))
214228

@@ -220,7 +234,8 @@
220234
(try
221235
(System/setProperty "fake.class.path" (System/getProperty "java.class.path"))
222236
(let [response (session/message {:op "info" :sym "as->" :ns "user"})]
223-
(is (= (:status response) #{"done"}))
237+
(is (= (:status response) #{"done"})
238+
(pr-str response))
224239
(is (= (:ns response) "clojure.core"))
225240
(is (= (:name response) "as->"))
226241
(is (= (:arglists-str response) "[expr name & forms]"))
@@ -239,7 +254,8 @@
239254
file (:file reply)
240255
protocol (:protocol reply)
241256
ns (:ns reply)]
242-
(is (= status #{"done"}))
257+
(is (= status #{"done"})
258+
(pr-str reply))
243259
(is (= client-name "junk-protocol-client"))
244260
(is (.endsWith file "clojure/data.clj"))
245261
(is (= protocol "#'clojure.data/Diff"))
@@ -248,17 +264,21 @@
248264
(testing "see also"
249265
(let [response (session/message {:op "info" :sym "map" :ns "cider.nrepl.middleware.info-test"})]
250266
(is (= (:see-also response)
251-
["clojure.core/map-indexed" "clojure.core/pmap" "clojure.core/amap" "clojure.core/mapcat" "clojure.core/keep" "clojure.core/juxt" "clojure.core/mapv" "clojure.core/reduce" "clojure.core/run!"])))
267+
["clojure.core/map-indexed" "clojure.core/pmap" "clojure.core/amap" "clojure.core/mapcat" "clojure.core/keep" "clojure.core/juxt" "clojure.core/mapv" "clojure.core/reduce" "clojure.core/run!"])
268+
(pr-str response)))
252269
(let [response (session/message {:op "info" :sym "xyz" :ns "cider.nrepl.middleware.info-test"})]
253-
(is (nil? (:see-also response))))
270+
(is (nil? (:see-also response))
271+
(pr-str response)))
254272

255273
(let [response (session/message {:op "info" :sym "xyz"})]
256-
(is (nil? (:see-also response))))))
274+
(is (nil? (:see-also response))
275+
(pr-str response)))))
257276

258277
(testing "eldoc op"
259278
(testing "clojure function"
260279
(let [response (session/message {:op "eldoc" :sym "+" :ns "user"})]
261-
(is (= (:status response) #{"done"}))
280+
(is (= (:status response) #{"done"})
281+
(pr-str response))
262282
(is (= (:eldoc response) [[] ["x"] ["x" "y"] ["x" "y" "&" "more"]]))
263283
(is (= (:ns response) "clojure.core"))
264284
(is (not (contains? response :class)))
@@ -267,18 +287,21 @@
267287

268288
(testing "clojure special form"
269289
(let [response (session/message {:op "eldoc" :sym "try" :ns "user"})]
270-
(is (= (:status response) #{"done"}))
290+
(is (= (:status response) #{"done"})
291+
(pr-str response))
271292
(is (= (:eldoc response) [["try" "expr*" "catch-clause*" "finally-clause?"]]))
272293
(is (= (:type response) "function"))))
273294

274295
(testing "clojure dot operator"
275296
(let [response (session/message {:op "eldoc" :sym "." :ns "user"})]
276-
(is (= (:status response) #{"done"}))
297+
(is (= (:status response) #{"done"})
298+
(pr-str response))
277299
(is (= (:type response) "function"))))
278300

279301
(testing "clojure variable"
280302
(let [response (session/message {:op "eldoc" :sym "some-test-var" :ns "cider.test-ns.first-test-ns"})]
281-
(is (= (:status response) #{"done"}))
303+
(is (= (:status response) #{"done"})
304+
(pr-str response))
282305
(is (= (:docstring response) "This is a test var used to check eldoc returned for a variable."))
283306
(is (= (:name response) "some-test-var"))
284307
(is (= (:ns response) "cider.test-ns.first-test-ns"))
@@ -288,14 +311,16 @@
288311
(testing "java interop method with multiple classes"
289312
(let [response (session/message {:op "eldoc" :sym ".length" :ns "cider.nrepl.middleware.info-test"})]
290313
(is (= (:class response)
291-
["java.lang.String" "java.lang.StringBuffer" "java.lang.CharSequence" "java.lang.StringBuilder"]))
314+
["java.lang.String" "java.lang.StringBuffer" "java.lang.CharSequence" "java.lang.StringBuilder"])
315+
(pr-str response))
292316
(is (= (:member response) "length"))
293317
(is (not (contains? response :ns)))
294318
(is (= (:type response) "function"))))
295319

296320
(testing "java interop method with single class"
297321
(let [response (session/message {:op "eldoc" :sym ".startsWith" :ns "cider.nrepl.middleware.info-test"})]
298-
(is (= (:class response) ["java.lang.String"]))
322+
(is (= (:class response) ["java.lang.String"])
323+
(pr-str response))
299324
(is (= (:member response) "startsWith"))
300325
(is (not (contains? response :ns)))
301326
(is (= (:type response) "function"))))
@@ -305,84 +330,100 @@
305330
(is (= #{["this"] ;;TestClass
306331
["int" "java.lang.String" "boolean"] ;;AnotherTestClass
307332
["this" "byte[]" "java.lang.Object[]" "java.util.List"]} ;;YetAnotherTest
308-
(set (:eldoc response))))
333+
(set (:eldoc response)))
334+
(pr-str response))
309335
(is (= (:type response) "function"))))))
310336

311337
(deftest missing-info-test
312338
(testing "ensure info returns a no-info packet if symbol not found"
313339
(let [response (session/message {:op "info" :sym "awoeijfxcvb" :ns "user"})]
314-
(is (= (:status response) #{"no-info" "done"}))))
340+
(is (= (:status response) #{"no-info" "done"})
341+
(pr-str response))))
315342

316343
(testing "ensure info returns a no-info packet if ns not found"
317344
(let [response (session/message {:op "info" :sym "+" :ns "fakefakefake"})]
318-
(is (= (:status response) #{"no-info" "done"}))))
345+
(is (= (:status response) #{"no-info" "done"})
346+
(pr-str response))))
319347

320348
(testing "ensure info returns a no-info packet if class not found"
321349
(let [response (session/message {:op "info" :class "awoeijfxcvb" :member "toString"})]
322-
(is (= (:status response) #{"no-info" "done"}))))
350+
(is (= (:status response) #{"no-info" "done"})
351+
(pr-str response))))
323352

324353
(testing "ensure info returns a no-info packet if member not found"
325354
(let [response (session/message {:op "info" :class "java.lang.Exception" :member "fakefakefake"})]
326-
(is (= (:status response) #{"no-info" "done"})))))
355+
(is (= (:status response) #{"no-info" "done"})
356+
(pr-str response)))))
327357

328358
(deftest missing-eldoc-test
329359
(testing "ensure eldoc returns a no-eldoc packet if symbol not found"
330360
(let [response (session/message {:op "eldoc" :sym "awoeijfxcvb" :ns "user"})]
331-
(is (= (:status response) #{"no-eldoc" "done"}))))
361+
(is (= (:status response) #{"no-eldoc" "done"})
362+
(pr-str response))))
332363

333364
(testing "ensure eldoc returns a no-eldoc packet if ns not found"
334365
(let [response (session/message {:op "eldoc" :sym "+" :ns "fakefakefake"})]
335-
(is (= (:status response) #{"no-eldoc" "done"}))))
366+
(is (= (:status response) #{"no-eldoc" "done"})
367+
(pr-str response))))
336368

337369
(testing "ensure eldoc returns a no-eldoc packet if class not found"
338370
(let [response (session/message {:op "eldoc" :class "awoeijfxcvb" :member "toString"})]
339-
(is (= (:status response) #{"no-eldoc" "done"}))))
371+
(is (= (:status response) #{"no-eldoc" "done"})
372+
(pr-str response))))
340373

341374
(testing "ensure eldoc returns a no-eldoc packet if member not found"
342375
(let [response (session/message {:op "eldoc" :class "java.lang.Exception" :member "fakefakefake"})]
343-
(is (= (:status response) #{"no-eldoc" "done"})))))
376+
(is (= (:status response) #{"no-eldoc" "done"})
377+
(pr-str response)))))
344378

345379
(deftest error-handling-test
346380
(testing "handle the exception thrown if no member provided to a java class info query"
347381
(let [response (session/message {:op "info" :class "test"})]
348-
(is (= (:status response) #{"info-error" "done"}))
382+
(is (= (:status response) #{"info-error" "done"})
383+
(pr-str response))
349384
(is (= (:ex response) "class java.lang.Exception"))
350385
(is (-> response ^String (:err) (.startsWith "java.lang.Exception: Either")))
351386
(is (:pp-stacktrace response))))
352387

353388
(testing "handle the exception thrown if no member provided to a java class eldoc query"
354389
(let [response (session/message {:op "eldoc" :class "test"})]
355-
(is (= (:status response) #{"eldoc-error" "done"}))
390+
(is (= (:status response) #{"eldoc-error" "done"})
391+
(pr-str response))
356392
(is (= (:ex response) "class java.lang.Exception"))
357393
(is (-> response ^String (:err) (.startsWith "java.lang.Exception: Either")))
358394
(is (:pp-stacktrace response))))
359395

360396
(testing "handle the exception thrown if no class provided to a java member info query"
361397
(let [response (session/message {:op "info" :member "test"})]
362-
(is (= (:status response) #{"info-error" "done"}))
398+
(is (= (:status response) #{"info-error" "done"})
399+
(pr-str response))
363400
(is (= (:ex response) "class java.lang.Exception"))
364401
(is (-> response ^String (:err) (.startsWith "java.lang.Exception: Either")))
365402
(is (:pp-stacktrace response))))
366403

367404
(testing "handle the exception thrown if no class provided to a java member eldoc query"
368405
(let [response (session/message {:op "eldoc" :member "test"})]
369-
(is (= (:status response) #{"eldoc-error" "done"}))
406+
(is (= (:status response) #{"eldoc-error" "done"})
407+
(pr-str response))
370408
(is (= (:ex response) "class java.lang.Exception"))
371409
(is (-> response ^String (:err) (.startsWith "java.lang.Exception: Either")))
372410
(is (:pp-stacktrace response))))
373411

374412
(testing "handle the exception thrown if there's a mocked info retrieval error"
375413
(with-redefs [info/info (fn [& _] (throw (Exception. "info-exception")))]
376414
(let [response (session/message {:op "info" :sym "test" :ns "user"})]
377-
(is (= (:status response) #{"info-error" "done"}))
415+
(is (= (:status response) #{"info-error" "done"})
416+
(pr-str response))
378417
(is (= (:ex response) "class java.lang.Exception"))
379418
(is (-> response ^String (:err) (.startsWith "java.lang.Exception: info-exception")))
380419
(is (:pp-stacktrace response)))))
381420

382421
(testing "handle the exception thrown if there's a mocked eldoc retreival error "
383422
(with-redefs [info/eldoc-reply (fn [& _] (throw (Exception. "eldoc-exception")))]
384423
(let [response (session/message {:op "eldoc" :sym "test" :ns "user"})]
385-
(is (= (:status response) #{"eldoc-error" "done"}))
424+
(is (= (:status response) #{"eldoc-error" "done"})
425+
426+
(pr-str response))
386427
(is (= (:ex response) "class java.lang.Exception"))
387428
(is (-> response ^String (:err) (.startsWith "java.lang.Exception: eldoc-exception")))
388429
(is (:pp-stacktrace response))))))
@@ -398,34 +439,40 @@
398439
(let [response (session/message {:op "eldoc-datomic-query"
399440
:sym "'[:find ?x :in $ % ?person-id]"
400441
:ns "user"})]
401-
(is (= (:inputs response) '(["$" "%" "?person-id"])))))
442+
(is (= (:inputs response) '(["$" "%" "?person-id"]))
443+
(pr-str response))))
402444

403445
(testing "eldoc of inline datomic query as map"
404446
(let [response (session/message {:op "eldoc-datomic-query"
405447
:sym "'{:find [?x] :in [$ % ?person-id]}"
406448
:ns "user"})]
407-
(is (= (:inputs response) '(["$" "%" "?person-id"])))))
449+
(is (= (:inputs response) '(["$" "%" "?person-id"]))
450+
(pr-str response))))
408451

409452
(testing "eldoc of datomic query defined as symbol"
410453
(let [response (session/message {:op "eldoc-datomic-query"
411454
:sym "testing-datomic-query"
412455
:ns "cider.nrepl.middleware.info-test"})]
413-
(is (= (:inputs response) '(["$" "?name"])))))
456+
(is (= (:inputs response) '(["$" "?name"]))
457+
(pr-str response))))
414458

415459
(testing "eldoc of inline datomic query without :in"
416460
(let [response (session/message {:op "eldoc-datomic-query"
417461
:sym "'[:find ?x]"
418462
:ns "user"})]
419-
(is (= (:inputs response) '(["$"])))))
463+
(is (= (:inputs response) '(["$"]))
464+
(pr-str response))))
420465

421466
(testing "eldoc of inline datomic query as map without :in"
422467
(let [response (session/message {:op "eldoc-datomic-query"
423468
:sym "'{:find ?x}"
424469
:ns "user"})]
425-
(is (= (:inputs response) '(["$"])))))
470+
(is (= (:inputs response) '(["$"]))
471+
(pr-str response))))
426472

427473
(testing "eldoc of empty datomic query"
428474
(let [response (session/message {:op "eldoc-datomic-query"
429475
:sym ""
430476
:ns "user"})]
431-
(is (= (:status response) #{"no-eldoc" "done"})))))
477+
(is (= (:status response) #{"no-eldoc" "done"})
478+
(pr-str response)))))

0 commit comments

Comments
 (0)