From 742054c713ddaac3a0a674faa1cd2731baf74359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20K=C3=A4stner?= Date: Fri, 10 Apr 2026 18:10:52 +0200 Subject: 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". --- tests/modus-themes-test.el | 21 +++++++++++++-------- 1 file 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))) -- cgit v1.0