unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: 51941@debbugs.gnu.org
Subject: bug#51941: Detect duplication of ERT tests
Date: Thu, 18 Nov 2021 11:16:09 +0100	[thread overview]
Message-ID: <21CD2DED-354E-4C46-9794-07172E3BD5F1@acm.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]

Duplicated `ert-deftest` forms (ie, two or more definitions with the same test name) is a serious problem: the older test is silently ignored, which has the consequence of the test covering less than intended.

A quick experiment in the Emacs tree immediately reveals 51 instances. There's no telling how many lie waiting in external code.

Having explored various options I've come to the conclusion that it needs to be a hard error, at run-time, when running non-interactively (see attached diff). Rationale:

* We can't just warn at run time because tests tend to spam a lot when run and users only care about whether the tests passed and won't even look at the logs otherwise.
* We can't just warn at compile time because many tests aren't compiled at all, and where they are (as in the Emacs tree) nobody cares much about the warnings, because they are "just tests".
* We can't issue a complaint when running interactively because it's natural to keep redefining tests during development.

Since `ert-deftest` forms are often generated as a result of macro-expansion, passive static textual linting won't do.

The effect of this change will be a visible and easily remedied failure in broken test code. I volunteer to fix the first-order errors in Emacs (by renaming the clashes); domain specialists may need to help fixing secondary failures (failures in previously ignored tests).


[-- Attachment #2: ert-deftest-redefine-error.diff --]
[-- Type: application/octet-stream, Size: 661 bytes --]

diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 36b4408dc8..92a1315f13 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -151,6 +151,10 @@ ert-set-test
     ;; 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))
+    ;; If a test is redefined when running noninteractively, treat it
+    ;; as a hard error to make sure it is discovered.
+    (error "Test `%s' redefined" symbol))
   (define-symbol-prop symbol 'ert--test definition)
   definition)
 

             reply	other threads:[~2021-11-18 10:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 10:16 Mattias Engdegård [this message]
2021-11-18 10:35 ` bug#51941: Detect duplication of ERT tests Lars Ingebrigtsen
2021-11-18 11:54   ` Mattias Engdegård
2021-11-18 11:58     ` Lars Ingebrigtsen
2021-11-18 17:44     ` Lars Ingebrigtsen
2021-11-18 17:53       ` Philipp Stephani
2021-11-18 19:13       ` Mattias Engdegård
2021-11-18 19:34         ` Lars Ingebrigtsen
2021-11-18 19:43           ` Mattias Engdegård
2021-11-18 22:51         ` Glenn Morris
2021-11-19  5:28           ` Lars Ingebrigtsen
2021-11-19  9:33             ` Mattias Engdegård
2021-11-20  8:38               ` Lars Ingebrigtsen
2021-11-20  8:49                 ` Mattias Engdegård
2021-11-24  7:30   ` Ihor Radchenko
2021-11-24  8:52     ` Mattias Engdegård
2021-11-24  9:29       ` Ihor Radchenko
2021-11-24 10:00         ` Mattias Engdegård
2021-11-24 12:16           ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21CD2DED-354E-4C46-9794-07172E3BD5F1@acm.org \
    --to=mattiase@acm.org \
    --cc=51941@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).