emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 67ffcc5 2/2: Signal an error for duplicated ERT tests (bug#51941)


From: Mattias Engdegård
Subject: master 67ffcc5 2/2: Signal an error for duplicated ERT tests (bug#51941)
Date: Thu, 18 Nov 2021 06:27:14 -0500 (EST)

branch: master
commit 67ffcc5c7f5e1adcc6f662b01c7904f977dd4f51
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    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 80be6c0..cee2844 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 36b4408..dc9cbc4 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]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]