From: Vladimir Kazanov <vekazanov@gmail.com>
To: 67621@debbugs.gnu.org
Subject: bug#67621: [PATCH] documentation for ert-font-lock
Date: Mon, 4 Dec 2023 12:19:55 +0000 [thread overview]
Message-ID: <CAAs=0-0huAp-o5CD08F+N+fiYt18f+iPzU_tm4aRSuH0OdpB0A@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 239 bytes --]
Hi team,
As (reasonably) requested in emacs-devel@ [1], sending a patch that
adds ert-font-lock to NEWS and expands the ERT manual.
[1] https://lists.gnu.org/archive/html/emacs-devel/2023-12/msg00082.html
--
Regards,
Vladimir Kazanov
[-- Attachment #2: 0001-add-ert-font-lock-docs.patch --]
[-- Type: text/x-patch, Size: 4352 bytes --]
From c0ec08349c54ce3877e9ff94bfc7c87484fc2a6e Mon Sep 17 00:00:00 2001
From: Vladimir Kazanov <vekazanov@gmail.com>
Date: Mon, 4 Dec 2023 12:07:46 +0000
Subject: [PATCH] add ert-font-lock docs
Document ert-font-lock:
* doc/misc/ert.texi: expand the manual
* etc/NEWS: mention ert-font-lock
---
doc/misc/ert.texi | 97 +++++++++++++++++++++++++++++++++++++++++++++++
etc/NEWS | 7 ++++
2 files changed, 104 insertions(+)
diff --git a/doc/misc/ert.texi b/doc/misc/ert.texi
index f4a072cf2bc..20608516e37 100644
--- a/doc/misc/ert.texi
+++ b/doc/misc/ert.texi
@@ -526,6 +526,7 @@ How to Write Tests
* Tests and Their Environment:: Don't depend on customizations; no side effects.
* Useful Techniques:: Some examples.
* erts files:: Files containing many buffer tests.
+* Syntax Highlighting Tests:: Tests for face assignment.
@end menu
@@ -942,6 +943,102 @@ erts files
If you need to use the literal line single line @samp{=-=} in a test
section, you can quote it with a @samp{\} character.
+@node Syntax Highlighting Tests
+@section Syntax Highlighting Tests
+
+Syntax highlighting is normally provided by the Font Lock minor mode
+that assigns face properties to parts of the buffer. The
+@code{ert-font-lock} package makes it possible to introduce unit tests
+checking face assignment. Test assertions are included in code-level
+comments directly and can be read either from inline strings or files.
+
+Test assertion parser extracts tests from comment-only lines. Every
+comment assertion line starts either with a caret ('^') or an arrow
+('<-'). A caret/arrow should be followed immedately by the name of a
+face to be checked.
+
+The test then checks if the first non-assertion column above the caret
+contains a face expected by the assertion:
+
+@example
+var variable = 11;
+// ^ font-lock-variable-name-face
+// ^ font-lock-literal-face
+// ^ font-lock-punctuation-face
+// this is not an assertion, it's just a comment
+// ^ font-lock-comment-face
+@end example
+
+The arrow means that the first non-empty column will be used in the
+assertion:
+
+@example
+var variable = 1;
+// <- font-lock-keyword-face
+11;
+// <- font-lock-literal-face
+@end example
+
+@findex ert-font-lock-test-string
+
+The @code{ert-font-lock-test-string} function extracts ERT assertions
+from an inline string. The @code{javascript-mode} symbol below
+specifies the major mode used for comments and font locking:
+
+@lisp
+(ert-deftest test-font-lock-test-string--correct ()
+ (ert-font-lock-test-string
+ "
+var abc = function(d) @{
+// <- font-lock-keyword-face
+// ^ font-lock-variable-name-face
+ // ^ font-lock-keyword-face
+ // ^ font-lock-variable-name-face
+@};
+"
+ 'javascript-mode))
+@end lisp
+
+@findex ert-font-lock-test-file
+
+It is also possible to extract test assertions from a file:
+
+@lisp
+(ert-deftest test-font-lock-test-file--correct ()
+ (ert-font-lock-test-file
+ (ert-resource-file "correct.js")
+ 'javascript-mode))
+@end lisp
+
+@findex ert-font-lock-deftest
+
+The @code{ert-font-lock-deftest} macro simplifies inline test
+definition:
+
+@lisp
+(ert-font-lock-deftest test-macro-test--inline
+ emacs-lisp-mode
+ "
+(defun fun ())
+;; ^ font-lock-keyword-face
+;; ^ font-lock-function-name-face")
+@end lisp
+
+@findex ert-font-lock-deftest-file
+
+The @code{ert-font-lock-deftest-file} macro reads assertions from a
+file:
+
+@lisp
+(ert-font-lock-deftest-file test-macro-test--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 parameteres as @code{ert-deftest},
+i.e. @code{:tag} and @code{:expected-result}.
@node How to Debug Tests
@chapter How to Debug Tests
diff --git a/etc/NEWS b/etc/NEWS
index 29f4e5c0b66..37e54f4865a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1102,6 +1102,13 @@ will return the URL for that bug.
*** New command 'customize-dirlocals'.
This command pops up a buffer to edit the settings in ".dir-locals.el".
+** ERT
+
++++
+*** Syntax highlighting unit testing support
+An ERT extension ('ert-font-lock') now provides support for face
+assignment unit testing.
+
\f
* New Modes and Packages in Emacs 30.1
--
2.34.1
next reply other threads:[~2023-12-04 12:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 12:19 Vladimir Kazanov [this message]
2023-12-04 13:01 ` bug#67621: [PATCH] documentation for ert-font-lock Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 13:29 ` Vladimir Kazanov
2023-12-04 14:02 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 14:42 ` Vladimir Kazanov
2023-12-04 15:15 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-08 13:47 ` Vladimir Kazanov
2023-12-08 13:56 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-09 9:29 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAs=0-0huAp-o5CD08F+N+fiYt18f+iPzU_tm4aRSuH0OdpB0A@mail.gmail.com' \
--to=vekazanov@gmail.com \
--cc=67621@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.