]> git.eshelyaron.com Git - emacs.git/commitdiff
Consolidate symbols ERT uses with find-function
authorEshel Yaron <me@eshelyaron.com>
Wed, 15 Jan 2025 08:47:03 +0000 (09:47 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 15 Jan 2025 08:47:03 +0000 (09:47 +0100)
lisp/emacs-lisp/ert.el
lisp/emacs-lisp/find-func.el

index 1f87059237af15dcb30aa4818f2b7e21df3f3f72..bbefa7c788c1bb6a30ddb4d132b09200614feb78 100644 (file)
@@ -245,12 +245,6 @@ in batch mode, an error is signaled.
                         :file-name ,(or (macroexp-file-name) buffer-file-name)))
          ',name))))
 
-(defvar ert--find-test-regexp
-  (concat "^\\s-*(ert-deftest"
-          find-function-space-re
-          "%s\\(\\s-\\|$\\)")
-  "The regexp the `find-function' mechanisms use for finding test definitions.")
-
 (define-error 'ert-test-failed "Test failed")
 (define-error 'ert-test-skipped "Test skipped")
 
@@ -1887,7 +1881,7 @@ default (if any)."
 (defun ert-find-test-other-window (test-name)
   "Find, in another window, the definition of TEST-NAME."
   (interactive (list (ert-read-test-name-at-point "Find test definition")))
-  (find-function-do-it test-name 'ert--test 'switch-to-buffer-other-window))
+  (find-function-do-it test-name 'ert-deftest 'switch-to-buffer-other-window))
 
 (defun ert-delete-test (test-name)
   "Make the test TEST-NAME unbound.
@@ -2467,7 +2461,9 @@ To be used in the ERT results buffer."
 
 (defun ert--test-name-button-action (button)
   "Find the definition of the test BUTTON belongs to, in another window."
-  (let ((name (button-get button 'ert-test-name)))
+  ;; Support both `insert-test-name-button' and `help-xref-button'.
+  (let ((name (or (button-get button 'ert-test-name)
+                  (car (button-get button 'help-args)))))
     (ert-find-test-other-window name)))
 
 (defun ert--ewoc-position (ewoc node)
@@ -2813,7 +2809,7 @@ To be used in the ERT results buffer."
                                       (file-name-nondirectory file-name)))
               (save-excursion
                 (re-search-backward (substitute-command-keys "`\\([^`']+\\)'"))
-                (help-xref-button 1 'help-function-def test-name file-name)))
+                (help-xref-button 1 'ert--test-name-button test-name file-name)))
             (insert ".")
             (fill-region-as-paragraph (point-min) (point))
             (insert "\n\n")
@@ -2846,7 +2842,6 @@ To be used in the ERT results buffer."
              `("ERT test" ,#'ert-test-boundp
                ,(lambda (s _b _f) (ert-describe-test s))))
 
-(add-to-list 'find-function-regexp-alist '(ert--test . ert--find-test-regexp))
 (add-to-list 'minor-mode-alist '(ert--current-run-stats
                                  (:eval
                                   (ert--tests-running-mode-line-indicator))))
@@ -2854,7 +2849,6 @@ To be used in the ERT results buffer."
 
 (defun ert--unload-function ()
   "Unload function to undo the side-effects of loading ert.el."
-  (ert--remove-from-list 'find-function-regexp-alist 'ert-deftest :key #'car)
   (ert--remove-from-list 'minor-mode-alist 'ert--current-run-stats :key #'car)
   (ert--remove-from-list 'emacs-lisp-mode-hook
                          'ert--activate-font-lock-keywords)
index 0a5938ff62ad47a8203889a4d12c0709a29e1a32..45209dc53c0c82bf2b70939e85f956698d6b15dc 100644 (file)
@@ -110,7 +110,7 @@ should insert the feature name."
   :version "25.1")
 
 (defcustom find-ert-deftest-regexp
-  "(ert-deftest +'%s"
+  (concat "^\\s-*(ert-deftest" find-function-space-re "%s\\(\\s-\\|$\\)")
   "The regexp used to search for an `ert-deftest' definition.
 Note it must contain a `%s' at the place where `format'
 should insert the feature name."