Subject: 29.0.60; `erts-run-test' does not properly set match data for `ert-test--erts-test'

From: Troy Brown <[email-masked]>
Date: Sun, 12 Mar 2023 13:31:25 -0400

`ert-test--erts-test' is expecting match data to exist (i.e., set by the
caller) for the beginning of the test.  This is used to locate the test
specification data (e.g., 'Name').  However, when this function is
invoked via `erts-run-test', it appears this match data (established by
the call to `erts-mode--goto-start-of-test') is overwritten by the call
to `erts-mode--preceding-spec' to locate "Point-Char".  In this
situation, if "Point-Char" exists in the test specification and appears
prior to "Name" in the test specification, the "Name" specification will
not be able to be located (due to the expected match location having
been moved higher in the buffer).  As a result a "No name for test case"
error will be raised.

Here is an ERTS test which can be used to reproduce this problem.
Pressing C-c C-c when in `erts-mode' with the following will exhibit the
problem.

Code:
  (lambda ()
    (fundamental-mode)
    (newline))

Point-Char: |

Name: Simple Test

=-=
Hi| there
=-=
Hi
| there
=-=-=

This particular issue can be fixed by wrapping the call to
`erts-mode--preceding-spec` with `save-match-data', but it might be even
better to incorporate that into `erts-mode--preceding-spec' itself.

   (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")))
+               (cons 'point-char
+                     (save-match-data
+                       (erts-mode--preceding-spec "Point-Char"))))
          (buffer-file-name))
       (:success (message "Test successful"))