summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorJulian Scheid <jscheid@protonmail.com>2021-06-15 17:01:49 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-06-15 17:01:57 +0200
commit8be9d4a1568c34aed753b085d5d33daef5dfa797 (patch)
treeb2c3d84d4dcdc1fc6274f4ccb45c90f72eddfd34 /lisp/emacs-lisp
parent81fd5603ce701a0acae096314c1f7ab1db69c64f (diff)
downloademacs-8be9d4a1568c34aed753b085d5d33daef5dfa797.tar.gz
emacs-8be9d4a1568c34aed753b085d5d33daef5dfa797.tar.bz2
emacs-8be9d4a1568c34aed753b085d5d33daef5dfa797.zip
Allow ERT tests to output the failure reasons, too
* lisp/emacs-lisp/ert.el (ert-reason-for-test-result): New function. (ert-run-tests-batch): Output failure or skip reason (bug#47071).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/ert.el31
1 files changed, 27 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index e91ec0af443..6793b374eea 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1279,6 +1279,23 @@ EXPECTEDP specifies whether the result was expected."
(ert-test-quit '("quit" "QUIT")))))
(elt s (if expectedp 0 1))))
+(defun ert-reason-for-test-result (result)
+ "Return the reason given for RESULT, as a string.
+
+The reason is the argument given when invoking `ert-fail' or `ert-skip'.
+It is output using `prin1' prefixed by two spaces.
+
+If no reason was given, or for a successful RESULT, return the
+empty string."
+ (let ((reason
+ (and
+ (ert-test-result-with-condition-p result)
+ (cadr (ert-test-result-with-condition-condition result))))
+ (print-escape-newlines t)
+ (print-level 6)
+ (print-length 10))
+ (if reason (format " %S" reason) "")))
+
(defun ert--pp-with-indentation-and-newline (object)
"Pretty-print OBJECT, indenting it to the current column of point.
Ensures a final newline is inserted."
@@ -1369,18 +1386,24 @@ Returns the stats object."
(cl-loop for test across (ert--stats-tests stats)
for result = (ert-test-most-recent-result test) do
(when (not (ert-test-result-expected-p test result))
- (message "%9s %S"
+ (message "%9s %S%s"
(ert-string-for-test-result result nil)
- (ert-test-name test))))
+ (ert-test-name test)
+ (if (getenv "EMACS_TEST_VERBOSE")
+ (ert-reason-for-test-result result)
+ ""))))
(message "%s" ""))
(unless (zerop skipped)
(message "%s skipped results:" skipped)
(cl-loop for test across (ert--stats-tests stats)
for result = (ert-test-most-recent-result test) do
(when (ert-test-result-type-p result :skipped)
- (message "%9s %S"
+ (message "%9s %S%s"
(ert-string-for-test-result result nil)
- (ert-test-name test))))
+ (ert-test-name test)
+ (if (getenv "EMACS_TEST_VERBOSE")
+ (ert-reason-for-test-result result)
+ ""))))
(message "%s" "")))))
(test-started
)