Function: ert-run-tests-interactively

ert-run-tests-interactively is an autoloaded, interactive and byte-compiled function defined in ert.el.gz.

Signature

(ert-run-tests-interactively SELECTOR)

Documentation

Run the tests specified by SELECTOR and display the results in a buffer.

SELECTOR selects which tests to run as described in ert-select-tests when called with its second argument t. Interactively, prompt for SELECTOR; the default t means run all the defined tests.

Key Bindings

Aliases

ert

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
;;;###autoload
(defun ert-run-tests-interactively (selector)
  "Run the tests specified by SELECTOR and display the results in a buffer.

SELECTOR selects which tests to run as described in `ert-select-tests'
when called with its second argument t.  Interactively, prompt for
SELECTOR; the default t means run all the defined tests."
  (interactive
   (list (let ((default (if ert--selector-history
                            ;; Can't use `first' here as this form is
                            ;; not compiled, and `first' is not
                            ;; defined without cl.
                            (car ert--selector-history)
                          "t")))
           (read
            (completing-read (format-prompt "Run tests" default)
                             obarray #'ert-test-boundp nil nil
                             'ert--selector-history default nil)))))
  (let (buffer listener)
    (setq listener
          (lambda (event-type &rest event-args)
            (cl-ecase event-type
              (run-started
               (cl-destructuring-bind (stats) event-args
                 (setq buffer (ert--setup-results-buffer stats listener))
                 (pop-to-buffer buffer)))
              (run-ended
               (cl-destructuring-bind (stats abortedp) event-args
                 (message
                          "%sRan %s tests, %s results were as expected%s%s"
                          (if (not abortedp)
                              ""
                            "Aborted: ")
                          (ert-stats-total stats)
                          (ert-stats-completed-expected stats)
                          (let ((unexpected
                                 (ert-stats-completed-unexpected stats)))
                            (if (zerop unexpected)
                                ""
                              (format ", %s unexpected" unexpected)))
                          (let ((skipped
                                 (ert-stats-skipped stats)))
                            (if (zerop skipped)
                                ""
                              (format ", %s skipped" skipped))))
                 (ert--results-update-stats-display (with-current-buffer buffer
                                                      ert--results-ewoc)
                                                    stats)))
              (test-started
               (cl-destructuring-bind (stats test) event-args
                 (with-current-buffer buffer
                   (let* ((ewoc ert--results-ewoc)
                          (pos (ert--stats-test-pos stats test))
                          (node (ewoc-nth ewoc pos)))
                     (cl-assert node)
                     (setf (ert--ewoc-entry-test (ewoc-data node)) test)
                     (aset ert--results-progress-bar-string pos
                           (ert-char-for-test-result nil t))
                     (ert--results-update-stats-display-maybe ewoc stats)
                     (ewoc-invalidate ewoc node)))))
              (test-ended
               (cl-destructuring-bind (stats test result) event-args
                 (with-current-buffer buffer
                   (let* ((ewoc ert--results-ewoc)
                          (pos (ert--stats-test-pos stats test))
                          (node (ewoc-nth ewoc pos)))
                     (when (ert--ewoc-entry-hidden-p (ewoc-data node))
                       (setf (ert--ewoc-entry-hidden-p (ewoc-data node))
                             (ert-test-result-expected-p test result)))
                     (aset ert--results-progress-bar-string pos
                           (ert-char-for-test-result result
                                                     (ert-test-result-expected-p
                                                      test result)))
                     (ert--results-update-stats-display-maybe ewoc stats)
                     (ewoc-invalidate ewoc node))))))))
    (ert-run-tests selector listener t)))