[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master f6da1eed74: Properly report errors about unbound ERT test symbols
From: |
Philipp Stephani |
Subject: |
master f6da1eed74: Properly report errors about unbound ERT test symbols. |
Date: |
Thu, 30 Dec 2021 11:06:27 -0500 (EST) |
branch: master
commit f6da1eed7447c363ef927fea9b23a7b35587473c
Author: Philipp Stephani <phst@google.com>
Commit: Philipp Stephani <phst@google.com>
Properly report errors about unbound ERT test symbols.
Assertions should only be used to check internal consistency within a
package, not to check arguments passed by callers. Instead, define
and use a new error symbol.
* lisp/emacs-lisp/ert.el (ert-test-unbound): New error symbol.
(ert-select-tests): Use it.
* test/lisp/emacs-lisp/ert-tests.el (ert-test-select-undefined): New
unit test.
* etc/NEWS: Document new behavior.
---
etc/NEWS | 3 +++
lisp/emacs-lisp/ert.el | 9 +++++++--
test/lisp/emacs-lisp/ert-tests.el | 6 ++++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 96e95967ef..bbe0aed3f7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -175,6 +175,9 @@ When environment variable 'EMACS_TEST_JUNIT_REPORT' is set,
ERT
generates a JUnit test report under this file name. This is useful
for Emacs integration into CI/CD test environments.
+*** Unbound test symbols now signal an 'ert-test-unbound' error.
+This affects the 'ert-select-tests' function and its callers.
+
** Emoji
+++
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index c570132870..da14b93d1b 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1012,7 +1012,8 @@ contained in UNIVERSE."
universe))))
((pred ert-test-p) (list selector))
((pred symbolp)
- (cl-assert (ert-test-boundp selector))
+ (unless (ert-test-boundp selector)
+ (signal 'ert-test-unbound (list selector)))
(list (ert-get-test selector)))
(`(,operator . ,operands)
(cl-ecase operator
@@ -1020,7 +1021,9 @@ contained in UNIVERSE."
(mapcar (lambda (purported-test)
(pcase-exhaustive purported-test
((pred symbolp)
- (cl-assert (ert-test-boundp purported-test))
+ (unless (ert-test-boundp purported-test)
+ (signal 'ert-test-unbound
+ (list purported-test)))
(ert-get-test purported-test))
((pred ert-test-p) purported-test)))
operands))
@@ -1059,6 +1062,8 @@ contained in UNIVERSE."
(cl-remove-if-not (car operands)
(ert-select-tests 't universe)))))))
+(define-error 'ert-test-unbound "ERT test is unbound")
+
(defun ert--insert-human-readable-selector (selector)
"Insert a human-readable presentation of SELECTOR into the current buffer."
;; This is needed to avoid printing the (huge) contents of the
diff --git a/test/lisp/emacs-lisp/ert-tests.el
b/test/lisp/emacs-lisp/ert-tests.el
index 1a8c9bf4f0..e2b41297ad 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -495,6 +495,12 @@ This macro is used to test if macroexpansion in `should'
works."
(should (equal (ert-select-tests '(tag b) (list test)) (list test)))
(should (equal (ert-select-tests '(tag c) (list test)) '()))))
+(ert-deftest ert-test-select-undefined ()
+ (let* ((symbol (make-symbol "ert-not-a-test"))
+ (data (should-error (ert-select-tests symbol t)
+ :type 'ert-test-unbound)))
+ (should (eq (cadr data) symbol))))
+
;;; Tests for utility functions.
(ert-deftest ert-test-parse-keys-and-body ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master f6da1eed74: Properly report errors about unbound ERT test symbols.,
Philipp Stephani <=