Function: ert--should-error-handle-error

ert--should-error-handle-error is a byte-compiled function defined in ert.el.gz.

Signature

(ert--should-error-handle-error FORM-DESCRIPTION-FN CONDITION TYPE EXCLUDE-SUBTYPES)

Documentation

Helper function for should-error.

Determines whether CONDITION matches TYPE and EXCLUDE-SUBTYPES, and aborts the current test as failed if it doesn't.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
(defun ert--should-error-handle-error (form-description-fn
                                       condition type exclude-subtypes)
  "Helper function for `should-error'.

Determines whether CONDITION matches TYPE and EXCLUDE-SUBTYPES,
and aborts the current test as failed if it doesn't."
  (let ((signaled-conditions (get (car condition) 'error-conditions))
        (handled-conditions (pcase-exhaustive type
                              ((pred listp) type)
                              ((pred symbolp) (list type)))))
    (cl-assert signaled-conditions)
    (unless (cl-intersection signaled-conditions handled-conditions)
      (ert-fail (append
                 (funcall form-description-fn)
                 (list
                  :condition condition
                  :fail-reason (concat "the error signaled did not"
                                       " have the expected type")))))
    (when exclude-subtypes
      (unless (member (car condition) handled-conditions)
        (ert-fail (append
                   (funcall form-description-fn)
                   (list
                    :condition condition
                    :fail-reason (concat "the error signaled was a subtype"
                                         " of the expected type"))))))))