branch: elpa/cider commit 483f7c78000b0a25d3a17cc2782ea989f46f7753 Author: ikappaki <ikapp...@users.noreply.github.com> Commit: Bozhidar Batsov <bozhi...@batsov.dev>
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. --- test/integration/integration-test-utils.el | 26 +++++++++++++++++++++++--- test/integration/integration-tests.el | 10 +++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/test/integration/integration-test-utils.el b/test/integration/integration-test-utils.el index a8cc7b081b..ff61e3656a 100644 --- a/test/integration/integration-test-utils.el +++ b/test/integration/integration-test-utils.el @@ -31,17 +31,37 @@ (require 'cider) (require 'cl-lib) +(defun cider-itu-dump-all-buffers-contents () + "Print out the contents of all buffers." + (dolist (buff (buffer-list)) + (message "\n:BUFFER %S" (buffer-name buff)) + (with-current-buffer buff + (message "%s\n" (buffer-substring-no-properties (point-min) (point-max)))))) + (defmacro with-cider-test-sandbox (&rest body) "Run BODY inside sandbox, with key cider global vars restored on exit. +On error, it prints out all buffer contents including the nREPL messages +buffer. Only the following variables are currently restored, please add more as the test coverage increases: `cider-connected-hook`." (declare (indent 0)) - ;; for dynamic vars, just use a binding under the same name. - `(let ((cider-connected-hook cider-connected-hook)) - ,@body)) + `(let (;; for dynamic vars, just use a binding under the same name, so that + ;; the global value is not modified. + (cider-connected-hook cider-connected-hook) + + ;; Helpful for post morterm investigations. + (nrepl-log-messages t)) + (condition-case err + (progn + ,@body) + (error + (message ":DUMPING-BUFFERS-CONTENTS-ON-ERROR---") + (cider-itu-dump-all-buffers-contents) + ;; rethrow error + (signal (car err) (cdr err)))))) ;; https://emacs.stackexchange.com/a/55031 (defmacro with-temp-dir (temp-dir &rest body) diff --git a/test/integration/integration-tests.el b/test/integration/integration-tests.el index 2baa6e77fb..70037cefa1 100644 --- a/test/integration/integration-tests.el +++ b/test/integration/integration-tests.el @@ -85,8 +85,8 @@ (when err (push err eval-err)) (when out (push out eval-out)))) ) - ;; wait for the response to come back. - (cider-itu-poll-until eval-out 5) + ;; wait for a response to come back. + (cider-itu-poll-until (or eval-err eval-out) 5) ;; ensure there are no errors and response is as expected. (expect eval-err :to-equal '()) @@ -131,7 +131,7 @@ (out err) (when err (push err eval-err)) (when out (push out eval-out)))) ) - (cider-itu-poll-until eval-out 10) + (cider-itu-poll-until (or eval-err eval-out) 10) (expect eval-err :to-equal '()) (expect eval-out :to-equal '(":clojure? true")) (cider-quit repl-buffer) @@ -169,7 +169,7 @@ (out err) (when err (push err eval-err)) (when out (push out eval-out)))) ) - (cider-itu-poll-until eval-out 10) + (cider-itu-poll-until (or eval-err eval-out) 10) (expect eval-err :to-equal '()) (expect eval-out :to-equal '(":clojure? true")) (cider-quit repl-buffer) @@ -220,7 +220,7 @@ (out err) (when err (push err eval-err)) (when out (push out eval-out)))) ) - (cider-itu-poll-until eval-out 10) + (cider-itu-poll-until (or eval-err eval-out) 10) (expect eval-err :to-equal '()) (expect eval-out :to-equal '(":cljs? true\n")) (cider-quit repl-buffer)