diff options
| author | Benjamin Kästner <benjamin.kaestner@gmail.com> | 2026-04-10 18:10:52 +0200 |
|---|---|---|
| committer | Benjamin Kästner <benjamin.kaestner@gmail.com> | 2026-04-10 18:29:24 +0200 |
| commit | 742054c713ddaac3a0a674faa1cd2731baf74359 (patch) | |
| tree | 71b1c232734dbb0da2fb0674a42584b0e89d47b4 | |
| parent | 0217c0dde5a060dfd48318a70814687062e4ce3a (diff) | |
Make DOCSTRING in mtt-define-test optional
This commit removes mtt-define-test's explicit DOCSTRING argument and
instead inspects the first entry of the given ARGS:
- if (car args) is a string, it is interpreted as a DOCSTRING
- otherwise, it is considered to be part of the test's BODY
Examples:
;; No docstring
(macroexpand-1
'(mtt-define-test trivial-check
(should (= 1 1))))
=> (ert-deftest mtt-trivial-check nil "Test that `trivial-check' does the right thing." (should (= 1 1)))
;; With docstring
(macroexpand-1
'(mtt-define-test trivial-check-with-docstring
"This tests a trivial thing."
(should (= 1 1))))
=> (ert-deftest mtt-trivial-check-with-docstring nil "This tests a trivial thing." (should (= 1 1)))
mtt-define-test's own docstring follows the usual \(fn ARGLIST)
feature used for macros, see "(elisp) Function Documentation".
| -rw-r--r-- | tests/modus-themes-test.el | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/tests/modus-themes-test.el b/tests/modus-themes-test.el index 71faab5..818a7ae 100644 --- a/tests/modus-themes-test.el +++ b/tests/modus-themes-test.el @@ -35,15 +35,20 @@ (require 'ert) (require 'modus-themes) -(defmacro mtt-define-test (symbol docstring &rest body) +(defmacro mtt-define-test (symbol &rest args) "Write test for SYMBOL with DOCSTRING that runs BODY. -If docstring is nil, use a generic snippet of text." - (declare (indent defun)) - `(ert-deftest ,(intern (format "mtt-%s" symbol)) () - ,(if (stringp docstring) - docstring - (format "Test that `%s' does the right thing." symbol)) - ,@body)) +If DOCSTRING is nil, use a generic snippet of text. + +\(fn NAME [DOCSTRING] BODY...)" + (declare (doc-string 2) (indent defun)) + (let* ((has-docstring (stringp (car args))) + (docstring (if has-docstring + (car args) + (format "Test that `%s' does the right thing." symbol))) + (body (if has-docstring (cdr args) args))) + `(ert-deftest ,(intern (format "mtt-%s" symbol)) () + ,docstring + ,@body))) (mtt-define-test modus-themes--hex-to-rgb nil (should (equal (modus-themes--hex-to-rgb "#fff") (list 1.0 1.0 1.0))) |
