Skip to content

Commit 599ceb5

Browse files
authoredJul 21, 2023
cider-test: add timing information (#3373)
See also: clojure-emacs/cider-nrepl#755
1 parent 02802a8 commit 599ceb5

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- [#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.
88
- [#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.
9+
- `cider-test`: add timing information.
910

1011
### Bugs fixed
1112

‎cider-test.el

+34-14
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,14 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
374374
(let ((face (cider-test-type-face type)))
375375
`(:foreground ,(face-attribute face :background))))
376376

377-
(defun cider-test-render-summary (buffer summary)
377+
(defun cider-test-render-summary (buffer summary &optional elapsed-time)
378378
"Emit into BUFFER the report SUMMARY statistics."
379379
(with-current-buffer buffer
380380
(nrepl-dbind-response summary (ns var test pass fail error)
381-
(insert (format "Tested %d namespaces\n" ns))
381+
(let ((ms (nrepl-dict-get elapsed-time "ms")))
382+
(insert (format "Tested %d namespaces%s\n" ns (if ms
383+
(format " in %s ms" ms)
384+
""))))
382385
(insert (format "Ran %d assertions, in %d test functions\n" test var))
383386
(unless (zerop fail)
384387
(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."
391394
(defun cider-test-render-assertion (buffer test)
392395
"Emit into BUFFER report detail for the TEST assertion."
393396
(with-current-buffer buffer
394-
(nrepl-dbind-response test (var context type message expected actual diffs error gen-input)
397+
(nrepl-dbind-response test (var context type message expected actual diffs error gen-input elapsed-time)
395398
(cl-flet ((insert-label (s)
396399
(cider-insert (format "%8s: " s) 'font-lock-comment-face))
397400
(insert-align-label (s)
@@ -410,6 +413,9 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
410413
(bg `(:background ,cider-test-items-background-color :extend t)))
411414
(cider-insert (capitalize type) type-face nil " in ")
412415
(cider-insert var 'font-lock-function-name-face t)
416+
(when elapsed-time
417+
(when-let ((humanized (nrepl-dict-get elapsed-time "humanized")))
418+
(cider-insert humanized)))
413419
(when context (cider-insert context 'font-lock-doc-face t))
414420
(when message (cider-insert message 'font-lock-string-face t))
415421
(when expected
@@ -450,16 +456,21 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
450456
test))
451457
tests))
452458

453-
(defun cider-test-render-report (buffer summary results)
459+
(defun cider-test-render-report (buffer summary results &optional elapsed-time ns-elapsed-time)
454460
"Emit into BUFFER the report for the SUMMARY, and test RESULTS."
455461
(with-current-buffer buffer
456462
(let ((inhibit-read-only t))
457463
(cider-test-report-mode)
458464
(cider-insert "Test Summary" 'bold t)
459465
(dolist (ns (nrepl-dict-keys results))
460-
(insert (cider-propertize ns 'ns) "\n"))
466+
(insert (cider-propertize ns 'ns)
467+
(or (let ((ms (nrepl-dict-get (nrepl-dict-get ns-elapsed-time ns)
468+
"ms")))
469+
(format " (%s ms)" ms))
470+
"")
471+
"\n"))
461472
(cider-insert "\n")
462-
(cider-test-render-summary buffer summary)
473+
(cider-test-render-summary buffer summary elapsed-time)
463474
(nrepl-dbind-response summary (fail error)
464475
(unless (zerop (+ fail error))
465476
(cider-insert "Results" 'bold t "\n")
@@ -506,22 +517,26 @@ The optional arg TEST denotes an individual test name."
506517
'ns)
507518
(unless (stringp ns) " namespaces")))))
508519

509-
(defun cider-test-echo-summary (summary results)
510-
"Echo SUMMARY statistics for a test run returning RESULTS."
520+
(defun cider-test-echo-summary (summary results &optional elapsed-time)
521+
"Echo SUMMARY statistics for a test run returning RESULTS in ELAPSED-TIME."
511522
(nrepl-dbind-response summary (ns test var fail error)
512523
(if (nrepl-dict-empty-p results)
513524
(message (concat (propertize "No assertions (or no tests) were run." 'face 'cider-test-error-face)
514525
"Did you forget to use `is' in your tests?"))
526+
(let* ((ms (nrepl-dict-get elapsed-time "ms"))
527+
(ms (if ms
528+
(propertize (concat " in " (prin1-to-string ms) "ms") 'face 'font-lock-comment-face)
529+
".")))
515530
(message (propertize
516-
"%sRan %d assertions, in %d test functions. %d failures, %d errors."
531+
"%sRan %d assertions, in %d test functions. %d failures, %d errors%s"
517532
'face (cond ((not (zerop error)) 'cider-test-error-face)
518533
((not (zerop fail)) 'cider-test-failure-face)
519534
(t 'cider-test-success-face)))
520535
(concat (if (= 1 ns) ; ns count from summary
521536
(cider-propertize (car (nrepl-dict-keys results)) 'ns)
522537
(propertize (format "%d namespaces" ns) 'face 'default))
523538
(propertize ": " 'face 'default))
524-
test var fail error))))
539+
test var fail error ms)))))
525540

526541
;;; Test definition highlighting
527542
;;
@@ -685,7 +700,7 @@ running them."
685700
(cider-nrepl-send-request
686701
request
687702
(lambda (response)
688-
(nrepl-dbind-response response (summary results status out err)
703+
(nrepl-dbind-response response (summary results status out err elapsed-time ns-elapsed-time)
689704
(cond ((member "namespace-not-found" status)
690705
(unless silent
691706
(message "No test namespace: %s" (cider-propertize ns 'ns))))
@@ -696,22 +711,27 @@ running them."
696711
(setq cider-test-last-summary summary)
697712
(setq cider-test-last-results results)
698713
(cider-test-highlight-problems results)
699-
(cider-test-echo-summary summary results)
714+
(cider-test-echo-summary summary results elapsed-time)
700715
(if (or (not (zerop (+ error fail)))
701716
cider-test-show-report-on-success)
702717
(cider-test-render-report
703718
(cider-popup-buffer
704719
cider-test-report-buffer
705720
cider-auto-select-test-report-buffer)
706721
summary
707-
results)
722+
results
723+
elapsed-time
724+
ns-elapsed-time)
708725
(when (get-buffer cider-test-report-buffer)
709726
(with-current-buffer cider-test-report-buffer
710727
(let ((inhibit-read-only t))
711728
(erase-buffer)))
712729
(cider-test-render-report
713730
cider-test-report-buffer
714-
summary results))))))))
731+
summary
732+
results
733+
elapsed-time
734+
ns-elapsed-time))))))))
715735
conn))))))
716736

717737
(defun cider-test-rerun-failed-tests ()

‎cider.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ the artifact.")
489489
(defconst cider-latest-clojure-version "1.10.1"
490490
"Latest supported version of Clojure.")
491491

492-
(defconst cider-required-middleware-version "0.32.0-alpha1"
492+
(defconst cider-required-middleware-version "0.32.0-alpha2"
493493
"The CIDER nREPL version that's known to work properly with CIDER.")
494494

495495
(defcustom cider-injected-middleware-version cider-required-middleware-version

0 commit comments

Comments
 (0)
Please sign in to comment.