Function: ert-read-test-name

ert-read-test-name is a byte-compiled function defined in ert.el.gz.

Signature

(ert-read-test-name PROMPT &optional DEFAULT HISTORY ADD-DEFAULT-TO-PROMPT)

Documentation

Read the name of a test and return it as a symbol.

Prompt with PROMPT. If DEFAULT is a valid test name, use it as a default. HISTORY is the history to use; see completing-read. If ADD-DEFAULT-TO-PROMPT is non-nil, PROMPT will be modified to include the default, if any.

Signals an error if no test name was read.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
;;; Some basic interactive functions.

(defun ert-read-test-name (prompt &optional default history
                                  add-default-to-prompt)
  "Read the name of a test and return it as a symbol.

Prompt with PROMPT.  If DEFAULT is a valid test name, use it as a
default.  HISTORY is the history to use; see `completing-read'.
If ADD-DEFAULT-TO-PROMPT is non-nil, PROMPT will be modified to
include the default, if any.

Signals an error if no test name was read."
  (cl-etypecase default
    (string (let ((symbol (intern-soft default)))
              (unless (and symbol (ert-test-boundp symbol))
                (setq default nil))))
    (symbol (setq default
                  (if (ert-test-boundp default)
                      (symbol-name default)
                    nil)))
    (ert-test (setq default (ert-test-name default))))
  (when add-default-to-prompt
    (setq prompt (format-prompt prompt default)))
  (let ((input (completing-read prompt obarray #'ert-test-boundp
                                t nil history default nil)))
    ;; completing-read returns an empty string if default was nil and
    ;; the user just hit enter.
    (let ((sym (intern-soft input)))
      (if (ert-test-boundp sym)
          sym
        (user-error "Input does not name a test")))))