(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))
(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))))
(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.
(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
# If you just want a pass/fail, setting this to no is much faster.
TEST_LOAD_EL ?= yes
+# Additional settings for ert.
+ert_opts =
+
# Maximum length of lines in ert backtraces; nil for no limit.
# (if empty, use the default ert-batch-backtrace-right-margin).
TEST_BACKTRACE_LINE_LENGTH =
-ifeq (${TEST_BACKTRACE_LINE_LENGTH},)
-ert_opts =
-else
-ert_opts = --eval '(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
+ifneq (${TEST_BACKTRACE_LINE_LENGTH},)
+ert_opts += --eval '(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
+endif
+
+# Whether the tests shall also report their duration.
+ifdef TEST_PRINT_TEST_DURATION
+ert_opts += --eval '(setq ert-batch-print-duration t)'
endif
ifeq (@HAVE_MODULES@, yes)
make TEST_LOAD_EL=no ...
+Sometimes, it is ncessary to trace the duration time for single tests.
+This is controlled by the environment variable TEST_PRINT_TEST_DURATION
+
+ make TEST_PRINT_TEST_DURATION=1 ...
+
\f
(Also, see etc/compilation.txt for compilation mode font lock tests.)