diff options
| author | Basil L. Contovounesios | 2025-02-20 10:29:54 +0100 |
|---|---|---|
| committer | Basil L. Contovounesios | 2025-02-25 11:02:55 +0100 |
| commit | 02c830ba22b0564f6725cd403beba4accb836061 (patch) | |
| tree | b7e74c0a1b57b0b2c9d4eaab61766a6cde91b249 | |
| parent | 0c6b8643aec24935f82c63d43219f26378e3e578 (diff) | |
| download | emacs-02c830ba22b0564f6725cd403beba4accb836061.tar.gz emacs-02c830ba22b0564f6725cd403beba4accb836061.zip | |
Fix ert-font-lock macro signatures
* 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.
| -rw-r--r-- | doc/misc/ert.texi | 10 | ||||
| -rw-r--r-- | lisp/emacs-lisp/ert-font-lock.el | 39 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/ert-font-lock-tests.el | 94 |
3 files changed, 73 insertions, 70 deletions
diff --git a/doc/misc/ert.texi b/doc/misc/ert.texi index 9e60647f3ba..e0cc415fa93 100644 --- a/doc/misc/ert.texi +++ b/doc/misc/ert.texi | |||
| @@ -955,7 +955,7 @@ checking face assignment. Test assertions are included in code-level | |||
| 955 | comments directly and can be read either from inline strings or files. | 955 | comments directly and can be read either from inline strings or files. |
| 956 | The parser expects the input string to contain at least one assertion. | 956 | The parser expects the input string to contain at least one assertion. |
| 957 | 957 | ||
| 958 | Test assertion parser extracts tests from comment-only lines. Every | 958 | The test assertion parser extracts tests from comment-only lines. Every |
| 959 | comment assertion line starts either with a caret (@samp{^}) or an arrow | 959 | comment assertion line starts either with a caret (@samp{^}) or an arrow |
| 960 | (@samp{<-}). A single caret/arrow or carets should be followed | 960 | (@samp{<-}). A single caret/arrow or carets should be followed |
| 961 | immediately by the name of a face or a list of faces to be checked | 961 | immediately by the name of a face or a list of faces to be checked |
| @@ -977,7 +977,7 @@ var variable = 11; | |||
| 977 | @end example | 977 | @end example |
| 978 | 978 | ||
| 979 | Both symbol-only @code{:face} property values and assertion face values | 979 | Both symbol-only @code{:face} property values and assertion face values |
| 980 | are normalized to single element lists so assertions below are | 980 | are normalized to single element lists so the assertions below are |
| 981 | equivalent: | 981 | equivalent: |
| 982 | 982 | ||
| 983 | @example | 983 | @example |
| @@ -1054,7 +1054,7 @@ definition: | |||
| 1054 | 1054 | ||
| 1055 | @lisp | 1055 | @lisp |
| 1056 | (ert-font-lock-deftest test-macro-test--inline | 1056 | (ert-font-lock-deftest test-macro-test--inline |
| 1057 | emacs-lisp-mode | 1057 | emacs-lisp-mode |
| 1058 | " | 1058 | " |
| 1059 | (defun fun ()) | 1059 | (defun fun ()) |
| 1060 | ;; ^ font-lock-keyword-face | 1060 | ;; ^ font-lock-keyword-face |
| @@ -1068,13 +1068,13 @@ file: | |||
| 1068 | 1068 | ||
| 1069 | @lisp | 1069 | @lisp |
| 1070 | (ert-font-lock-deftest-file test-macro-test--file | 1070 | (ert-font-lock-deftest-file test-macro-test--file |
| 1071 | "Test reading correct assertions from a file" | 1071 | "Test reading correct assertions from a file." |
| 1072 | javascript-mode | 1072 | javascript-mode |
| 1073 | "correct.js") | 1073 | "correct.js") |
| 1074 | @end lisp | 1074 | @end lisp |
| 1075 | 1075 | ||
| 1076 | The @code{ert-font-lock-deftest} and @code{ert-font-lock-deftest-file} | 1076 | The @code{ert-font-lock-deftest} and @code{ert-font-lock-deftest-file} |
| 1077 | macros accept the same keyword parameters as @code{ert-deftest} i.e., | 1077 | macros accept the same keyword arguments as @code{ert-deftest}, i.e., |
| 1078 | @code{:tag} and @code{:expected-result}. | 1078 | @code{:tag} and @code{:expected-result}. |
| 1079 | 1079 | ||
| 1080 | @node How to Debug Tests | 1080 | @node How to Debug Tests |
diff --git a/lisp/emacs-lisp/ert-font-lock.el b/lisp/emacs-lisp/ert-font-lock.el index e584eb679fd..80f4a6d5467 100644 --- a/lisp/emacs-lisp/ert-font-lock.el +++ b/lisp/emacs-lisp/ert-font-lock.el | |||
| @@ -27,8 +27,8 @@ | |||
| 27 | ;; highlighting provided by font-lock. | 27 | ;; highlighting provided by font-lock. |
| 28 | ;; | 28 | ;; |
| 29 | ;; ert-font-lock entry points are functions | 29 | ;; ert-font-lock entry points are functions |
| 30 | ;; `ert-font-lock-test-string' and `ert-font-lock-test-file' and | 30 | ;; `ert-font-lock-test-string' and `ert-font-lock-test-file', and |
| 31 | ;; convenience macros: `ert-font-lock-deftest' and | 31 | ;; convenience macros `ert-font-lock-deftest' and |
| 32 | ;; `ert-font-lock-deftest-file'. | 32 | ;; `ert-font-lock-deftest-file'. |
| 33 | ;; | 33 | ;; |
| 34 | ;; See unit tests in ert-font-lock-tests.el for usage examples. | 34 | ;; 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." | |||
| 124 | (defmacro ert-font-lock-deftest (name &rest docstring-keys-mode-and-str) | 124 | (defmacro ert-font-lock-deftest (name &rest docstring-keys-mode-and-str) |
| 125 | "Define test NAME (a symbol) using assertions from TEST-STR. | 125 | "Define test NAME (a symbol) using assertions from TEST-STR. |
| 126 | 126 | ||
| 127 | Other than MAJOR-MODE and TEST-STR parameters, this macro accepts | 127 | The MAJOR-MODE symbol determines the syntax and font lock of TEST-STR. |
| 128 | the same parameters and keywords as `ert-deftest' and is intended | ||
| 129 | to be used through `ert'. | ||
| 130 | 128 | ||
| 131 | \(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \ | 129 | Except for the MAJOR-MODE and TEST-STR parameters, this macro accepts |
| 130 | the same arguments and keywords as `ert-deftest' and is intended to be | ||
| 131 | used through `ert'. | ||
| 132 | |||
| 133 | \(fn NAME [DOCSTRING] [:expected-result RESULT-TYPE] \ | ||
| 132 | [:tags \\='(TAG...)] MAJOR-MODE TEST-STR)" | 134 | [:tags \\='(TAG...)] MAJOR-MODE TEST-STR)" |
| 133 | (declare (debug (&define [&name "test@" symbolp] | 135 | (declare (debug (&define [&name "test@" symbolp] |
| 134 | sexp [&optional stringp] | 136 | [&optional stringp] |
| 135 | [&rest keywordp sexp] | 137 | [&rest keywordp sexp] |
| 136 | symbolp | 138 | symbolp |
| 137 | stringp)) | 139 | stringp)) |
| 138 | (doc-string 3) | 140 | (doc-string 2) |
| 139 | (indent 2)) | 141 | (indent 1)) |
| 140 | (pcase-let ((`(,documentation | 142 | (pcase-let ((`(,documentation |
| 141 | ,documentation-supplied-p | 143 | ,documentation-supplied-p |
| 142 | ,keys ,mode ,arg) | 144 | ,keys ,mode ,arg) |
| @@ -159,22 +161,23 @@ to be used through `ert'. | |||
| 159 | (defmacro ert-font-lock-deftest-file (name &rest docstring-keys-mode-and-file) | 161 | (defmacro ert-font-lock-deftest-file (name &rest docstring-keys-mode-and-file) |
| 160 | "Define test NAME (a symbol) using assertions from FILE. | 162 | "Define test NAME (a symbol) using assertions from FILE. |
| 161 | 163 | ||
| 162 | FILE - path to a file with assertions in ERT resource director as | 164 | FILE names a file with assertions in the ERT resource directory, as |
| 163 | return by `ert-resource-directory'. | 165 | returned by `ert-resource-directory'. The MAJOR-MODE symbol determines |
| 166 | the syntax and font lock of FILE's contents. | ||
| 164 | 167 | ||
| 165 | Other than MAJOR-MODE and FILE parameters, this macro accepts the | 168 | Except for the MAJOR-MODE and FILE parameters, this macro accepts the |
| 166 | same parameters and keywords as `ert-deftest' and is intended to | 169 | same arguments and keywords as `ert-deftest' and is intended to be used |
| 167 | be used through `ert'. | 170 | through `ert'. |
| 168 | 171 | ||
| 169 | \(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \ | 172 | \(fn NAME [DOCSTRING] [:expected-result RESULT-TYPE] \ |
| 170 | [:tags \\='(TAG...)] MAJOR-MODE FILE)" | 173 | [:tags \\='(TAG...)] MAJOR-MODE FILE)" |
| 171 | (declare (debug (&define [&name "test@" symbolp] | 174 | (declare (debug (&define [&name "test@" symbolp] |
| 172 | sexp [&optional stringp] | 175 | [&optional stringp] |
| 173 | [&rest keywordp sexp] | 176 | [&rest keywordp sexp] |
| 174 | symbolp | 177 | symbolp |
| 175 | stringp)) | 178 | stringp)) |
| 176 | (doc-string 3) | 179 | (doc-string 2) |
| 177 | (indent 2)) | 180 | (indent 1)) |
| 178 | 181 | ||
| 179 | (pcase-let ((`(,documentation | 182 | (pcase-let ((`(,documentation |
| 180 | ,documentation-supplied-p | 183 | ,documentation-supplied-p |
diff --git a/test/lisp/emacs-lisp/ert-font-lock-tests.el b/test/lisp/emacs-lisp/ert-font-lock-tests.el index e410cf5fa13..0c3e4405562 100644 --- a/test/lisp/emacs-lisp/ert-font-lock-tests.el +++ b/test/lisp/emacs-lisp/ert-font-lock-tests.el | |||
| @@ -39,13 +39,13 @@ | |||
| 39 | "Create a buffer with STR contents and MODE. " | 39 | "Create a buffer with STR contents and MODE. " |
| 40 | (declare (indent 1) (debug t)) | 40 | (declare (indent 1) (debug t)) |
| 41 | `(with-temp-buffer | 41 | `(with-temp-buffer |
| 42 | (insert ,str) | ||
| 43 | (,mode) | 42 | (,mode) |
| 43 | (insert ,str) | ||
| 44 | (goto-char (point-min)) | 44 | (goto-char (point-min)) |
| 45 | ,@body)) | 45 | ,@body)) |
| 46 | 46 | ||
| 47 | (defun ert-font-lock--wrap-begin-end (re) | 47 | (defun ert-font-lock--wrap-begin-end (re) |
| 48 | (concat "^" re "$")) | 48 | (rx bol (regexp re) eol)) |
| 49 | 49 | ||
| 50 | ;;; Regexp tests | 50 | ;;; Regexp tests |
| 51 | ;;; | 51 | ;;; |
| @@ -97,89 +97,89 @@ | |||
| 97 | 97 | ||
| 98 | (ert-deftest test-line-comment-p--emacs-lisp () | 98 | (ert-deftest test-line-comment-p--emacs-lisp () |
| 99 | (with-temp-buffer-str-mode emacs-lisp-mode | 99 | (with-temp-buffer-str-mode emacs-lisp-mode |
| 100 | "not comment | 100 | "not comment |
| 101 | ;; comment | 101 | ;; comment |
| 102 | " | 102 | " |
| 103 | (should-not (ert-font-lock--line-comment-p)) | 103 | (should-not (ert-font-lock--line-comment-p)) |
| 104 | (forward-line) | 104 | (forward-line) |
| 105 | (should (ert-font-lock--line-comment-p)) | 105 | (should (ert-font-lock--line-comment-p)) |
| 106 | (forward-line) | 106 | (forward-line) |
| 107 | (should-not (ert-font-lock--line-comment-p)))) | 107 | (should-not (ert-font-lock--line-comment-p)))) |
| 108 | 108 | ||
| 109 | (ert-deftest test-line-comment-p--shell-script () | 109 | (ert-deftest test-line-comment-p--shell-script () |
| 110 | (with-temp-buffer-str-mode shell-script-mode | 110 | (with-temp-buffer-str-mode shell-script-mode |
| 111 | "echo Not a comment | 111 | "echo Not a comment |
| 112 | # comment | 112 | # comment |
| 113 | " | 113 | " |
| 114 | (should-not (ert-font-lock--line-comment-p)) | 114 | (should-not (ert-font-lock--line-comment-p)) |
| 115 | (forward-line) | 115 | (forward-line) |
| 116 | (should (ert-font-lock--line-comment-p)))) | 116 | (should (ert-font-lock--line-comment-p)))) |
| 117 | 117 | ||
| 118 | (declare-function php-mode "php-mode") | 118 | (declare-function php-mode "php-mode") |
| 119 | (ert-deftest test-line-comment-p--php () | 119 | (ert-deftest test-line-comment-p--php () |
| 120 | (skip-unless (featurep 'php-mode)) | 120 | (skip-unless (fboundp 'php-mode)) |
| 121 | 121 | ||
| 122 | (with-temp-buffer-str-mode php-mode | 122 | (with-temp-buffer-str-mode php-mode |
| 123 | "echo 'Not a comment' | 123 | "echo 'Not a comment' |
| 124 | // comment | 124 | // comment |
| 125 | /* comment */ | 125 | /* comment */ |
| 126 | " | 126 | " |
| 127 | (should-not (ert-font-lock--line-comment-p)) | 127 | (should-not (ert-font-lock--line-comment-p)) |
| 128 | (forward-line) | 128 | (forward-line) |
| 129 | (should (ert-font-lock--line-comment-p)) | 129 | (should (ert-font-lock--line-comment-p)) |
| 130 | (forward-line) | 130 | (forward-line) |
| 131 | (should (ert-font-lock--line-comment-p)))) | 131 | (should (ert-font-lock--line-comment-p)))) |
| 132 | 132 | ||
| 133 | 133 | ||
| 134 | (ert-deftest test-line-comment-p--javascript () | 134 | (ert-deftest test-line-comment-p--javascript () |
| 135 | (with-temp-buffer-str-mode javascript-mode | 135 | (with-temp-buffer-str-mode javascript-mode |
| 136 | "// comment | 136 | "// comment |
| 137 | 137 | ||
| 138 | // comment, after a blank line | 138 | // comment, after a blank line |
| 139 | 139 | ||
| 140 | var abc = function(d) {}; | 140 | var abc = function(d) {}; |
| 141 | " | 141 | " |
| 142 | (should (ert-font-lock--line-comment-p)) | 142 | (should (ert-font-lock--line-comment-p)) |
| 143 | 143 | ||
| 144 | (forward-line) | 144 | (forward-line) |
| 145 | (should-not (ert-font-lock--line-comment-p)) | 145 | (should-not (ert-font-lock--line-comment-p)) |
| 146 | 146 | ||
| 147 | (forward-line) | 147 | (forward-line) |
| 148 | (should (ert-font-lock--line-comment-p)) | 148 | (should (ert-font-lock--line-comment-p)) |
| 149 | 149 | ||
| 150 | (forward-line) | 150 | (forward-line) |
| 151 | (should-not (ert-font-lock--line-comment-p)) | 151 | (should-not (ert-font-lock--line-comment-p)) |
| 152 | 152 | ||
| 153 | (forward-line) | 153 | (forward-line) |
| 154 | (should-not (ert-font-lock--line-comment-p)))) | 154 | (should-not (ert-font-lock--line-comment-p)))) |
| 155 | 155 | ||
| 156 | (ert-deftest test-line-comment-p--python () | 156 | (ert-deftest test-line-comment-p--python () |
| 157 | 157 | ||
| 158 | (with-temp-buffer-str-mode python-mode | 158 | (with-temp-buffer-str-mode python-mode |
| 159 | "# comment | 159 | "# comment |
| 160 | 160 | ||
| 161 | # comment | 161 | # comment |
| 162 | print(\"Hello, world!\")" | 162 | print(\"Hello, world!\")" |
| 163 | (should (ert-font-lock--line-comment-p)) | 163 | (should (ert-font-lock--line-comment-p)) |
| 164 | 164 | ||
| 165 | (forward-line) | 165 | (forward-line) |
| 166 | (should-not (ert-font-lock--line-comment-p)) | 166 | (should-not (ert-font-lock--line-comment-p)) |
| 167 | 167 | ||
| 168 | (forward-line) | 168 | (forward-line) |
| 169 | (should (ert-font-lock--line-comment-p)) | 169 | (should (ert-font-lock--line-comment-p)) |
| 170 | 170 | ||
| 171 | (forward-line) | 171 | (forward-line) |
| 172 | (should-not (ert-font-lock--line-comment-p)))) | 172 | (should-not (ert-font-lock--line-comment-p)))) |
| 173 | 173 | ||
| 174 | (ert-deftest test-line-comment-p--c () | 174 | (ert-deftest test-line-comment-p--c () |
| 175 | 175 | ||
| 176 | (with-temp-buffer-str-mode c-mode | 176 | (with-temp-buffer-str-mode c-mode |
| 177 | "// comment | 177 | "// comment |
| 178 | /* also comment */" | 178 | /* also comment */" |
| 179 | (should (ert-font-lock--line-comment-p)) | 179 | (should (ert-font-lock--line-comment-p)) |
| 180 | 180 | ||
| 181 | (forward-line) | 181 | (forward-line) |
| 182 | (should (ert-font-lock--line-comment-p)))) | 182 | (should (ert-font-lock--line-comment-p)))) |
| 183 | 183 | ||
| 184 | (ert-deftest test-parse-comments--no-assertion-error () | 184 | (ert-deftest test-parse-comments--no-assertion-error () |
| 185 | (let* ((str " | 185 | (let* ((str " |
| @@ -568,14 +568,14 @@ var abc = function(d) { | |||
| 568 | ;; | 568 | ;; |
| 569 | 569 | ||
| 570 | (ert-font-lock-deftest test-macro-test--correct-highlighting | 570 | (ert-font-lock-deftest test-macro-test--correct-highlighting |
| 571 | emacs-lisp-mode | 571 | emacs-lisp-mode |
| 572 | " | 572 | " |
| 573 | (defun fun ()) | 573 | (defun fun ()) |
| 574 | ;; ^ font-lock-keyword-face | 574 | ;; ^ font-lock-keyword-face |
| 575 | ;; ^ font-lock-function-name-face") | 575 | ;; ^ font-lock-function-name-face") |
| 576 | 576 | ||
| 577 | (ert-font-lock-deftest test-macro-test--docstring | 577 | (ert-font-lock-deftest test-macro-test--docstring |
| 578 | "A test with a docstring." | 578 | "A test with a docstring." |
| 579 | emacs-lisp-mode | 579 | emacs-lisp-mode |
| 580 | " | 580 | " |
| 581 | (defun fun ()) | 581 | (defun fun ()) |
| @@ -583,7 +583,7 @@ var abc = function(d) { | |||
| 583 | ) | 583 | ) |
| 584 | 584 | ||
| 585 | (ert-font-lock-deftest test-macro-test--failing | 585 | (ert-font-lock-deftest test-macro-test--failing |
| 586 | "A failing test." | 586 | "A failing test." |
| 587 | :expected-result :failed | 587 | :expected-result :failed |
| 588 | emacs-lisp-mode | 588 | emacs-lisp-mode |
| 589 | " | 589 | " |
| @@ -591,18 +591,18 @@ var abc = function(d) { | |||
| 591 | ;; ^ wrong-face") | 591 | ;; ^ wrong-face") |
| 592 | 592 | ||
| 593 | (ert-font-lock-deftest-file test-macro-test--file | 593 | (ert-font-lock-deftest-file test-macro-test--file |
| 594 | "Test reading correct assertions from a file" | 594 | "Test reading correct assertions from a file." |
| 595 | javascript-mode | 595 | javascript-mode |
| 596 | "correct.js") | 596 | "correct.js") |
| 597 | 597 | ||
| 598 | (ert-font-lock-deftest-file test-macro-test--file-no-asserts | 598 | (ert-font-lock-deftest-file test-macro-test--file-no-asserts |
| 599 | "Check failing on files without assertions" | 599 | "Check failing on files without assertions." |
| 600 | :expected-result :failed | 600 | :expected-result :failed |
| 601 | javascript-mode | 601 | javascript-mode |
| 602 | "no-asserts.js") | 602 | "no-asserts.js") |
| 603 | 603 | ||
| 604 | (ert-font-lock-deftest-file test-macro-test--file-failing | 604 | (ert-font-lock-deftest-file test-macro-test--file-failing |
| 605 | "Test reading wrong assertions from a file" | 605 | "Test reading wrong assertions from a file." |
| 606 | :expected-result :failed | 606 | :expected-result :failed |
| 607 | javascript-mode | 607 | javascript-mode |
| 608 | "broken.js") | 608 | "broken.js") |