From 67ffcc5c7f5e1adcc6f662b01c7904f977dd4f51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 18 Nov 2021 12:18:24 +0100 Subject: [PATCH] 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. --- etc/NEWS | 7 +++++++ lisp/emacs-lisp/ert.el | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 80be6c0e498..cee2844be3a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -64,6 +64,13 @@ the 'COLORTERM' environment variable is set to the value "truecolor". These variables will override 'print-length' and 'print-level' when printing Lisp values in ERT batch test results. +--- +** Redefining an ERT test in batch mode now signals an error +Executing 'ert-deftest' with the same name as an existing test causes +the previous definition to be discarded, which was probably not +intended when this occurs in batch mode. To remedy the error, rename +tests so that they all have unique names. + ** Emacs now supports Unicode Standard version 14.0. ** Emoji diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 36b4408dc8e..dc9cbc47458 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -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] -- 2.39.5