]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix ert-font-lock macro signatures
authorBasil L. Contovounesios <basil@contovou.net>
Thu, 20 Feb 2025 09:29:54 +0000 (10:29 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 20:49:50 +0000 (21:49 +0100)
* doc/misc/ert.texi (Syntax Highlighting Tests):
* test/lisp/emacs-lisp/ert-font-lock-tests.el
(test-line-comment-p--emacs-lisp, test-line-comment-p--shell-script)
(test-line-comment-p--javascript, test-line-comment-p--python)
(test-line-comment-p--c, test-macro-test--correct-highlighting)
(test-macro-test--docstring, test-macro-test--failing)
(test-macro-test--file, test-macro-test--file-no-asserts)
(test-macro-test--file-failing): Reindent macro calls.
(with-temp-buffer-str-mode): Evaluate macro arguments left-to-right.
(ert-font-lock--wrap-begin-end): Use rx for more robust composition.
(test-line-comment-p--php): Require that php-mode is callable, not
already loaded.

* lisp/emacs-lisp/ert-font-lock.el (ert-font-lock-deftest)
(ert-font-lock-deftest-file): NAME is not followed by an empty list
like in ert-deftest, so the optional DOCSTRING is actually the
second argument.  Adapt calling convention in docstring, and debug,
doc-string, and indent properties accordingly (bug#76372).  Fix
docstring grammar, document MAJOR-MODE, and avoid referring to a
file name as a path.

(cherry picked from commit 02c830ba22b0564f6725cd403beba4accb836061)

doc/misc/ert.texi
lisp/emacs-lisp/ert-font-lock.el
test/lisp/emacs-lisp/ert-font-lock-tests.el

index d4aa60f829993afe8a4643f93e293e17f6d055c3..93f4a58de8602268b2e2dc0fe4ecd06ac97ba77d 100644 (file)
@@ -958,7 +958,7 @@ checking face assignment.  Test assertions are included in code-level
 comments directly and can be read either from inline strings or files.
 The parser expects the input string to contain at least one assertion.
 
-Test assertion parser extracts tests from comment-only lines.  Every
+The test assertion parser extracts tests from comment-only lines.  Every
 comment assertion line starts either with a caret (@samp{^}) or an arrow
 (@samp{<-}).  A single caret/arrow or carets should be followed
 immediately by the name of a face or a list of faces to be checked
@@ -980,7 +980,7 @@ var variable = 11;
 @end example
 
 Both symbol-only @code{:face} property values and assertion face values
-are normalized to single element lists so assertions below are
+are normalized to single element lists so the assertions below are
 equivalent:
 
 @example
@@ -1057,7 +1057,7 @@ definition:
 
 @lisp
 (ert-font-lock-deftest test-macro-test--inline
-    emacs-lisp-mode
+  emacs-lisp-mode
   "
 (defun fun ())
 ;; ^ font-lock-keyword-face
@@ -1071,13 +1071,13 @@ file:
 
 @lisp
 (ert-font-lock-deftest-file test-macro-test--file
-    "Test reading correct assertions from a file"
+  "Test reading correct assertions from a file."
   javascript-mode
   "correct.js")
 @end lisp
 
 The @code{ert-font-lock-deftest} and @code{ert-font-lock-deftest-file}
-macros accept the same keyword parameters as @code{ert-deftest} i.e.,
+macros accept the same keyword arguments as @code{ert-deftest}, i.e.,
 @code{:tag} and @code{:expected-result}.
 
 
index e584eb679fda8c0106446a5c4ec28c45dac7a96e..80f4a6d54678afaa35ccc59a9d64abad11ae85b7 100644 (file)
@@ -27,8 +27,8 @@
 ;; highlighting provided by font-lock.
 ;;
 ;; ert-font-lock entry points are functions
-;; `ert-font-lock-test-string' and `ert-font-lock-test-file' and
-;; convenience macros: `ert-font-lock-deftest' and
+;; `ert-font-lock-test-string' and `ert-font-lock-test-file', and
+;; convenience macros `ert-font-lock-deftest' and
 ;; `ert-font-lock-deftest-file'.
 ;;
 ;; See unit tests in ert-font-lock-tests.el for usage examples.
@@ -124,19 +124,21 @@ Argument TEST-NAME - name of the currently running ert test."
 (defmacro ert-font-lock-deftest (name &rest docstring-keys-mode-and-str)
   "Define test NAME (a symbol) using assertions from TEST-STR.
 
-Other than MAJOR-MODE and TEST-STR parameters, this macro accepts
-the same parameters and keywords as `ert-deftest' and is intended
-to be used through `ert'.
+The MAJOR-MODE symbol determines the syntax and font lock of TEST-STR.
 
-\(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \
+Except for the MAJOR-MODE and TEST-STR parameters, this macro accepts
+the same arguments and keywords as `ert-deftest' and is intended to be
+used through `ert'.
+
+\(fn NAME [DOCSTRING] [:expected-result RESULT-TYPE] \
 [:tags \\='(TAG...)] MAJOR-MODE TEST-STR)"
   (declare (debug (&define [&name "test@" symbolp]
-                           sexp [&optional stringp]
+                           [&optional stringp]
                            [&rest keywordp sexp]
                            symbolp
                            stringp))
-           (doc-string 3)
-           (indent 2))
+           (doc-string 2)
+           (indent 1))
   (pcase-let ((`(,documentation
                  ,documentation-supplied-p
                  ,keys ,mode ,arg)
@@ -159,22 +161,23 @@ to be used through `ert'.
 (defmacro ert-font-lock-deftest-file (name &rest docstring-keys-mode-and-file)
   "Define test NAME (a symbol) using assertions from FILE.
 
-FILE - path to a file with assertions in ERT resource director as
-return by `ert-resource-directory'.
+FILE names a file with assertions in the ERT resource directory, as
+returned by `ert-resource-directory'.  The MAJOR-MODE symbol determines
+the syntax and font lock of FILE's contents.
 
-Other than MAJOR-MODE and FILE parameters, this macro accepts the
-same parameters and keywords as `ert-deftest' and is intended to
-be used through `ert'.
+Except for the MAJOR-MODE and FILE parameters, this macro accepts the
+same arguments and keywords as `ert-deftest' and is intended to be used
+through `ert'.
 
-\(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \
+\(fn NAME [DOCSTRING] [:expected-result RESULT-TYPE] \
 [:tags \\='(TAG...)] MAJOR-MODE FILE)"
   (declare (debug (&define [&name "test@" symbolp]
-                           sexp [&optional stringp]
+                           [&optional stringp]
                            [&rest keywordp sexp]
                            symbolp
                            stringp))
-           (doc-string 3)
-           (indent 2))
+           (doc-string 2)
+           (indent 1))
 
   (pcase-let ((`(,documentation
                  ,documentation-supplied-p
index e410cf5fa138fcb8a5bd0a822787c2762bd9bd74..0c3e440556269c5ecd8f5dcf0ae37bef0c5f3939 100644 (file)
   "Create a buffer with STR contents and MODE. "
   (declare (indent 1) (debug t))
   `(with-temp-buffer
-     (insert ,str)
      (,mode)
+     (insert ,str)
      (goto-char (point-min))
      ,@body))
 
 (defun ert-font-lock--wrap-begin-end (re)
-  (concat "^" re "$"))
+  (rx bol (regexp re) eol))
 
 ;;; Regexp tests
 ;;;
 
 (ert-deftest test-line-comment-p--emacs-lisp ()
   (with-temp-buffer-str-mode emacs-lisp-mode
-                             "not comment
+    "not comment
 ;; comment
 "
-                             (should-not (ert-font-lock--line-comment-p))
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))
-                             (forward-line)
-                             (should-not (ert-font-lock--line-comment-p))))
+    (should-not (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should-not (ert-font-lock--line-comment-p))))
 
 (ert-deftest test-line-comment-p--shell-script ()
   (with-temp-buffer-str-mode shell-script-mode
-                             "echo Not a comment
+    "echo Not a comment
 # comment
 "
-                             (should-not (ert-font-lock--line-comment-p))
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))))
+    (should-not (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))))
 
 (declare-function php-mode "php-mode")
 (ert-deftest test-line-comment-p--php ()
-  (skip-unless (featurep 'php-mode))
+  (skip-unless (fboundp 'php-mode))
 
   (with-temp-buffer-str-mode php-mode
-                             "echo 'Not a comment'
+    "echo 'Not a comment'
 // comment
 /* comment */
 "
-                             (should-not (ert-font-lock--line-comment-p))
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))))
+    (should-not (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))))
 
 
 (ert-deftest test-line-comment-p--javascript ()
   (with-temp-buffer-str-mode javascript-mode
-                             "// comment
+    "// comment
 
    // comment, after a blank line
 
 var abc = function(d) {};
 "
-                             (should (ert-font-lock--line-comment-p))
+    (should (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should-not (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should-not (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should-not (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should-not (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should-not (ert-font-lock--line-comment-p))))
+    (forward-line)
+    (should-not (ert-font-lock--line-comment-p))))
 
 (ert-deftest test-line-comment-p--python ()
 
   (with-temp-buffer-str-mode python-mode
-                             "# comment
+    "# comment
 
    # comment
 print(\"Hello, world!\")"
-                             (should (ert-font-lock--line-comment-p))
+    (should (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should-not (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should-not (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should-not (ert-font-lock--line-comment-p))))
+    (forward-line)
+    (should-not (ert-font-lock--line-comment-p))))
 
 (ert-deftest test-line-comment-p--c ()
 
   (with-temp-buffer-str-mode c-mode
-                             "// comment
+    "// comment
 /* also comment */"
-                             (should (ert-font-lock--line-comment-p))
+    (should (ert-font-lock--line-comment-p))
 
-                             (forward-line)
-                             (should (ert-font-lock--line-comment-p))))
+    (forward-line)
+    (should (ert-font-lock--line-comment-p))))
 
 (ert-deftest test-parse-comments--no-assertion-error ()
   (let* ((str "
@@ -568,14 +568,14 @@ var abc = function(d) {
 ;;
 
 (ert-font-lock-deftest test-macro-test--correct-highlighting
-    emacs-lisp-mode
+  emacs-lisp-mode
   "
 (defun fun ())
 ;; ^ font-lock-keyword-face
 ;;      ^ font-lock-function-name-face")
 
 (ert-font-lock-deftest test-macro-test--docstring
-    "A test with a docstring."
+  "A test with a docstring."
   emacs-lisp-mode
   "
 (defun fun ())
@@ -583,7 +583,7 @@ var abc = function(d) {
   )
 
 (ert-font-lock-deftest test-macro-test--failing
-    "A failing test."
+  "A failing test."
   :expected-result :failed
   emacs-lisp-mode
   "
@@ -591,18 +591,18 @@ var abc = function(d) {
 ;; ^ wrong-face")
 
 (ert-font-lock-deftest-file test-macro-test--file
-    "Test reading correct assertions from a file"
+  "Test reading correct assertions from a file."
   javascript-mode
   "correct.js")
 
 (ert-font-lock-deftest-file test-macro-test--file-no-asserts
-    "Check failing on files without assertions"
+  "Check failing on files without assertions."
   :expected-result :failed
   javascript-mode
   "no-asserts.js")
 
 (ert-font-lock-deftest-file test-macro-test--file-failing
-    "Test reading wrong assertions from a file"
+  "Test reading wrong assertions from a file."
   :expected-result :failed
   javascript-mode
   "broken.js")