[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#47071: 28.0.50; Show ERT failure reason in batch mode
From: |
Julian Scheid |
Subject: |
bug#47071: 28.0.50; Show ERT failure reason in batch mode |
Date: |
Thu, 11 Mar 2021 10:42:19 +0000 |
Severity: normal
Tags: patch
`ert-fail' and `ert-skip' both require an argument described as "[data
that] is displayed to the user and should state the reason of the
failure [or the reason for skipping]."
The data is only displayed in interactive mode as a side-effect
however, not in batch mode. I think it's useful to see the failure or
skip reason in batch mode as well, which is why I would like to
suggest the following change.
(I've borrowed `print-level' etc. from other parts of ERT code but
don't have a strong opinion on it. I'd imagine that most of the time
people would just pass in a short string anyway. That's what a quick
grep of Emacs code seems to point to as well.)
>From 053abfe6e9a35a76b7f0af866a6336fb35d959f9 Mon Sep 17 00:00:00 2001
From: Julian Scheid <jscheid@protonmail.com>
Date: Thu, 11 Mar 2021 22:49:11 +1300
Subject: [PATCH] Output test failure or skip reason in batch mode
* lisp/emacs-lisp/ert.el (ert-reason-for-test-result): New function.
(ert-run-tests-batch): Output failure or skip reason.
---
lisp/emacs-lisp/ert.el | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index e91ec0af44..05edbb6fd1 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1279,6 +1279,23 @@ ert-string-for-test-result
(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,20 @@ ert-run-tests-batch
(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)
+ (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)
+ (ert-reason-for-test-result result))))
(message "%s" "")))))
(test-started
)
--
2.30.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#47071: 28.0.50; Show ERT failure reason in batch mode,
Julian Scheid <=