branch: elpa/cider commit 599ceb5841ffb621a3c8035433ad61d0e67e73b4 Author: vemv <v...@users.noreply.github.com> Commit: GitHub <nore...@github.com>
`cider-test`: add timing information (#3373) See also: https://github.com/clojure-emacs/cider-nrepl/issues/755 --- CHANGELOG.md | 1 + cider-test.el | 48 ++++++++++++++++++++++++++++++++++-------------- cider.el | 2 +- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4969d6b5a..a638bb62c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#3352](https://github.com/clojure-emacs/cider/pull/3352) Add CIDER Log Mode, a major mode that allows you to capture, debug, inspect and view log events emitted by Java logging frameworks. - [#3354](https://github.com/clojure-emacs/cider/issues/3354): Add new customization variable `cider-reuse-dead-repls` to control how dead REPL buffers are reused on new connections. +- `cider-test`: add timing information. ### Bugs fixed diff --git a/cider-test.el b/cider-test.el index 50ff75f27f..3436077ab0 100644 --- a/cider-test.el +++ b/cider-test.el @@ -374,11 +374,14 @@ With the actual value, the outermost '(not ...)' s-expression is removed." (let ((face (cider-test-type-face type))) `(:foreground ,(face-attribute face :background)))) -(defun cider-test-render-summary (buffer summary) +(defun cider-test-render-summary (buffer summary &optional elapsed-time) "Emit into BUFFER the report SUMMARY statistics." (with-current-buffer buffer (nrepl-dbind-response summary (ns var test pass fail error) - (insert (format "Tested %d namespaces\n" ns)) + (let ((ms (nrepl-dict-get elapsed-time "ms"))) + (insert (format "Tested %d namespaces%s\n" ns (if ms + (format " in %s ms" ms) + "")))) (insert (format "Ran %d assertions, in %d test functions\n" test var)) (unless (zerop fail) (cider-insert (format "%d failures" fail) 'cider-test-failure-face t)) @@ -391,7 +394,7 @@ With the actual value, the outermost '(not ...)' s-expression is removed." (defun cider-test-render-assertion (buffer test) "Emit into BUFFER report detail for the TEST assertion." (with-current-buffer buffer - (nrepl-dbind-response test (var context type message expected actual diffs error gen-input) + (nrepl-dbind-response test (var context type message expected actual diffs error gen-input elapsed-time) (cl-flet ((insert-label (s) (cider-insert (format "%8s: " s) 'font-lock-comment-face)) (insert-align-label (s) @@ -410,6 +413,9 @@ With the actual value, the outermost '(not ...)' s-expression is removed." (bg `(:background ,cider-test-items-background-color :extend t))) (cider-insert (capitalize type) type-face nil " in ") (cider-insert var 'font-lock-function-name-face t) + (when elapsed-time + (when-let ((humanized (nrepl-dict-get elapsed-time "humanized"))) + (cider-insert humanized))) (when context (cider-insert context 'font-lock-doc-face t)) (when message (cider-insert message 'font-lock-string-face t)) (when expected @@ -450,16 +456,21 @@ With the actual value, the outermost '(not ...)' s-expression is removed." test)) tests)) -(defun cider-test-render-report (buffer summary results) +(defun cider-test-render-report (buffer summary results &optional elapsed-time ns-elapsed-time) "Emit into BUFFER the report for the SUMMARY, and test RESULTS." (with-current-buffer buffer (let ((inhibit-read-only t)) (cider-test-report-mode) (cider-insert "Test Summary" 'bold t) (dolist (ns (nrepl-dict-keys results)) - (insert (cider-propertize ns 'ns) "\n")) + (insert (cider-propertize ns 'ns) + (or (let ((ms (nrepl-dict-get (nrepl-dict-get ns-elapsed-time ns) + "ms"))) + (format " (%s ms)" ms)) + "") + "\n")) (cider-insert "\n") - (cider-test-render-summary buffer summary) + (cider-test-render-summary buffer summary elapsed-time) (nrepl-dbind-response summary (fail error) (unless (zerop (+ fail error)) (cider-insert "Results" 'bold t "\n") @@ -506,14 +517,18 @@ The optional arg TEST denotes an individual test name." 'ns) (unless (stringp ns) " namespaces"))))) -(defun cider-test-echo-summary (summary results) - "Echo SUMMARY statistics for a test run returning RESULTS." +(defun cider-test-echo-summary (summary results &optional elapsed-time) + "Echo SUMMARY statistics for a test run returning RESULTS in ELAPSED-TIME." (nrepl-dbind-response summary (ns test var fail error) (if (nrepl-dict-empty-p results) (message (concat (propertize "No assertions (or no tests) were run." 'face 'cider-test-error-face) "Did you forget to use `is' in your tests?")) + (let* ((ms (nrepl-dict-get elapsed-time "ms")) + (ms (if ms + (propertize (concat " in " (prin1-to-string ms) "ms") 'face 'font-lock-comment-face) + "."))) (message (propertize - "%sRan %d assertions, in %d test functions. %d failures, %d errors." + "%sRan %d assertions, in %d test functions. %d failures, %d errors%s" 'face (cond ((not (zerop error)) 'cider-test-error-face) ((not (zerop fail)) 'cider-test-failure-face) (t 'cider-test-success-face))) @@ -521,7 +536,7 @@ The optional arg TEST denotes an individual test name." (cider-propertize (car (nrepl-dict-keys results)) 'ns) (propertize (format "%d namespaces" ns) 'face 'default)) (propertize ": " 'face 'default)) - test var fail error)))) + test var fail error ms))))) ;;; Test definition highlighting ;; @@ -685,7 +700,7 @@ running them." (cider-nrepl-send-request request (lambda (response) - (nrepl-dbind-response response (summary results status out err) + (nrepl-dbind-response response (summary results status out err elapsed-time ns-elapsed-time) (cond ((member "namespace-not-found" status) (unless silent (message "No test namespace: %s" (cider-propertize ns 'ns)))) @@ -696,7 +711,7 @@ running them." (setq cider-test-last-summary summary) (setq cider-test-last-results results) (cider-test-highlight-problems results) - (cider-test-echo-summary summary results) + (cider-test-echo-summary summary results elapsed-time) (if (or (not (zerop (+ error fail))) cider-test-show-report-on-success) (cider-test-render-report @@ -704,14 +719,19 @@ running them." cider-test-report-buffer cider-auto-select-test-report-buffer) summary - results) + results + elapsed-time + ns-elapsed-time) (when (get-buffer cider-test-report-buffer) (with-current-buffer cider-test-report-buffer (let ((inhibit-read-only t)) (erase-buffer))) (cider-test-render-report cider-test-report-buffer - summary results)))))))) + summary + results + elapsed-time + ns-elapsed-time)))))))) conn)))))) (defun cider-test-rerun-failed-tests () diff --git a/cider.el b/cider.el index 12d0bdbaa7..0e70211b91 100644 --- a/cider.el +++ b/cider.el @@ -489,7 +489,7 @@ the artifact.") (defconst cider-latest-clojure-version "1.10.1" "Latest supported version of Clojure.") -(defconst cider-required-middleware-version "0.32.0-alpha1" +(defconst cider-required-middleware-version "0.32.0-alpha2" "The CIDER nREPL version that's known to work properly with CIDER.") (defcustom cider-injected-middleware-version cider-required-middleware-version