Skip to content

Commit 483f7c7

Browse files
ikappakibbatsov
authored andcommitted
Improve integration tests diagnostics on error
1. Also poll `eval-err` when expecting a response from the server. 2. Enable nREPL messages logging and dump all buffers contents on error.
1 parent 228d2fe commit 483f7c7

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

test/integration/integration-test-utils.el

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,37 @@
3131
(require 'cider)
3232
(require 'cl-lib)
3333

34+
(defun cider-itu-dump-all-buffers-contents ()
35+
"Print out the contents of all buffers."
36+
(dolist (buff (buffer-list))
37+
(message "\n:BUFFER %S" (buffer-name buff))
38+
(with-current-buffer buff
39+
(message "%s\n" (buffer-substring-no-properties (point-min) (point-max))))))
40+
3441
(defmacro with-cider-test-sandbox (&rest body)
3542
"Run BODY inside sandbox, with key cider global vars restored on exit.
43+
On error, it prints out all buffer contents including the nREPL messages
44+
buffer.
3645
3746
Only the following variables are currently restored, please add more as the
3847
test coverage increases:
3948
4049
`cider-connected-hook`."
4150
(declare (indent 0))
42-
;; for dynamic vars, just use a binding under the same name.
43-
`(let ((cider-connected-hook cider-connected-hook))
44-
,@body))
51+
`(let (;; for dynamic vars, just use a binding under the same name, so that
52+
;; the global value is not modified.
53+
(cider-connected-hook cider-connected-hook)
54+
55+
;; Helpful for post morterm investigations.
56+
(nrepl-log-messages t))
57+
(condition-case err
58+
(progn
59+
,@body)
60+
(error
61+
(message ":DUMPING-BUFFERS-CONTENTS-ON-ERROR---")
62+
(cider-itu-dump-all-buffers-contents)
63+
;; rethrow error
64+
(signal (car err) (cdr err))))))
4565

4666
;; https://emacs.stackexchange.com/a/55031
4767
(defmacro with-temp-dir (temp-dir &rest body)

test/integration/integration-tests.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
(when err (push err eval-err))
8686
(when out (push out eval-out)))) )
8787

88-
;; wait for the response to come back.
89-
(cider-itu-poll-until eval-out 5)
88+
;; wait for a response to come back.
89+
(cider-itu-poll-until (or eval-err eval-out) 5)
9090

9191
;; ensure there are no errors and response is as expected.
9292
(expect eval-err :to-equal '())
@@ -131,7 +131,7 @@
131131
(out err)
132132
(when err (push err eval-err))
133133
(when out (push out eval-out)))) )
134-
(cider-itu-poll-until eval-out 10)
134+
(cider-itu-poll-until (or eval-err eval-out) 10)
135135
(expect eval-err :to-equal '())
136136
(expect eval-out :to-equal '(":clojure? true"))
137137
(cider-quit repl-buffer)
@@ -169,7 +169,7 @@
169169
(out err)
170170
(when err (push err eval-err))
171171
(when out (push out eval-out)))) )
172-
(cider-itu-poll-until eval-out 10)
172+
(cider-itu-poll-until (or eval-err eval-out) 10)
173173
(expect eval-err :to-equal '())
174174
(expect eval-out :to-equal '(":clojure? true"))
175175
(cider-quit repl-buffer)
@@ -220,7 +220,7 @@
220220
(out err)
221221
(when err (push err eval-err))
222222
(when out (push out eval-out)))) )
223-
(cider-itu-poll-until eval-out 10)
223+
(cider-itu-poll-until (or eval-err eval-out) 10)
224224
(expect eval-err :to-equal '())
225225
(expect eval-out :to-equal '(":cljs? true\n"))
226226
(cider-quit repl-buffer)

0 commit comments

Comments
 (0)