1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-01 01:41:01 -08:00

Signal an error for duplicated ERT tests (bug#51941)

Make `ert-deftest` fail with an error (in batch mode only) if an
existing test is redefined, because that is an easy mistake to make
and which leads to a test being discarded silently.

lisp/emacs-lisp/ert.el (ert-set-test, ert-deftest): Add check.
etc/NEWS: Announce.
This commit is contained in:
Mattias Engdegård 2021-11-18 12:18:24 +01:00
parent f41c6a70e7
commit 67ffcc5c7f
2 changed files with 14 additions and 0 deletions

View file

@ -151,6 +151,10 @@ in batch mode.")
;; Note that nil is still a valid value for the `name' slot in
;; ert-test objects. It designates an anonymous test.
(error "Attempt to define a test named nil"))
(when (and noninteractive (get symbol 'ert--test))
;; Make sure duplicated tests are discovered since the older test would
;; be ignored silently otherwise.
(error "Test `%s' redefined" symbol))
(define-symbol-prop symbol 'ert--test definition)
definition)
@ -206,6 +210,9 @@ Macros in BODY are expanded when the test is defined, not when it
is run. If a macro (possibly with side effects) is to be tested,
it has to be wrapped in `(eval (quote ...))'.
If NAME is already defined as a test and Emacs is running
in batch mode, an error is signalled.
\(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \
[:tags \\='(TAG...)] BODY...)"
(declare (debug (&define [&name "test@" symbolp]