Function: ert-run-tests-batch
ert-run-tests-batch is an autoloaded and byte-compiled function
defined in ert.el.gz.
Signature
(ert-run-tests-batch &optional SELECTOR)
Documentation
Run the tests specified by SELECTOR, printing results to the terminal.
SELECTOR selects which tests to run as described in ert-select-tests when
called with its second argument t, except if SELECTOR is nil, in which case
all tests rather than none will be run; this makes the command line
"emacs -batch -l my-tests.el -f ert-run-tests-batch-and-exit" useful.
Returns the stats object.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
;;;###autoload
(defun ert-run-tests-batch (&optional selector)
"Run the tests specified by SELECTOR, printing results to the terminal.
SELECTOR selects which tests to run as described in `ert-select-tests' when
called with its second argument t, except if SELECTOR is nil, in which case
all tests rather than none will be run; this makes the command line
\"emacs -batch -l my-tests.el -f ert-run-tests-batch-and-exit\" useful.
Returns the stats object."
(unless selector (setq selector 't))
(ert-run-tests
selector
(lambda (event-type &rest event-args)
(cl-ecase event-type
(run-started
(unless ert-quiet
(cl-destructuring-bind (stats) event-args
(message "Running %s tests (%s, selector `%S')"
(length (ert--stats-tests stats))
(ert--format-time-iso8601 (ert--stats-start-time stats))
selector))))
(run-ended
(cl-destructuring-bind (stats abortedp) event-args
(let ((unexpected (ert-stats-completed-unexpected stats))
(skipped (ert-stats-skipped stats))
(expected-failures (ert--stats-failed-expected stats)))
(message "\n%sRan %s tests, %s results as expected, %s unexpected%s (%s, %f sec)%s\n"
(if (not abortedp)
""
"Aborted: ")
(ert-stats-total stats)
(ert-stats-completed-expected stats)
unexpected
(if (zerop skipped)
""
(format ", %s skipped" skipped))
(ert--format-time-iso8601 (ert--stats-end-time stats))
(float-time
(time-subtract
(ert--stats-end-time stats)
(ert--stats-start-time stats)))
(if (zerop expected-failures)
""
(format "\n%s expected failures" expected-failures)))
(unless (zerop unexpected)
(message "%s unexpected results:" unexpected)
(cl-loop for test across (ert--stats-tests stats)
for result = (ert-test-most-recent-result test) do
(when (not (ert-test-result-expected-p test result))
(message "%9s %S%s"
(ert-string-for-test-result result nil)
(ert-test-name test)
(if (plusp
(length (getenv "EMACS_TEST_VERBOSE")))
(ert-reason-for-test-result result)
""))))
(message "%s" ""))
(unless (zerop skipped)
(message "%s skipped results:" skipped)
(cl-loop for test across (ert--stats-tests stats)
for result = (ert-test-most-recent-result test) do
(when (ert-test-result-type-p result :skipped)
(message "%9s %S%s"
(ert-string-for-test-result result nil)
(ert-test-name test)
(if (plusp
(length (getenv "EMACS_TEST_VERBOSE")))
(ert-reason-for-test-result result)
""))))
(message "%s" ""))
(when (getenv "EMACS_TEST_JUNIT_REPORT")
(ert-write-junit-test-report stats)))))
(test-started)
(test-ended
(cl-destructuring-bind (stats test result) event-args
(unless (ert-test-result-expected-p test result)
(cl-etypecase result
(ert-test-passed
(message "Test %S passed unexpectedly" (ert-test-name test)))
(ert-test-result-with-condition
(message "Test %S backtrace:" (ert-test-name test))
(with-temp-buffer
(let ((backtrace-line-length
(if (eq ert-batch-backtrace-line-length t)
backtrace-line-length
ert-batch-backtrace-line-length))
(print-level ert-batch-print-level)
(print-length ert-batch-print-length))
(insert (backtrace-to-string
(ert-test-result-with-condition-backtrace result))))
(if (not ert-batch-backtrace-right-margin)
(message "%s"
(buffer-substring-no-properties (point-min)
(point-max)))
(goto-char (point-min))
(while (not (eobp))
(let ((start (point))
(end (line-end-position)))
(setq end (min end
(+ start
ert-batch-backtrace-right-margin)))
(message "%s" (buffer-substring-no-properties
start end)))
(forward-line 1))))
(with-temp-buffer
(ert--insert-infos result)
(insert " ")
(let ((print-escape-newlines t)
(print-level ert-batch-print-level)
(print-length ert-batch-print-length))
(ert--pp-with-indentation-and-newline
(ert-test-result-with-condition-condition result)))
(goto-char (1- (point-max)))
(cl-assert (looking-at "\n"))
(delete-char 1)
(message "Test %S condition:" (ert-test-name test))
(message "%s" (buffer-string))))
(ert-test-aborted-with-non-local-exit
(message "Test %S aborted with non-local exit"
(ert-test-name test)))
(ert-test-quit
(message "Quit during %S" (ert-test-name test)))))
(unless ert-quiet
(let* ((max (prin1-to-string (length (ert--stats-tests stats))))
(format-string (concat "%9s %"
(prin1-to-string (length max))
"s/" max " %S (%f sec)%s")))
(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-result-duration result)
(if (ert-test-result-expected-p test result)
""
(concat " " (ert-test-location test))))))))))
nil))