mirror of
https://github.com/protesilaos/modus-themes.git
synced 2026-09-10 07:16:30 -04:00
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".
This commit is contained in:
parent
0217c0dde5
commit
742054c713
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue