diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2018-03-14 16:21:06 +0100 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2018-03-14 16:21:06 +0100 |
commit | 84a946a5199d84163ee221994216360502fc85ee (patch) | |
tree | b5903c5912bebc0bea49bf1d738c527127a095c8 /lisp/emacs-lisp/ert.el | |
parent | 4c33ad4a244db59bfe128aa54380904efdc775ba (diff) | |
download | emacs-84a946a5199d84163ee221994216360502fc85ee.tar.gz |
Extend ert to print duration of single tests
* lisp/emacs-lisp/ert.el (ert-test-result): New slot ´duration'.
(ert-run-or-rerun-test): Set it.
(ert-batch-print-duration): New defvar.
(ert-run-tests-batch): Print duration if needed.
* test/Makefile.in (TEST_PRINT_TEST_DURATION): New variable.
* test/README: Explain TEST_PRINT_TEST_DURATION.
Diffstat (limited to 'lisp/emacs-lisp/ert.el')
-rw-r--r-- | lisp/emacs-lisp/ert.el | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index a47108545d1..7d8d0a50e48 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -676,6 +676,7 @@ and is displayed in front of the value of MESSAGE-FORM." (cl-defstruct ert-test-result (messages nil) (should-forms nil) + (duration 0) ) (cl-defstruct (ert-test-passed (:include ert-test-result))) (cl-defstruct (ert-test-result-with-condition (:include ert-test-result)) @@ -1230,6 +1231,11 @@ SELECTOR is the selector that was used to select TESTS." (ert-run-test test) (setf (aref (ert--stats-test-end-times stats) pos) (current-time)) (let ((result (ert-test-most-recent-result test))) + (setf (ert-test-result-duration result) + (float-time + (time-subtract + (aref (ert--stats-test-end-times stats) pos) + (aref (ert--stats-test-start-times stats) pos)))) (ert--stats-set-test-and-result stats pos test result) (funcall listener 'test-ended stats test result)) (setf (ert--stats-current-test stats) nil)))) @@ -1336,6 +1342,9 @@ RESULT must be an `ert-test-result-with-condition'." (defvar ert-quiet nil "Non-nil makes ERT only print important information in batch mode.") +(defvar ert-batch-print-duration nil + "Non-nil makes ERT print duration time of single tests in batch mode.") + ;;;###autoload (defun ert-run-tests-batch (&optional selector) "Run the tests specified by SELECTOR, printing results to the terminal. @@ -1446,13 +1455,17 @@ Returns the stats object." (let* ((max (prin1-to-string (length (ert--stats-tests stats)))) (format-string (concat "%9s %" (prin1-to-string (length max)) - "s/" max " %S"))) + "s/" max " %S" + (if ert-batch-print-duration + " (%f sec)")))) (message format-string (ert-string-for-test-result result (ert-test-result-expected-p test result)) (1+ (ert--stats-test-pos stats test)) - (ert-test-name test)))))))) + (ert-test-name test) + (if ert-batch-print-duration + (ert-test-result-duration result))))))))) nil)) ;;;###autoload |