comments directly and can be read either from inline strings or files.
The parser expects the input string to contain at least one assertion.
-Test assertion parser extracts tests from comment-only lines. Every
+The test assertion parser extracts tests from comment-only lines. Every
comment assertion line starts either with a caret (@samp{^}) or an arrow
(@samp{<-}). A single caret/arrow or carets should be followed
immediately by the name of a face or a list of faces to be checked
@end example
Both symbol-only @code{:face} property values and assertion face values
-are normalized to single element lists so assertions below are
+are normalized to single element lists so the assertions below are
equivalent:
@example
@lisp
(ert-font-lock-deftest test-macro-test--inline
- emacs-lisp-mode
+ emacs-lisp-mode
"
(defun fun ())
;; ^ font-lock-keyword-face
@lisp
(ert-font-lock-deftest-file test-macro-test--file
- "Test reading correct assertions from a 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 parameters as @code{ert-deftest} i.e.,
+macros accept the same keyword arguments as @code{ert-deftest}, i.e.,
@code{:tag} and @code{:expected-result}.
;; highlighting provided by font-lock.
;;
;; ert-font-lock entry points are functions
-;; `ert-font-lock-test-string' and `ert-font-lock-test-file' and
-;; convenience macros: `ert-font-lock-deftest' and
+;; `ert-font-lock-test-string' and `ert-font-lock-test-file', and
+;; convenience macros `ert-font-lock-deftest' and
;; `ert-font-lock-deftest-file'.
;;
;; See unit tests in ert-font-lock-tests.el for usage examples.
(defmacro ert-font-lock-deftest (name &rest docstring-keys-mode-and-str)
"Define test NAME (a symbol) using assertions from TEST-STR.
-Other than MAJOR-MODE and TEST-STR parameters, this macro accepts
-the same parameters and keywords as `ert-deftest' and is intended
-to be used through `ert'.
+The MAJOR-MODE symbol determines the syntax and font lock of TEST-STR.
-\(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \
+Except for the MAJOR-MODE and TEST-STR parameters, this macro accepts
+the same arguments and keywords as `ert-deftest' and is intended to be
+used through `ert'.
+
+\(fn NAME [DOCSTRING] [:expected-result RESULT-TYPE] \
[:tags \\='(TAG...)] MAJOR-MODE TEST-STR)"
(declare (debug (&define [&name "test@" symbolp]
- sexp [&optional stringp]
+ [&optional stringp]
[&rest keywordp sexp]
symbolp
stringp))
- (doc-string 3)
- (indent 2))
+ (doc-string 2)
+ (indent 1))
(pcase-let ((`(,documentation
,documentation-supplied-p
,keys ,mode ,arg)
(defmacro ert-font-lock-deftest-file (name &rest docstring-keys-mode-and-file)
"Define test NAME (a symbol) using assertions from FILE.
-FILE - path to a file with assertions in ERT resource director as
-return by `ert-resource-directory'.
+FILE names a file with assertions in the ERT resource directory, as
+returned by `ert-resource-directory'. The MAJOR-MODE symbol determines
+the syntax and font lock of FILE's contents.
-Other than MAJOR-MODE and FILE parameters, this macro accepts the
-same parameters and keywords as `ert-deftest' and is intended to
-be used through `ert'.
+Except for the MAJOR-MODE and FILE parameters, this macro accepts the
+same arguments and keywords as `ert-deftest' and is intended to be used
+through `ert'.
-\(fn NAME () [DOCSTRING] [:expected-result RESULT-TYPE] \
+\(fn NAME [DOCSTRING] [:expected-result RESULT-TYPE] \
[:tags \\='(TAG...)] MAJOR-MODE FILE)"
(declare (debug (&define [&name "test@" symbolp]
- sexp [&optional stringp]
+ [&optional stringp]
[&rest keywordp sexp]
symbolp
stringp))
- (doc-string 3)
- (indent 2))
+ (doc-string 2)
+ (indent 1))
(pcase-let ((`(,documentation
,documentation-supplied-p
"Create a buffer with STR contents and MODE. "
(declare (indent 1) (debug t))
`(with-temp-buffer
- (insert ,str)
(,mode)
+ (insert ,str)
(goto-char (point-min))
,@body))
(defun ert-font-lock--wrap-begin-end (re)
- (concat "^" re "$"))
+ (rx bol (regexp re) eol))
;;; Regexp tests
;;;
(ert-deftest test-line-comment-p--emacs-lisp ()
(with-temp-buffer-str-mode emacs-lisp-mode
- "not comment
+ "not comment
;; comment
"
- (should-not (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should-not (ert-font-lock--line-comment-p))))
+ (should-not (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should-not (ert-font-lock--line-comment-p))))
(ert-deftest test-line-comment-p--shell-script ()
(with-temp-buffer-str-mode shell-script-mode
- "echo Not a comment
+ "echo Not a comment
# comment
"
- (should-not (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))))
+ (should-not (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))))
(declare-function php-mode "php-mode")
(ert-deftest test-line-comment-p--php ()
- (skip-unless (featurep 'php-mode))
+ (skip-unless (fboundp 'php-mode))
(with-temp-buffer-str-mode php-mode
- "echo 'Not a comment'
+ "echo 'Not a comment'
// comment
/* comment */
"
- (should-not (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))))
+ (should-not (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))))
(ert-deftest test-line-comment-p--javascript ()
(with-temp-buffer-str-mode javascript-mode
- "// comment
+ "// comment
// comment, after a blank line
var abc = function(d) {};
"
- (should (ert-font-lock--line-comment-p))
+ (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should-not (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should-not (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should-not (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should-not (ert-font-lock--line-comment-p))
- (forward-line)
- (should-not (ert-font-lock--line-comment-p))))
+ (forward-line)
+ (should-not (ert-font-lock--line-comment-p))))
(ert-deftest test-line-comment-p--python ()
(with-temp-buffer-str-mode python-mode
- "# comment
+ "# comment
# comment
print(\"Hello, world!\")"
- (should (ert-font-lock--line-comment-p))
+ (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should-not (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should-not (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should-not (ert-font-lock--line-comment-p))))
+ (forward-line)
+ (should-not (ert-font-lock--line-comment-p))))
(ert-deftest test-line-comment-p--c ()
(with-temp-buffer-str-mode c-mode
- "// comment
+ "// comment
/* also comment */"
- (should (ert-font-lock--line-comment-p))
+ (should (ert-font-lock--line-comment-p))
- (forward-line)
- (should (ert-font-lock--line-comment-p))))
+ (forward-line)
+ (should (ert-font-lock--line-comment-p))))
(ert-deftest test-parse-comments--no-assertion-error ()
(let* ((str "
;;
(ert-font-lock-deftest test-macro-test--correct-highlighting
- emacs-lisp-mode
+ emacs-lisp-mode
"
(defun fun ())
;; ^ font-lock-keyword-face
;; ^ font-lock-function-name-face")
(ert-font-lock-deftest test-macro-test--docstring
- "A test with a docstring."
+ "A test with a docstring."
emacs-lisp-mode
"
(defun fun ())
)
(ert-font-lock-deftest test-macro-test--failing
- "A failing test."
+ "A failing test."
:expected-result :failed
emacs-lisp-mode
"
;; ^ wrong-face")
(ert-font-lock-deftest-file test-macro-test--file
- "Test reading correct assertions from a file"
+ "Test reading correct assertions from a file."
javascript-mode
"correct.js")
(ert-font-lock-deftest-file test-macro-test--file-no-asserts
- "Check failing on files without assertions"
+ "Check failing on files without assertions."
:expected-result :failed
javascript-mode
"no-asserts.js")
(ert-font-lock-deftest-file test-macro-test--file-failing
- "Test reading wrong assertions from a file"
+ "Test reading wrong assertions from a file."
:expected-result :failed
javascript-mode
"broken.js")