unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47071: 28.0.50; Show ERT failure reason in batch mode
@ 2021-03-11 10:42 Julian Scheid via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-05-17 15:34 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Julian Scheid via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-03-11 10:42 UTC (permalink / raw)
  To: 47071

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







^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-15 15:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 10:42 bug#47071: 28.0.50; Show ERT failure reason in batch mode Julian Scheid via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-17 15:34 ` Lars Ingebrigtsen
2021-05-17 15:52   ` Philipp Stephani
2021-05-18 13:42     ` Lars Ingebrigtsen
2021-06-15 15:03       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).