Subject: bug#66312: 30.0.50; erts-run-test always fails

From: Augustin Chéneau (BTuin) <[email-masked]>
Date: Mon, 2 Oct 2023 21:25:44 +0200

Every time I try to use the command `erts-run-test' in erts files (such
as emacs/test/lisp/progmodes/java-ts-mode-resources/indent.erts), it
fails with the message "No name for test case".  The culprits lies in
`ert-test--erts-test' which depends on the result of a regex search run 
in another function (with match-beginning).

It probably works in batch mode (I don't know how to use it), but in
erts-mode the search is not executed so the function is not run 
correctly and fails.

By the way, is there any resource about running erts files? I looked in
the ERT manual, but there is only information on writing erts files and
executing regular ERT files.

In GNU Emacs 30.0.50 (build 23, x86_64-pc-linux-gnu, GTK+ Version
  3.24.38, cairo version 1.18.0) of 2023-10-02 built on inspiron-5567
Repository revision: 6295f2d44fa26ed141309481ec9ea1640d75e490
Repository branch: html-js-css
Windowing system distributor 'The X.Org Foundation', version 11.0.12302001
System Description: Arch Linux

Configured using:
  'configure --with-tree-sitter --with-modules --without-gconf
  PKG_CONFIG_PATH=/home/arch-aug/_opam/lib/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG
SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP
X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
   value of $LANG: fr_FR.UTF-8
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   show-paren-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   minibuffer-regexp-mode: t
   line-number-mode: t
   indent-tabs-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date subr-x
smerge-mode diff vc-git vc-dispatcher cl-loaddefs cl-lib whitespace
diff-mode easy-mmode rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd touch-screen tool-bar dnd fontset
image regexp-opt fringe tabulated-list replace newcomment text-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo gtk
x-toolkit xinput2 x multi-tty move-toolbar make-network-process emacs)

Memory information:
((conses 16 46026 10928) (symbols 48 6033 0) (strings 32 16223 1757)
  (string-bytes 1 479609) (vectors 16 11733)
  (vector-slots 8 170944 14863) (floats 8 26 21) (intervals 56 231 0)
  (buffers 992 10))

From 442afd3c365c4b960d168b1166e1dd935bde5580 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Augustin=20Ch=C3=A9neau?= <[email-masked]>
Date: Mon, 2 Oct 2023 21:00:44 +0200
Subject: [PATCH] Fix `erts-run-test' in erts-mode

The previous behaviour depended on the result of `match-beginning' run
from another function, causing an issue if another function called
ert-test--erts-test.
---
 lisp/emacs-lisp/ert.el      |  6 +++---
 lisp/progmodes/erts-mode.el | 12 +++++++-----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index d727bc94ec5..c57e7733138 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -2911,13 +2911,13 @@ ert-test-erts-file
                            (cons 'code transform))))
       ;; Find the start of a test.
       (while (re-search-forward "^=-=\n" nil t)
-        (setq gen-specs (ert-test--erts-test gen-specs file))
+        (setq gen-specs (ert-test--erts-test gen-specs file (match-beginning 0)))
         ;; Search to the end of the test.
         (re-search-forward "^=-=-=\n")))))
 
-(defun ert-test--erts-test (gen-specs file)
+(defun ert-test--erts-test (gen-specs file end)
   (let* ((file-buffer (current-buffer))
-         (specs (ert--erts-specifications (match-beginning 0)))
+         (specs (ert--erts-specifications end))
          (name (cdr (assq 'name specs)))
          (start-before (point))
          (end-after (if (re-search-forward "^=-=-=\n" nil t)
diff --git a/lisp/progmodes/erts-mode.el b/lisp/progmodes/erts-mode.el
index 8dce93eae7e..b72e1df44ca 100644
--- a/lisp/progmodes/erts-mode.el
+++ b/lisp/progmodes/erts-mode.el
@@ -178,11 +178,13 @@ erts-run-test
   (save-excursion
     (erts-mode--goto-start-of-test)
     (condition-case arg
-        (ert-test--erts-test
-         (list (cons 'dummy t)
-               (cons 'code (car (read-from-string test-function)))
-               (cons 'point-char (erts-mode--preceding-spec "Point-Char")))
-         (buffer-file-name))
+        (let ((end (point)))
+         (ert-test--erts-test
+          (list (cons 'dummy t)
+                (cons 'code (car (read-from-string test-function)))
+                (cons 'point-char (erts-mode--preceding-spec "Point-Char")))
+          (buffer-file-name)
+          end))
       (:success (message "Test successful"))
       (ert-test-failed
        (if (not verbose)
-- 
2.42.0